mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f5ba70c30 | ||
|
|
700b4e071f | ||
|
|
d103774cbe | ||
|
|
5a3e22c213 | ||
|
|
b6ff9f9360 | ||
|
|
ffb733ef78 | ||
|
|
818be8de6a | ||
|
|
268ae0f584 | ||
|
|
6b3854ad25 | ||
|
|
db125e8df4 | ||
|
|
62d62638b2 | ||
|
|
476f62b577 | ||
|
|
e5c8b970d6 | ||
|
|
d5d2d76892 | ||
|
|
fba297a2a7 | ||
|
|
0fd348d3fe | ||
|
|
67e478e26a | ||
|
|
e292151642 | ||
|
|
8bb2a5f9b7 | ||
|
|
ac3b854893 | ||
|
|
c6fad15f7c | ||
|
|
836d531676 | ||
|
|
bba116ba9d | ||
|
|
23fa082874 | ||
|
|
e6811e927f | ||
|
|
05596d7626 | ||
|
|
e5e172728c | ||
|
|
9a2f0eb8ba | ||
|
|
bf44b757fe | ||
|
|
e6526132ee | ||
|
|
6b7c110b33 | ||
|
|
ad1e63e15c | ||
|
|
6eafab0ff3 | ||
|
|
fe49c3d9ee | ||
|
|
3f6ec1c280 | ||
|
|
72df918400 | ||
|
|
c10c41e932 | ||
|
|
977da00f0f | ||
|
|
7e5538a638 | ||
|
|
295d2fba38 | ||
|
|
ef9f04dd59 | ||
|
|
6171834fde | ||
|
|
7f729dc9a7 | ||
|
|
144140cd39 | ||
|
|
be72a2d318 | ||
|
|
6d03fa81d9 | ||
|
|
3e7bb6e171 | ||
|
|
0f32bd0e61 | ||
|
|
b0b90f44f0 | ||
|
|
6b69015d83 | ||
|
|
053005ed4e | ||
|
|
64165bd4ba | ||
|
|
9b08619fbd | ||
|
|
3dcbd98b5d | ||
|
|
d411a2bc7e | ||
|
|
e6a969a640 | ||
|
|
708c2c9253 | ||
|
|
d68dbdc53d | ||
|
|
fb5dfa51d4 | ||
|
|
ae02953010 | ||
|
|
fd0ac20074 | ||
|
|
21feb61eb5 | ||
|
|
280a3ce56d | ||
|
|
0604d62704 | ||
|
|
a66d783afd | ||
|
|
84de81c009 | ||
|
|
38743b6779 | ||
|
|
0d52cb6389 | ||
|
|
2281569ebc | ||
|
|
e0faa7f04f | ||
|
|
39a08094f1 | ||
|
|
07b195e1ee | ||
|
|
0bca477a34 | ||
|
|
66a7d3bf31 | ||
|
|
2331fc92f6 | ||
|
|
b1922e00de | ||
|
|
53ba484043 | ||
|
|
cfb3ebea55 | ||
|
|
c33820b04b | ||
|
|
280c4a1d44 | ||
|
|
66ae84e9d7 | ||
|
|
3023fb2220 | ||
|
|
a9b6edf3ce | ||
|
|
f3d1a28bf7 | ||
|
|
fd9e6bd26d | ||
|
|
d5e4b2ec73 | ||
|
|
bae8be0dcd | ||
|
|
3a5d30e027 | ||
|
|
d2414cd3dc | ||
|
|
070b13745a | ||
|
|
df7807cd73 | ||
|
|
b07e3c36b7 | ||
|
|
163dd7877e | ||
|
|
6d705c1a0f | ||
|
|
ab0bcb8d31 | ||
|
|
ac6e37af97 | ||
|
|
4a7affe15b | ||
|
|
b7797b4e1a | ||
|
|
8b529636bf | ||
|
|
2e9fd6a2e8 | ||
|
|
cbb14bab1e | ||
|
|
d57128e65c | ||
|
|
d9c0928243 | ||
|
|
63c9de4e8b | ||
|
|
76619d4a16 | ||
|
|
47d3f86c53 | ||
|
|
cfb104b8c8 | ||
|
|
5c51ccf185 | ||
|
|
5d93f42598 | ||
|
|
eb83d810de | ||
|
|
6f0fc03c49 | ||
|
|
b09525332f | ||
|
|
c2796044a6 | ||
|
|
8418970624 | ||
|
|
0d38c84407 | ||
|
|
bfc443b40c | ||
|
|
4a9ddd15fe | ||
|
|
87ed522579 | ||
|
|
f01f8ea41d | ||
|
|
620b932272 | ||
|
|
beb96a487b | ||
|
|
7a03741e0b | ||
|
|
a79e4c174c | ||
|
|
be61012d74 | ||
|
|
99de44e96f | ||
|
|
b20c7da00b | ||
|
|
99054d341f | ||
|
|
9da4a65065 | ||
|
|
39faeec91d | ||
|
|
0c15eb99f5 | ||
|
|
21c36677ab | ||
|
|
ffcaa03337 | ||
|
|
37810ef836 | ||
|
|
587406073d | ||
|
|
aed654aa85 | ||
|
|
2812eac046 | ||
|
|
db20ae39fb | ||
|
|
cdaa97eb31 | ||
|
|
27bdc08a1e | ||
|
|
a18985a888 | ||
|
|
747e6d7cdf | ||
|
|
c2f692140f | ||
|
|
8eb596c1cc | ||
|
|
26e2eade91 | ||
|
|
1ac9106c48 | ||
|
|
1352ef56a6 | ||
|
|
6df31db139 | ||
|
|
829a92e5aa | ||
|
|
04936a7b39 | ||
|
|
ae82b8488f | ||
|
|
bae65d2afe | ||
|
|
28df2a4cd6 | ||
|
|
fedcd8cf49 | ||
|
|
a868c60f8e | ||
|
|
e6d2ec7c54 | ||
|
|
f19dac185a | ||
|
|
0ba0ad6b42 | ||
|
|
8b9591a7c5 | ||
|
|
082c9354d0 | ||
|
|
233e4b3ff7 | ||
|
|
d788b51755 | ||
|
|
bbd5775f1f | ||
|
|
044ebd68c9 | ||
|
|
e0a5a75364 | ||
|
|
607aa79601 | ||
|
|
a4107acb6d | ||
|
|
34eabb7d11 | ||
|
|
f07ab7eda0 | ||
|
|
d6119709ba | ||
|
|
21ec090933 | ||
|
|
ba1395e42d | ||
|
|
9a3c6f50ef | ||
|
|
009237bad2 |
@@ -0,0 +1,10 @@
|
|||||||
|
# Path-based git attributes
|
||||||
|
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
|
||||||
|
|
||||||
|
# Ignore all test and documentation with "export-ignore".
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/.gitattributes export-ignore
|
||||||
|
/.travis.yml export-ignore
|
||||||
|
/composer.lock export-ignore
|
||||||
|
/phpunit.xml.dist export-ignore
|
||||||
|
/tests export-ignore
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
name: Unit Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
php-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 15
|
||||||
|
env:
|
||||||
|
COMPOSER_NO_INTERACTION: 1
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php: [8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2]
|
||||||
|
dependency-version: [prefer-lowest, prefer-stable]
|
||||||
|
|
||||||
|
name: P${{ matrix.php }} - ${{ matrix.dependency-version }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
coverage: none
|
||||||
|
tools: composer:v2
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
|
||||||
|
|
||||||
|
- name: Execute Unit Tests
|
||||||
|
run: vendor/bin/phpunit
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
|
.phpunit.result.cache
|
||||||
|
composer.lock
|
||||||
vendor
|
vendor
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2010 Mike van Riel
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
The ReflectionDocBlock Component
|
The ReflectionDocBlock Component
|
||||||
================================
|
================================
|
||||||
|
|
||||||
|
> This is a fork of [phpDocumentor/ReflectionDocBlock 2.x](https://github.com/phpDocumentor/ReflectionDocBlock/tree/release/2.x) combined with bits of [phpDocumentor/TypeResolver](https://github.com/phpDocumentor/TypeResolver) and various tweaks. The main reason for this fork is to add functionality for https://github.com/barryvdh/laravel-ide-helper
|
||||||
|
> Any other use of this library is discouraged. You are probably better of using https://github.com/phpDocumentor/ReflectionDocBlock directly.
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser
|
The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser
|
||||||
that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest).
|
that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest).
|
||||||
|
|
||||||
With this component can a library provide support for annotations via DocBlocks
|
With this component, a library can provide support for annotations via DocBlocks
|
||||||
or otherwise retrieve information that is embedded in a DocBlock.
|
or otherwise retrieve information that is embedded in a DocBlock.
|
||||||
|
|
||||||
> **Note**: *this is a core component of phpDocumentor and is constantly being
|
> **Note**: *this is a core component of phpDocumentor and is constantly being
|
||||||
|
|||||||
+15
-4
@@ -1,15 +1,26 @@
|
|||||||
{
|
{
|
||||||
"name": "phpdocumentor/reflection-docblock",
|
"name": "barryvdh/reflection-docblock",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{"name": "Mike van Riel", "email": "[email protected]"}
|
{"name": "Mike van Riel", "email": "[email protected]"}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2",
|
"php": ">=7.1"
|
||||||
"dflydev/markdown": "1.0.*"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {"phpDocumentor": ["src/"]}
|
"psr-0": {"Barryvdh": ["src/"]}
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^8.5.14|^9"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dflydev/markdown": "~1.0",
|
||||||
|
"erusev/parsedown": "~1.0"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.3.x-dev"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
-67
@@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"hash": "89c7387ec02d39de3c07849e525f95e4",
|
|
||||||
"packages": [
|
|
||||||
{
|
|
||||||
"name": "dflydev/markdown",
|
|
||||||
"version": "v1.0.2",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/dflydev/dflydev-markdown.git",
|
|
||||||
"reference": "v1.0.2"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://github.com/dflydev/dflydev-markdown/zipball/v1.0.2",
|
|
||||||
"reference": "v1.0.2",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3"
|
|
||||||
},
|
|
||||||
"time": "2012-01-15 19:36:37",
|
|
||||||
"type": "library",
|
|
||||||
"installation-source": "dist",
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"dflydev\\markdown": "src"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"license": [
|
|
||||||
"New BSD License"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Dragonfly Development Inc.",
|
|
||||||
"email": "[email protected]",
|
|
||||||
"homepage": "http://dflydev.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Beau Simensen",
|
|
||||||
"email": "[email protected]",
|
|
||||||
"homepage": "http://beausimensen.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Michel Fortin",
|
|
||||||
"homepage": "http://michelf.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "John Gruber",
|
|
||||||
"homepage": "http://daringfireball.net"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PHP Markdown & Extra",
|
|
||||||
"homepage": "http://github.com/dflydev/dflydev-markdown",
|
|
||||||
"keywords": [
|
|
||||||
"markdown"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"packages-dev": null,
|
|
||||||
"aliases": [
|
|
||||||
|
|
||||||
],
|
|
||||||
"minimum-stability": "stable",
|
|
||||||
"stability-flags": [
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
|
||||||
+6
-2
@@ -1,6 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
<phpunit colors="true" strict="true" bootstrap="vendor/autoload.php">
|
<coverage>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">./src/</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="phpDocumentor\Reflection\DocBlock">
|
<testsuite name="phpDocumentor\Reflection\DocBlock">
|
||||||
<directory>./tests/</directory>
|
<directory>./tests/</directory>
|
||||||
|
|||||||
@@ -0,0 +1,503 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Location;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag\TemplateTag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the DocBlock for any structure.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class DocBlock implements \Reflector
|
||||||
|
{
|
||||||
|
/** @var string The opening line for this docblock. */
|
||||||
|
protected $short_description = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DocBlock\Description The actual
|
||||||
|
* description for this docblock.
|
||||||
|
*/
|
||||||
|
protected $long_description = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Tag[] An array containing all
|
||||||
|
* the tags in this docblock; except inline.
|
||||||
|
*/
|
||||||
|
protected $tags = array();
|
||||||
|
|
||||||
|
/** @var string[] An array containing all the generics in this docblock. */
|
||||||
|
protected $generics = array();
|
||||||
|
|
||||||
|
/** @var Context Information about the context of this DocBlock. */
|
||||||
|
protected $context = null;
|
||||||
|
|
||||||
|
/** @var Location Information about the location of this DocBlock. */
|
||||||
|
protected $location = null;
|
||||||
|
|
||||||
|
/** @var bool Is this DocBlock (the start of) a template? */
|
||||||
|
protected $isTemplateStart = false;
|
||||||
|
|
||||||
|
/** @var bool Does this DocBlock signify the end of a DocBlock template? */
|
||||||
|
protected $isTemplateEnd = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given docblock and populates the member fields.
|
||||||
|
*
|
||||||
|
* The constructor may also receive namespace information such as the
|
||||||
|
* current namespace and aliases. This information is used by some tags
|
||||||
|
* (e.g. @return, @param, etc.) to turn a relative Type into a FQCN.
|
||||||
|
*
|
||||||
|
* @param \Reflector|string $docblock A docblock comment (including
|
||||||
|
* asterisks) or reflector supporting the getDocComment method.
|
||||||
|
* @param Context $context The context in which the DocBlock
|
||||||
|
* occurs.
|
||||||
|
* @param Location $location The location within the file that this
|
||||||
|
* DocBlock occurs in.
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException if the given argument does not have the
|
||||||
|
* getDocComment method.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$docblock,
|
||||||
|
?Context $context = null,
|
||||||
|
?Location $location = null
|
||||||
|
) {
|
||||||
|
if (is_object($docblock)) {
|
||||||
|
if (!method_exists($docblock, 'getDocComment')) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Invalid object passed; the given reflector must support '
|
||||||
|
. 'the getDocComment method'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$docblock = $docblock->getDocComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
$docblock = $this->cleanInput($docblock);
|
||||||
|
|
||||||
|
list($templateMarker, $short, $long, $tags) = $this->splitDocBlock($docblock);
|
||||||
|
$this->isTemplateStart = $templateMarker === '#@+';
|
||||||
|
$this->isTemplateEnd = $templateMarker === '#@-';
|
||||||
|
$this->short_description = $short;
|
||||||
|
$this->long_description = new DocBlock\Description($long, $this);
|
||||||
|
$this->parseTags($tags);
|
||||||
|
|
||||||
|
$this->context = $context;
|
||||||
|
$this->location = $location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips the asterisks from the DocBlock comment.
|
||||||
|
*
|
||||||
|
* @param string $comment String containing the comment text.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function cleanInput($comment)
|
||||||
|
{
|
||||||
|
$comment = trim(
|
||||||
|
preg_replace(
|
||||||
|
'#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u',
|
||||||
|
'$1',
|
||||||
|
$comment
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// reg ex above is not able to remove */ from a single line docblock
|
||||||
|
if (substr($comment, -2) == '*/') {
|
||||||
|
$comment = trim(substr($comment, 0, -2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalize strings
|
||||||
|
$comment = str_replace(array("\r\n", "\r"), "\n", $comment);
|
||||||
|
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the DocBlock into a template marker, summary, description and block of tags.
|
||||||
|
*
|
||||||
|
* @param string $comment Comment to split into the sub-parts.
|
||||||
|
*
|
||||||
|
* @author Richard van Velzen (@_richardJ) Special thanks to Richard for the regex responsible for the split.
|
||||||
|
* @author Mike van Riel <[email protected]> for extending the regex with template marker support.
|
||||||
|
*
|
||||||
|
* @return string[] containing the template marker (if any), summary, description and a string containing the tags.
|
||||||
|
*/
|
||||||
|
protected function splitDocBlock($comment)
|
||||||
|
{
|
||||||
|
// Performance improvement cheat: if the first character is an @ then only tags are in this DocBlock. This
|
||||||
|
// method does not split tags so we return this verbatim as the fourth result (tags). This saves us the
|
||||||
|
// performance impact of running a regular expression
|
||||||
|
if (strpos($comment, '@') === 0) {
|
||||||
|
return array('', '', '', $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clears all extra horizontal whitespace from the line endings to prevent parsing issues
|
||||||
|
$comment = preg_replace('/\h*$/Sum', '', $comment);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Splits the docblock into a template marker, short description, long description and tags section
|
||||||
|
*
|
||||||
|
* - The template marker is empty, #@+ or #@- if the DocBlock starts with either of those (a newline may
|
||||||
|
* occur after it and will be stripped).
|
||||||
|
* - The short description is started from the first character until a dot is encountered followed by a
|
||||||
|
* newline OR two consecutive newlines (horizontal whitespace is taken into account to consider spacing
|
||||||
|
* errors). This is optional.
|
||||||
|
* - The long description, any character until a new line is encountered followed by an @ and word
|
||||||
|
* characters (a tag). This is optional.
|
||||||
|
* - Tags; the remaining characters
|
||||||
|
*
|
||||||
|
* Big thanks to RichardJ for contributing this Regular Expression
|
||||||
|
*/
|
||||||
|
preg_match(
|
||||||
|
'/
|
||||||
|
\A
|
||||||
|
# 1. Extract the template marker
|
||||||
|
(?:(\#\@\+|\#\@\-)\n?)?
|
||||||
|
|
||||||
|
# 2. Extract the summary
|
||||||
|
(?:
|
||||||
|
(?! @\pL ) # The summary may not start with an @
|
||||||
|
(
|
||||||
|
[^\n.]+
|
||||||
|
(?:
|
||||||
|
(?! \. \n | \n{2} ) # End summary upon a dot followed by newline or two newlines
|
||||||
|
[\n.] (?! [ \t]* @\pL ) # End summary when an @ is found as first character on a new line
|
||||||
|
[^\n.]+ # Include anything else
|
||||||
|
)*
|
||||||
|
\.?
|
||||||
|
)?
|
||||||
|
)
|
||||||
|
|
||||||
|
# 3. Extract the description
|
||||||
|
(?:
|
||||||
|
\s* # Some form of whitespace _must_ precede a description because a summary must be there
|
||||||
|
(?! @\pL ) # The description may not start with an @
|
||||||
|
(
|
||||||
|
[^\n]+
|
||||||
|
(?: \n+
|
||||||
|
(?! [ \t]* @\pL ) # End description when an @ is found as first character on a new line
|
||||||
|
[^\n]+ # Include anything else
|
||||||
|
)*
|
||||||
|
)
|
||||||
|
)?
|
||||||
|
|
||||||
|
# 4. Extract the tags (anything that follows)
|
||||||
|
(\s+ [\s\S]*)? # everything that follows
|
||||||
|
/ux',
|
||||||
|
$comment,
|
||||||
|
$matches
|
||||||
|
);
|
||||||
|
array_shift($matches);
|
||||||
|
|
||||||
|
while (count($matches) < 4) {
|
||||||
|
$matches[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the tag objects.
|
||||||
|
*
|
||||||
|
* @param string $tags Tag block to parse.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function parseTags($tags)
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
$tags = trim($tags);
|
||||||
|
if ('' !== $tags) {
|
||||||
|
if ('@' !== $tags[0]) {
|
||||||
|
throw new \LogicException(
|
||||||
|
'A tag block started with text instead of an actual tag,'
|
||||||
|
. ' this makes the tag block invalid: ' . $tags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
foreach (explode("\n", $tags) as $tag_line) {
|
||||||
|
if (isset($tag_line[0]) && ($tag_line[0] === '@')) {
|
||||||
|
$result[] = $tag_line;
|
||||||
|
} else {
|
||||||
|
$result[count($result) - 1] .= "\n" . $tag_line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create proper Tag objects
|
||||||
|
foreach ($result as $key => $tag_line) {
|
||||||
|
$tag = Tag::createInstance(trim($tag_line), $this);
|
||||||
|
if ($tag instanceof TemplateTag) {
|
||||||
|
$this->generics[] = $tag->getTemplateName();
|
||||||
|
}
|
||||||
|
$result[$key] = $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tags = $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text portion of the doc block.
|
||||||
|
*
|
||||||
|
* Gets the text portion (short and long description combined) of the doc
|
||||||
|
* block.
|
||||||
|
*
|
||||||
|
* @return string The text portion of the doc block.
|
||||||
|
*/
|
||||||
|
public function getText()
|
||||||
|
{
|
||||||
|
$short = $this->getShortDescription();
|
||||||
|
$long = $this->getLongDescription()->getContents();
|
||||||
|
|
||||||
|
if ($long) {
|
||||||
|
return "{$short}\n\n{$long}";
|
||||||
|
} else {
|
||||||
|
return $short;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the text portion of the doc block.
|
||||||
|
*
|
||||||
|
* Sets the text portion (short and long description combined) of the doc
|
||||||
|
* block.
|
||||||
|
*
|
||||||
|
* @param string $docblock The new text portion of the doc block.
|
||||||
|
*
|
||||||
|
* @return $this This doc block.
|
||||||
|
*/
|
||||||
|
public function setText($comment)
|
||||||
|
{
|
||||||
|
list(,$short, $long) = $this->splitDocBlock($comment);
|
||||||
|
$this->short_description = $short;
|
||||||
|
$this->long_description = new DocBlock\Description($long, $this);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the opening line or also known as short description.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getShortDescription()
|
||||||
|
{
|
||||||
|
return $this->short_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the full description or also known as long description.
|
||||||
|
*
|
||||||
|
* @return DocBlock\Description
|
||||||
|
*/
|
||||||
|
public function getLongDescription()
|
||||||
|
{
|
||||||
|
return $this->long_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this DocBlock is the start of a Template section.
|
||||||
|
*
|
||||||
|
* A Docblock may serve as template for a series of subsequent DocBlocks. This is indicated by a special marker
|
||||||
|
* (`#@+`) that is appended directly after the opening `/**` of a DocBlock.
|
||||||
|
*
|
||||||
|
* An example of such an opening is:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* /**#@+
|
||||||
|
* * My DocBlock
|
||||||
|
* * /
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* The description and tags (not the summary!) are copied onto all subsequent DocBlocks and also applied to all
|
||||||
|
* elements that follow until another DocBlock is found that contains the closing marker (`#@-`).
|
||||||
|
*
|
||||||
|
* @see self::isTemplateEnd() for the check whether a closing marker was provided.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isTemplateStart()
|
||||||
|
{
|
||||||
|
return $this->isTemplateStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this DocBlock is the end of a Template section.
|
||||||
|
*
|
||||||
|
* @see self::isTemplateStart() for a more complete description of the Docblock Template functionality.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isTemplateEnd()
|
||||||
|
{
|
||||||
|
return $this->isTemplateEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current context.
|
||||||
|
*
|
||||||
|
* @return Context
|
||||||
|
*/
|
||||||
|
public function getContext()
|
||||||
|
{
|
||||||
|
return $this->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current location.
|
||||||
|
*
|
||||||
|
* @return Location
|
||||||
|
*/
|
||||||
|
public function getLocation()
|
||||||
|
{
|
||||||
|
return $this->location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the tags for this DocBlock.
|
||||||
|
*
|
||||||
|
* @return Tag[]
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of tags matching the given name. If no tags are found
|
||||||
|
* an empty array is returned.
|
||||||
|
*
|
||||||
|
* @param string $name String to search by.
|
||||||
|
*
|
||||||
|
* @return Tag[]
|
||||||
|
*/
|
||||||
|
public function getTagsByName($name)
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
/** @var Tag $tag */
|
||||||
|
foreach ($this->getTags() as $tag) {
|
||||||
|
if ($tag->getName() != $name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a tag of a certain type is present in this DocBlock.
|
||||||
|
*
|
||||||
|
* @param string $name Tag name to check for.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasTag($name)
|
||||||
|
{
|
||||||
|
/** @var Tag $tag */
|
||||||
|
foreach ($this->getTags() as $tag) {
|
||||||
|
if ($tag->getName() == $name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a tag at the end of the list of tags.
|
||||||
|
*
|
||||||
|
* @param Tag $tag The tag to add.
|
||||||
|
*
|
||||||
|
* @return Tag The newly added tag.
|
||||||
|
*
|
||||||
|
* @throws \LogicException When the tag belongs to a different DocBlock.
|
||||||
|
*/
|
||||||
|
public function appendTag(Tag $tag)
|
||||||
|
{
|
||||||
|
if (null === $tag->getDocBlock()) {
|
||||||
|
$tag->setDocBlock($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tag->getDocBlock() === $this) {
|
||||||
|
$this->tags[] = $tag;
|
||||||
|
} else {
|
||||||
|
throw new \LogicException(
|
||||||
|
'This tag belongs to a different DocBlock object.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a tag from the list of tags.
|
||||||
|
*
|
||||||
|
* @param Tag $tag The tag to be deleted.
|
||||||
|
*
|
||||||
|
* @return bool True if the tag was deleted.
|
||||||
|
*/
|
||||||
|
public function deleteTag(Tag $tag)
|
||||||
|
{
|
||||||
|
if (($key = array_search($tag, $this->tags)) !== false) {
|
||||||
|
unset($this->tags[$key]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the generics for this DocBlock.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getGenerics()
|
||||||
|
{
|
||||||
|
return $this->generics;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a string representation of this object.
|
||||||
|
*
|
||||||
|
* @todo determine the exact format as used by PHP Reflection and
|
||||||
|
* implement it.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @codeCoverageIgnore Not yet implemented
|
||||||
|
*/
|
||||||
|
public static function export()
|
||||||
|
{
|
||||||
|
throw new \Exception('Not yet implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the exported information (we should use the export static method
|
||||||
|
* BUT this throws an exception at this point).
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @codeCoverageIgnore Not yet implemented
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return 'Not yet implemented';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The context in which a DocBlock occurs.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class Context
|
||||||
|
{
|
||||||
|
/** @var string The current namespace. */
|
||||||
|
protected $namespace = '';
|
||||||
|
|
||||||
|
/** @var array List of namespace aliases => Fully Qualified Namespace. */
|
||||||
|
protected $namespace_aliases = array();
|
||||||
|
|
||||||
|
/** @var string Name of the structural element, within the namespace. */
|
||||||
|
protected $lsen = '';
|
||||||
|
|
||||||
|
/** @var string[] List of generics */
|
||||||
|
protected $generics = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cteates a new context.
|
||||||
|
* @param string $namespace The namespace where this DocBlock
|
||||||
|
* resides in.
|
||||||
|
* @param array $namespace_aliases List of namespace aliases => Fully
|
||||||
|
* Qualified Namespace.
|
||||||
|
* @param string $lsen Name of the structural element, within
|
||||||
|
* the namespace.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$namespace = '',
|
||||||
|
array $namespace_aliases = array(),
|
||||||
|
$lsen = '',
|
||||||
|
array $generics = array()
|
||||||
|
) {
|
||||||
|
if (!empty($namespace)) {
|
||||||
|
$this->setNamespace($namespace);
|
||||||
|
}
|
||||||
|
$this->setNamespaceAliases($namespace_aliases);
|
||||||
|
$this->setLSEN($lsen);
|
||||||
|
$this->setGenerics($generics);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string The namespace where this DocBlock resides in.
|
||||||
|
*/
|
||||||
|
public function getNamespace()
|
||||||
|
{
|
||||||
|
return $this->namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array List of namespace aliases => Fully Qualified Namespace.
|
||||||
|
*/
|
||||||
|
public function getNamespaceAliases()
|
||||||
|
{
|
||||||
|
return $this->namespace_aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Local Structural Element Name.
|
||||||
|
*
|
||||||
|
* @return string Name of the structural element, within the namespace.
|
||||||
|
*/
|
||||||
|
public function getLSEN()
|
||||||
|
{
|
||||||
|
return $this->lsen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of generics.
|
||||||
|
*
|
||||||
|
* @return string[] List of generics
|
||||||
|
*/
|
||||||
|
public function getGenerics()
|
||||||
|
{
|
||||||
|
return $this->generics;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new namespace.
|
||||||
|
*
|
||||||
|
* Sets a new namespace for the context. Leading and trailing slashes are
|
||||||
|
* trimmed, and the keywords "global" and "default" are treated as aliases
|
||||||
|
* to no namespace.
|
||||||
|
*
|
||||||
|
* @param string $namespace The new namespace to set.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setNamespace($namespace)
|
||||||
|
{
|
||||||
|
if ('global' !== $namespace
|
||||||
|
&& 'default' !== $namespace
|
||||||
|
) {
|
||||||
|
// Srip leading and trailing slash
|
||||||
|
$this->namespace = trim((string)$namespace, '\\');
|
||||||
|
} else {
|
||||||
|
$this->namespace = '';
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the namespace aliases, replacing all previous ones.
|
||||||
|
*
|
||||||
|
* @param array $namespace_aliases List of namespace aliases => Fully
|
||||||
|
* Qualified Namespace.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setNamespaceAliases(array $namespace_aliases)
|
||||||
|
{
|
||||||
|
$this->namespace_aliases = array();
|
||||||
|
foreach ($namespace_aliases as $alias => $fqnn) {
|
||||||
|
$this->setNamespaceAlias($alias, $fqnn);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a namespace alias to the context.
|
||||||
|
*
|
||||||
|
* @param string $alias The alias name (the part after "as", or the last
|
||||||
|
* part of the Fully Qualified Namespace Name) to add.
|
||||||
|
* @param string $fqnn The Fully Qualified Namespace Name for this alias.
|
||||||
|
* Any form of leading/trailing slashes are accepted, but what will be
|
||||||
|
* stored is a name, prefixed with a slash, and no trailing slash.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setNamespaceAlias($alias, $fqnn)
|
||||||
|
{
|
||||||
|
$this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new Local Structural Element Name.
|
||||||
|
*
|
||||||
|
* Sets a new Local Structural Element Name. A local name also contains
|
||||||
|
* punctuation determining the kind of structural element (e.g. trailing "("
|
||||||
|
* and ")" for functions and methods).
|
||||||
|
*
|
||||||
|
* @param string $lsen The new local name of a structural element.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setLSEN($lsen)
|
||||||
|
{
|
||||||
|
$this->lsen = (string)$lsen;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new list of generics.
|
||||||
|
*
|
||||||
|
* @param string[] $generics The new list of generics.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setGenerics(array $generics)
|
||||||
|
{
|
||||||
|
$this->generics = $generics;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,422 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of phpDocumentor.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionClassConstant;
|
||||||
|
use ReflectionMethod;
|
||||||
|
use ReflectionParameter;
|
||||||
|
use ReflectionProperty;
|
||||||
|
use Reflector;
|
||||||
|
use RuntimeException;
|
||||||
|
use UnexpectedValueException;
|
||||||
|
|
||||||
|
use function define;
|
||||||
|
use function defined;
|
||||||
|
use function file_exists;
|
||||||
|
use function file_get_contents;
|
||||||
|
use function get_class;
|
||||||
|
use function in_array;
|
||||||
|
use function is_string;
|
||||||
|
use function strrpos;
|
||||||
|
use function substr;
|
||||||
|
use function token_get_all;
|
||||||
|
use function trim;
|
||||||
|
|
||||||
|
use const T_AS;
|
||||||
|
use const T_CLASS;
|
||||||
|
use const T_CURLY_OPEN;
|
||||||
|
use const T_DOLLAR_OPEN_CURLY_BRACES;
|
||||||
|
use const T_NAME_FULLY_QUALIFIED;
|
||||||
|
use const T_NAME_QUALIFIED;
|
||||||
|
use const T_NAMESPACE;
|
||||||
|
use const T_NS_SEPARATOR;
|
||||||
|
use const T_STRING;
|
||||||
|
use const T_TRAIT;
|
||||||
|
use const T_USE;
|
||||||
|
|
||||||
|
if (!defined('T_NAME_QUALIFIED')) {
|
||||||
|
define('T_NAME_QUALIFIED', 10001);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!defined('T_NAME_FULLY_QUALIFIED')) {
|
||||||
|
define('T_NAME_FULLY_QUALIFIED', 10002);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor.
|
||||||
|
*
|
||||||
|
* For a DocBlock to be able to resolve types that use partial namespace names or rely on namespace imports we need to
|
||||||
|
* provide a bit of context so that the DocBlock can read that and based on it decide how to resolve the types to
|
||||||
|
* Fully Qualified names.
|
||||||
|
*
|
||||||
|
* @see Context for more information.
|
||||||
|
*/
|
||||||
|
final class ContextFactory
|
||||||
|
{
|
||||||
|
/** The literal used at the end of a use statement. */
|
||||||
|
private const T_LITERAL_END_OF_USE = ';';
|
||||||
|
|
||||||
|
/** The literal used between sets of use statements */
|
||||||
|
private const T_LITERAL_USE_SEPARATOR = ',';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a Context given a Class Reflection.
|
||||||
|
*
|
||||||
|
* @see Context for more information on Contexts.
|
||||||
|
*/
|
||||||
|
public function createFromReflector(Reflector $reflector): Context
|
||||||
|
{
|
||||||
|
if ($reflector instanceof ReflectionClass) {
|
||||||
|
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
|
||||||
|
/** @var ReflectionClass<object> $reflector */
|
||||||
|
|
||||||
|
return $this->createFromReflectionClass($reflector);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reflector instanceof ReflectionParameter) {
|
||||||
|
return $this->createFromReflectionParameter($reflector);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reflector instanceof ReflectionMethod) {
|
||||||
|
return $this->createFromReflectionMethod($reflector);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reflector instanceof ReflectionProperty) {
|
||||||
|
return $this->createFromReflectionProperty($reflector);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reflector instanceof ReflectionClassConstant) {
|
||||||
|
return $this->createFromReflectionClassConstant($reflector);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnexpectedValueException('Unhandled \Reflector instance given: ' . get_class($reflector));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createFromReflectionParameter(ReflectionParameter $parameter): Context
|
||||||
|
{
|
||||||
|
$class = $parameter->getDeclaringClass();
|
||||||
|
if (!$class) {
|
||||||
|
throw new InvalidArgumentException('Unable to get class of ' . $parameter->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->createFromReflectionClass($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createFromReflectionMethod(ReflectionMethod $method): Context
|
||||||
|
{
|
||||||
|
$class = $method->getDeclaringClass();
|
||||||
|
|
||||||
|
return $this->createFromReflectionClass($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createFromReflectionProperty(ReflectionProperty $property): Context
|
||||||
|
{
|
||||||
|
$class = $property->getDeclaringClass();
|
||||||
|
|
||||||
|
return $this->createFromReflectionClass($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createFromReflectionClassConstant(ReflectionClassConstant $constant): Context
|
||||||
|
{
|
||||||
|
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
|
||||||
|
/** @phpstan-var ReflectionClass<object> $class */
|
||||||
|
$class = $constant->getDeclaringClass();
|
||||||
|
|
||||||
|
return $this->createFromReflectionClass($class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-param ReflectionClass<object> $class
|
||||||
|
*/
|
||||||
|
private function createFromReflectionClass(ReflectionClass $class): Context
|
||||||
|
{
|
||||||
|
$fileName = $class->getFileName();
|
||||||
|
$namespace = $class->getNamespaceName();
|
||||||
|
|
||||||
|
if (is_string($fileName) && file_exists($fileName)) {
|
||||||
|
$contents = file_get_contents($fileName);
|
||||||
|
if ($contents === false) {
|
||||||
|
throw new RuntimeException('Unable to read file "' . $fileName . '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->createForNamespace($namespace, $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Context($namespace, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a Context for a namespace in the provided file contents.
|
||||||
|
*
|
||||||
|
* @see Context for more information on Contexts.
|
||||||
|
*
|
||||||
|
* @param string $namespace It does not matter if a `\` precedes the namespace name,
|
||||||
|
* this method first normalizes.
|
||||||
|
* @param string $fileContents The file's contents to retrieve the aliases from with the given namespace.
|
||||||
|
*/
|
||||||
|
public function createForNamespace(string $namespace, string $fileContents): Context
|
||||||
|
{
|
||||||
|
$namespace = trim($namespace, '\\');
|
||||||
|
$useStatements = [];
|
||||||
|
$currentNamespace = '';
|
||||||
|
$tokens = new ArrayIterator(token_get_all($fileContents));
|
||||||
|
|
||||||
|
while ($tokens->valid()) {
|
||||||
|
$currentToken = $tokens->current();
|
||||||
|
switch ($currentToken[0]) {
|
||||||
|
case T_NAMESPACE:
|
||||||
|
$currentNamespace = $this->parseNamespace($tokens);
|
||||||
|
break;
|
||||||
|
case T_CLASS:
|
||||||
|
case T_TRAIT:
|
||||||
|
// Fast-forward the iterator through the class so that any
|
||||||
|
// T_USE tokens found within are skipped - these are not
|
||||||
|
// valid namespace use statements so should be ignored.
|
||||||
|
$braceLevel = 0;
|
||||||
|
$firstBraceFound = false;
|
||||||
|
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
|
||||||
|
$currentToken = $tokens->current();
|
||||||
|
if (
|
||||||
|
$currentToken === '{'
|
||||||
|
|| in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true)
|
||||||
|
) {
|
||||||
|
if (!$firstBraceFound) {
|
||||||
|
$firstBraceFound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++$braceLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currentToken === '}') {
|
||||||
|
--$braceLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tokens->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case T_USE:
|
||||||
|
if ($currentNamespace === $namespace) {
|
||||||
|
$useStatements += $this->parseUseStatement($tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tokens->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Context($namespace, $useStatements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deduce the name from tokens when we are at the T_NAMESPACE token.
|
||||||
|
*
|
||||||
|
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
|
||||||
|
*/
|
||||||
|
private function parseNamespace(ArrayIterator $tokens): string
|
||||||
|
{
|
||||||
|
// skip to the first string or namespace separator
|
||||||
|
$this->skipToNextStringOrNamespaceSeparator($tokens);
|
||||||
|
|
||||||
|
$name = '';
|
||||||
|
$acceptedTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED];
|
||||||
|
while ($tokens->valid() && in_array($tokens->current()[0], $acceptedTokens, true)) {
|
||||||
|
$name .= $tokens->current()[1];
|
||||||
|
$tokens->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deduce the names of all imports when we are at the T_USE token.
|
||||||
|
*
|
||||||
|
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
* @psalm-return array<string, string>
|
||||||
|
*/
|
||||||
|
private function parseUseStatement(ArrayIterator $tokens): array
|
||||||
|
{
|
||||||
|
$uses = [];
|
||||||
|
|
||||||
|
while ($tokens->valid()) {
|
||||||
|
$this->skipToNextStringOrNamespaceSeparator($tokens);
|
||||||
|
|
||||||
|
$uses += $this->extractUseStatements($tokens);
|
||||||
|
$currentToken = $tokens->current();
|
||||||
|
if ($currentToken[0] === self::T_LITERAL_END_OF_USE) {
|
||||||
|
return $uses;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $uses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.
|
||||||
|
*
|
||||||
|
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
|
||||||
|
*/
|
||||||
|
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens): void
|
||||||
|
{
|
||||||
|
while ($tokens->valid()) {
|
||||||
|
$currentToken = $tokens->current();
|
||||||
|
if (in_array($currentToken[0], [T_STRING, T_NS_SEPARATOR], true)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currentToken[0] === T_NAME_QUALIFIED) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined('T_NAME_FULLY_QUALIFIED') && $currentToken[0] === T_NAME_FULLY_QUALIFIED) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tokens->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of
|
||||||
|
* a USE statement yet. This will return a key/value array of the alias => namespace.
|
||||||
|
*
|
||||||
|
* @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
* @psalm-return array<string, string>
|
||||||
|
*
|
||||||
|
* @psalm-suppress TypeDoesNotContainType
|
||||||
|
*/
|
||||||
|
private function extractUseStatements(ArrayIterator $tokens): array
|
||||||
|
{
|
||||||
|
$extractedUseStatements = [];
|
||||||
|
$groupedNs = '';
|
||||||
|
$currentNs = '';
|
||||||
|
$currentAlias = '';
|
||||||
|
$state = 'start';
|
||||||
|
|
||||||
|
while ($tokens->valid()) {
|
||||||
|
$currentToken = $tokens->current();
|
||||||
|
$tokenId = is_string($currentToken) ? $currentToken : $currentToken[0];
|
||||||
|
$tokenValue = is_string($currentToken) ? null : $currentToken[1];
|
||||||
|
switch ($state) {
|
||||||
|
case 'start':
|
||||||
|
switch ($tokenId) {
|
||||||
|
case T_STRING:
|
||||||
|
case T_NS_SEPARATOR:
|
||||||
|
$currentNs .= (string) $tokenValue;
|
||||||
|
$currentAlias = $tokenValue;
|
||||||
|
break;
|
||||||
|
case T_NAME_QUALIFIED:
|
||||||
|
case T_NAME_FULLY_QUALIFIED:
|
||||||
|
$currentNs .= (string) $tokenValue;
|
||||||
|
$currentAlias = substr(
|
||||||
|
(string) $tokenValue,
|
||||||
|
(int) (strrpos((string) $tokenValue, '\\')) + 1
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case T_CURLY_OPEN:
|
||||||
|
case '{':
|
||||||
|
$state = 'grouped';
|
||||||
|
$groupedNs = $currentNs;
|
||||||
|
break;
|
||||||
|
case T_AS:
|
||||||
|
$state = 'start-alias';
|
||||||
|
break;
|
||||||
|
case self::T_LITERAL_USE_SEPARATOR:
|
||||||
|
case self::T_LITERAL_END_OF_USE:
|
||||||
|
$state = 'end';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'start-alias':
|
||||||
|
switch ($tokenId) {
|
||||||
|
case T_STRING:
|
||||||
|
$currentAlias = $tokenValue;
|
||||||
|
break;
|
||||||
|
case self::T_LITERAL_USE_SEPARATOR:
|
||||||
|
case self::T_LITERAL_END_OF_USE:
|
||||||
|
$state = 'end';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'grouped':
|
||||||
|
switch ($tokenId) {
|
||||||
|
case T_STRING:
|
||||||
|
case T_NS_SEPARATOR:
|
||||||
|
$currentNs .= (string) $tokenValue;
|
||||||
|
$currentAlias = $tokenValue;
|
||||||
|
break;
|
||||||
|
case T_AS:
|
||||||
|
$state = 'grouped-alias';
|
||||||
|
break;
|
||||||
|
case self::T_LITERAL_USE_SEPARATOR:
|
||||||
|
$state = 'grouped';
|
||||||
|
$extractedUseStatements[(string) $currentAlias] = $currentNs;
|
||||||
|
$currentNs = $groupedNs;
|
||||||
|
$currentAlias = '';
|
||||||
|
break;
|
||||||
|
case self::T_LITERAL_END_OF_USE:
|
||||||
|
$state = 'end';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'grouped-alias':
|
||||||
|
switch ($tokenId) {
|
||||||
|
case T_STRING:
|
||||||
|
$currentAlias = $tokenValue;
|
||||||
|
break;
|
||||||
|
case self::T_LITERAL_USE_SEPARATOR:
|
||||||
|
$state = 'grouped';
|
||||||
|
$extractedUseStatements[(string) $currentAlias] = $currentNs;
|
||||||
|
$currentNs = $groupedNs;
|
||||||
|
$currentAlias = '';
|
||||||
|
break;
|
||||||
|
case self::T_LITERAL_END_OF_USE:
|
||||||
|
$state = 'end';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($state === 'end') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tokens->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($groupedNs !== $currentNs) {
|
||||||
|
$extractedUseStatements[(string) $currentAlias] = $currentNs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $extractedUseStatements;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,223 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a Description of a DocBlock or tag.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class Description implements \Reflector
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
protected $contents = '';
|
||||||
|
|
||||||
|
/** @var array The contents, as an array of strings and Tag objects. */
|
||||||
|
protected $parsedContents = null;
|
||||||
|
|
||||||
|
/** @var DocBlock The DocBlock which this description belongs to. */
|
||||||
|
protected $docblock = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the fields of a description.
|
||||||
|
*
|
||||||
|
* @param string $content The description's contents.
|
||||||
|
* @param DocBlock $docblock The DocBlock which this description belongs to.
|
||||||
|
*/
|
||||||
|
public function __construct($content, ?DocBlock $docblock = null)
|
||||||
|
{
|
||||||
|
$this->setContent($content)->setDocBlock($docblock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text of this description.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getContents()
|
||||||
|
{
|
||||||
|
return $this->contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the text of this description.
|
||||||
|
*
|
||||||
|
* @param string $content The new text of this description.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
$this->contents = trim($content);
|
||||||
|
|
||||||
|
$this->parsedContents = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the parsed text of this description.
|
||||||
|
*
|
||||||
|
* @return array An array of strings and tag objects, in the order they
|
||||||
|
* occur within the description.
|
||||||
|
*/
|
||||||
|
public function getParsedContents()
|
||||||
|
{
|
||||||
|
if (null === $this->parsedContents) {
|
||||||
|
$this->parsedContents = preg_split(
|
||||||
|
'/\{
|
||||||
|
# "{@}" is not a valid inline tag. This ensures that
|
||||||
|
# we do not treat it as one, but treat it literally.
|
||||||
|
(?!@\})
|
||||||
|
# We want to capture the whole tag line, but without the
|
||||||
|
# inline tag delimiters.
|
||||||
|
(\@
|
||||||
|
# Match everything up to the next delimiter.
|
||||||
|
[^{}]*
|
||||||
|
# Nested inline tag content should not be captured, or
|
||||||
|
# it will appear in the result separately.
|
||||||
|
(?:
|
||||||
|
# Match nested inline tags.
|
||||||
|
(?:
|
||||||
|
# Because we did not catch the tag delimiters
|
||||||
|
# earlier, we must be explicit with them here.
|
||||||
|
# Notice that this also matches "{}", as a way
|
||||||
|
# to later introduce it as an escape sequence.
|
||||||
|
\{(?1)?\}
|
||||||
|
|
|
||||||
|
# Make sure we match hanging "{".
|
||||||
|
\{
|
||||||
|
)
|
||||||
|
# Match content after the nested inline tag.
|
||||||
|
[^{}]*
|
||||||
|
)* # If there are more inline tags, match them as well.
|
||||||
|
# We use "*" since there may not be any nested inline
|
||||||
|
# tags.
|
||||||
|
)
|
||||||
|
\}/Sux',
|
||||||
|
$this->contents,
|
||||||
|
-1,
|
||||||
|
PREG_SPLIT_DELIM_CAPTURE
|
||||||
|
);
|
||||||
|
|
||||||
|
$count = count($this->parsedContents);
|
||||||
|
for ($i=1; $i<$count; $i += 2) {
|
||||||
|
$this->parsedContents[$i] = Tag::createInstance(
|
||||||
|
$this->parsedContents[$i],
|
||||||
|
$this->docblock
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//In order to allow "literal" inline tags, the otherwise invalid
|
||||||
|
//sequence "{@}" is changed to "@", and "{}" is changed to "}".
|
||||||
|
//See unit tests for examples.
|
||||||
|
for ($i=0; $i<$count; $i += 2) {
|
||||||
|
$this->parsedContents[$i] = str_replace(
|
||||||
|
array('{@}', '{}'),
|
||||||
|
array('@', '}'),
|
||||||
|
$this->parsedContents[$i]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->parsedContents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a formatted variant of the Long Description using MarkDown.
|
||||||
|
*
|
||||||
|
* @todo this should become a more intelligent piece of code where the
|
||||||
|
* configuration contains a setting what format long descriptions are.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore Will be removed soon, in favor of adapters at
|
||||||
|
* PhpDocumentor itself that will process text in various formats.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFormattedContents()
|
||||||
|
{
|
||||||
|
$result = $this->contents;
|
||||||
|
|
||||||
|
// if the long description contains a plain HTML <code> element, surround
|
||||||
|
// it with a pre element. Please note that we explicitly used str_replace
|
||||||
|
// and not preg_replace to gain performance
|
||||||
|
if (strpos($result, '<code>') !== false) {
|
||||||
|
$result = str_replace(
|
||||||
|
array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'),
|
||||||
|
array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'),
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (class_exists('Parsedown')) {
|
||||||
|
$markdown = \Parsedown::instance();
|
||||||
|
$result = $markdown->parse($result);
|
||||||
|
} elseif (class_exists('dflydev\markdown\MarkdownExtraParser')) {
|
||||||
|
$markdown = new \dflydev\markdown\MarkdownExtraParser();
|
||||||
|
$result = $markdown->transformMarkdown($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the docblock this tag belongs to.
|
||||||
|
*
|
||||||
|
* @return DocBlock The docblock this description belongs to.
|
||||||
|
*/
|
||||||
|
public function getDocBlock()
|
||||||
|
{
|
||||||
|
return $this->docblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the docblock this tag belongs to.
|
||||||
|
*
|
||||||
|
* @param DocBlock $docblock The new docblock this description belongs to.
|
||||||
|
* Setting NULL removes any association.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDocBlock(?DocBlock $docblock = null)
|
||||||
|
{
|
||||||
|
$this->docblock = $docblock;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a string representation of this object.
|
||||||
|
*
|
||||||
|
* @todo determine the exact format as used by PHP Reflection
|
||||||
|
* and implement it.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @codeCoverageIgnore Not yet implemented
|
||||||
|
*/
|
||||||
|
public static function export()
|
||||||
|
{
|
||||||
|
throw new \Exception('Not yet implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the long description as a string.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->getContents();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The location a DocBlock occurs within a file.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class Location
|
||||||
|
{
|
||||||
|
/** @var int Line where the DocBlock text starts. */
|
||||||
|
protected $lineNumber = 0;
|
||||||
|
|
||||||
|
/** @var int Column where the DocBlock text starts. */
|
||||||
|
protected $columnNumber = 0;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
$lineNumber = 0,
|
||||||
|
$columnNumber = 0
|
||||||
|
) {
|
||||||
|
$this->setLineNumber($lineNumber)->setColumnNumber($columnNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int Line where the DocBlock text starts.
|
||||||
|
*/
|
||||||
|
public function getLineNumber()
|
||||||
|
{
|
||||||
|
return $this->lineNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type $lineNumber
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setLineNumber($lineNumber)
|
||||||
|
{
|
||||||
|
$this->lineNumber = (int)$lineNumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int Column where the DocBlock text starts.
|
||||||
|
*/
|
||||||
|
public function getColumnNumber()
|
||||||
|
{
|
||||||
|
return $this->columnNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $columnNumber
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setColumnNumber($columnNumber)
|
||||||
|
{
|
||||||
|
$this->columnNumber = (int)$columnNumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
|
* @copyright 2013 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes a DocBlock instance.
|
||||||
|
*
|
||||||
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class Serializer
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var string The string to indent the comment with. */
|
||||||
|
protected $indentString = ' ';
|
||||||
|
|
||||||
|
/** @var int The number of times the indent string is repeated. */
|
||||||
|
protected $indent = 0;
|
||||||
|
|
||||||
|
/** @var bool Whether to indent the first line. */
|
||||||
|
protected $isFirstLineIndented = true;
|
||||||
|
|
||||||
|
/** @var int|null The max length of a line. */
|
||||||
|
protected $lineLength = null;
|
||||||
|
|
||||||
|
/** @var bool Separate tag groups. */
|
||||||
|
protected $separateTags = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Serializer instance.
|
||||||
|
*
|
||||||
|
* @param int $indent The number of times the indent string is
|
||||||
|
* repeated.
|
||||||
|
* @param string $indentString The string to indent the comment with.
|
||||||
|
* @param bool $indentFirstLine Whether to indent the first line.
|
||||||
|
* @param int|null $lineLength The max length of a line or NULL to
|
||||||
|
* disable line wrapping.
|
||||||
|
* @param bool $separateTags Separate tag groups.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$indent = 0,
|
||||||
|
$indentString = ' ',
|
||||||
|
$indentFirstLine = true,
|
||||||
|
$lineLength = null,
|
||||||
|
$separateTags = false
|
||||||
|
) {
|
||||||
|
$this->setIndentationString($indentString);
|
||||||
|
$this->setIndent($indent);
|
||||||
|
$this->setIsFirstLineIndented($indentFirstLine);
|
||||||
|
$this->setLineLength($lineLength);
|
||||||
|
$this->setSeparateTags($separateTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the string to indent comments with.
|
||||||
|
*
|
||||||
|
* @param string $indentationString The string to indent comments with.
|
||||||
|
*
|
||||||
|
* @return $this This serializer object.
|
||||||
|
*/
|
||||||
|
public function setIndentationString($indentString)
|
||||||
|
{
|
||||||
|
$this->indentString = (string)$indentString;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the string to indent comments with.
|
||||||
|
*
|
||||||
|
* @return string The indent string.
|
||||||
|
*/
|
||||||
|
public function getIndentationString()
|
||||||
|
{
|
||||||
|
return $this->indentString;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the number of indents.
|
||||||
|
*
|
||||||
|
* @param int $indent The number of times the indent string is repeated.
|
||||||
|
*
|
||||||
|
* @return $this This serializer object.
|
||||||
|
*/
|
||||||
|
public function setIndent($indent)
|
||||||
|
{
|
||||||
|
$this->indent = (int)$indent;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of indents.
|
||||||
|
*
|
||||||
|
* @return int The number of times the indent string is repeated.
|
||||||
|
*/
|
||||||
|
public function getIndent()
|
||||||
|
{
|
||||||
|
return $this->indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not the first line should be indented.
|
||||||
|
*
|
||||||
|
* Sets whether or not the first line (the one with the "/**") should be
|
||||||
|
* indented.
|
||||||
|
*
|
||||||
|
* @param bool $indentFirstLine The new value for this setting.
|
||||||
|
*
|
||||||
|
* @return $this This serializer object.
|
||||||
|
*/
|
||||||
|
public function setIsFirstLineIndented($indentFirstLine)
|
||||||
|
{
|
||||||
|
$this->isFirstLineIndented = (bool)$indentFirstLine;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether or not the first line should be indented.
|
||||||
|
*
|
||||||
|
* @return bool Whether or not the first line should be indented.
|
||||||
|
*/
|
||||||
|
public function isFirstLineIndented()
|
||||||
|
{
|
||||||
|
return $this->isFirstLineIndented;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the line length.
|
||||||
|
*
|
||||||
|
* Sets the length of each line in the serialization. Content will be
|
||||||
|
* wrapped within this limit.
|
||||||
|
*
|
||||||
|
* @param int|null $lineLength The length of each line. NULL to disable line
|
||||||
|
* wrapping altogether.
|
||||||
|
*
|
||||||
|
* @return $this This serializer object.
|
||||||
|
*/
|
||||||
|
public function setLineLength($lineLength)
|
||||||
|
{
|
||||||
|
$this->lineLength = null === $lineLength ? null : (int)$lineLength;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the line length.
|
||||||
|
*
|
||||||
|
* @return int|null The length of each line or NULL if line wrapping is
|
||||||
|
* disabled.
|
||||||
|
*/
|
||||||
|
public function getLineLength()
|
||||||
|
{
|
||||||
|
return $this->lineLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether there should be an empty line between tag groups.
|
||||||
|
*
|
||||||
|
* @param bool $separateTags The new value for this setting.
|
||||||
|
*
|
||||||
|
* @return $this This serializer object.
|
||||||
|
*/
|
||||||
|
public function setSeparateTags($separateTags)
|
||||||
|
{
|
||||||
|
$this->separateTags = (bool)$separateTags;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether there should be an empty line between tag groups.
|
||||||
|
*
|
||||||
|
* @return bool Whether there should be an empty line between tag groups.
|
||||||
|
*/
|
||||||
|
public function getSeparateTags()
|
||||||
|
{
|
||||||
|
return $this->separateTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a DocBlock comment.
|
||||||
|
*
|
||||||
|
* @param DocBlock The DocBlock to serialize.
|
||||||
|
*
|
||||||
|
* @return string The serialized doc block.
|
||||||
|
*/
|
||||||
|
public function getDocComment(DocBlock $docblock)
|
||||||
|
{
|
||||||
|
$indent = str_repeat($this->indentString, $this->indent);
|
||||||
|
$firstIndent = $this->isFirstLineIndented ? $indent : '';
|
||||||
|
|
||||||
|
$text = $docblock->getText();
|
||||||
|
if ($this->lineLength) {
|
||||||
|
//3 === strlen(' * ')
|
||||||
|
$wrapLength = $this->lineLength - strlen($indent) - 3;
|
||||||
|
$text = wordwrap($text, $wrapLength);
|
||||||
|
}
|
||||||
|
$text = str_replace("\n", "\n{$indent} * ", $text);
|
||||||
|
$text = preg_replace('/^(\s*\*)[ \t]+$/m', '$1', $text);
|
||||||
|
|
||||||
|
$comment = !empty($text)? "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n" : "{$firstIndent}/**\n";
|
||||||
|
|
||||||
|
$tags = array_values($docblock->getTags());
|
||||||
|
|
||||||
|
/** @var Tag $tag */
|
||||||
|
foreach ($tags as $key => $tag) {
|
||||||
|
$nextTag = isset($tags[$key + 1]) ? $tags[$key + 1] : null;
|
||||||
|
|
||||||
|
$tagText = (string) $tag;
|
||||||
|
if ($this->lineLength) {
|
||||||
|
$tagText = wordwrap($tagText, $wrapLength);
|
||||||
|
}
|
||||||
|
$tagText = str_replace("\n", "\n{$indent} * ", $tagText);
|
||||||
|
$tagText = preg_replace('/^(\s*\*)[ \t]+$/m', '$1', $tagText);
|
||||||
|
|
||||||
|
$comment .= "{$indent} * {$tagText}\n";
|
||||||
|
|
||||||
|
if ($this->separateTags && $nextTag !== null && ! $tag->inSameGroup($nextTag)) {
|
||||||
|
$comment .= "{$indent} *\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$comment .= $indent . ' */';
|
||||||
|
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,414 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a tag definition for a DocBlock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class Tag implements \Reflector
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* PCRE regular expression matching a tag name.
|
||||||
|
*/
|
||||||
|
const REGEX_TAGNAME = '[\w\-\_\\\\]+';
|
||||||
|
|
||||||
|
/** @var string Name of the tag */
|
||||||
|
protected $tag = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|null Content of the tag.
|
||||||
|
* When set to NULL, it means it needs to be regenerated.
|
||||||
|
*/
|
||||||
|
protected $content = '';
|
||||||
|
|
||||||
|
/** @var string Description of the content of this tag */
|
||||||
|
protected $description = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|null The description, as an array of strings and Tag objects.
|
||||||
|
* When set to NULL, it means it needs to be regenerated.
|
||||||
|
*/
|
||||||
|
protected $parsedDescription = null;
|
||||||
|
|
||||||
|
/** @var Location Location of the tag. */
|
||||||
|
protected $location = null;
|
||||||
|
|
||||||
|
/** @var DocBlock The DocBlock which this tag belongs to. */
|
||||||
|
protected $docblock = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array An array with a tag as a key, and an FQCN to a class that
|
||||||
|
* handles it as an array value. The class is expected to inherit this
|
||||||
|
* class.
|
||||||
|
*/
|
||||||
|
private static $tagHandlerMappings = array(
|
||||||
|
'author'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\AuthorTag',
|
||||||
|
'covers'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\CoversTag',
|
||||||
|
'deprecated'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\DeprecatedTag',
|
||||||
|
'example'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\ExampleTag',
|
||||||
|
'link'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\LinkTag',
|
||||||
|
'method'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\MethodTag',
|
||||||
|
'param'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\ParamTag',
|
||||||
|
'property-read'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\PropertyReadTag',
|
||||||
|
'property'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\PropertyTag',
|
||||||
|
'property-write'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\PropertyWriteTag',
|
||||||
|
'return'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\ReturnTag',
|
||||||
|
'see'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\SeeTag',
|
||||||
|
'since'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\SinceTag',
|
||||||
|
'source'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\SourceTag',
|
||||||
|
'throw'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\ThrowsTag',
|
||||||
|
'throws'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\ThrowsTag',
|
||||||
|
'uses'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\UsesTag',
|
||||||
|
'var'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\VarTag',
|
||||||
|
'version'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\VersionTag',
|
||||||
|
'SuppressWarnings'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag',
|
||||||
|
'template'
|
||||||
|
=> '\Barryvdh\Reflection\DocBlock\Tag\TemplateTag'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method responsible for instantiating the correct sub type.
|
||||||
|
*
|
||||||
|
* @param string $tag_line The text for this tag, including description.
|
||||||
|
* @param DocBlock $docblock The DocBlock which this tag belongs to.
|
||||||
|
* @param Location $location Location of the tag.
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException if an invalid tag line was presented.
|
||||||
|
*
|
||||||
|
* @return static A new tag object.
|
||||||
|
*/
|
||||||
|
final public static function createInstance(
|
||||||
|
$tag_line,
|
||||||
|
?DocBlock $docblock = null,
|
||||||
|
?Location $location = null
|
||||||
|
) {
|
||||||
|
if (!preg_match(
|
||||||
|
'/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us',
|
||||||
|
$tag_line,
|
||||||
|
$matches
|
||||||
|
)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Invalid tag_line detected: ' . $tag_line
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$handler = __CLASS__;
|
||||||
|
if (isset(self::$tagHandlerMappings[$matches[1]])) {
|
||||||
|
$handler = self::$tagHandlerMappings[$matches[1]];
|
||||||
|
} elseif (isset($docblock)) {
|
||||||
|
$tagName = (string)new Type\Collection(
|
||||||
|
array($matches[1]),
|
||||||
|
$docblock->getContext()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset(self::$tagHandlerMappings[$tagName])) {
|
||||||
|
$handler = self::$tagHandlerMappings[$tagName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $handler(
|
||||||
|
$matches[1],
|
||||||
|
isset($matches[2]) ? $matches[2] : '',
|
||||||
|
$docblock,
|
||||||
|
$location
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a handler for tags.
|
||||||
|
*
|
||||||
|
* Registers a handler for tags. The class specified is autoloaded if it's
|
||||||
|
* not available. It must inherit from this class.
|
||||||
|
*
|
||||||
|
* @param string $tag Name of tag to regiser a handler for. When
|
||||||
|
* registering a namespaced tag, the full name, along with a prefixing
|
||||||
|
* slash MUST be provided.
|
||||||
|
* @param string|null $handler FQCN of handler. Specifing NULL removes the
|
||||||
|
* handler for the specified tag, if any.
|
||||||
|
*
|
||||||
|
* @return bool TRUE on success, FALSE on failure.
|
||||||
|
*/
|
||||||
|
final public static function registerTagHandler($tag, $handler)
|
||||||
|
{
|
||||||
|
$tag = trim((string)$tag);
|
||||||
|
|
||||||
|
if (null === $handler) {
|
||||||
|
unset(self::$tagHandlerMappings[$tag]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('' !== $tag
|
||||||
|
&& class_exists($handler, true)
|
||||||
|
&& is_subclass_of($handler, __CLASS__)
|
||||||
|
&& !strpos($tag, '\\') //Accept no slash, and 1st slash at offset 0.
|
||||||
|
) {
|
||||||
|
self::$tagHandlerMappings[$tag] = $handler;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a tag and populates the member variables.
|
||||||
|
*
|
||||||
|
* @param string $name Name of the tag.
|
||||||
|
* @param string $content The contents of the given tag.
|
||||||
|
* @param DocBlock $docblock The DocBlock which this tag belongs to.
|
||||||
|
* @param Location $location Location of the tag.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
$name,
|
||||||
|
$content,
|
||||||
|
?DocBlock $docblock = null,
|
||||||
|
?Location $location = null
|
||||||
|
) {
|
||||||
|
$this
|
||||||
|
->setName($name)
|
||||||
|
->setContent($content)
|
||||||
|
->setDocBlock($docblock)
|
||||||
|
->setLocation($location);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this tag.
|
||||||
|
*
|
||||||
|
* @return string The name of this tag.
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of this tag.
|
||||||
|
*
|
||||||
|
* @param string $name The new name of this tag.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
* @throws \InvalidArgumentException When an invalid tag name is provided.
|
||||||
|
*/
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
if (!preg_match('/^' . self::REGEX_TAGNAME . '$/u', $name)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'Invalid tag name supplied: ' . $name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tag = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the content of this tag.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the content of this tag.
|
||||||
|
*
|
||||||
|
* @param string $content The new content of this tag.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
$this->setDescription($content);
|
||||||
|
$this->content = $content;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the description component of this tag.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDescription()
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the description component of this tag.
|
||||||
|
*
|
||||||
|
* @param string $description The new description component of this tag.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDescription($description)
|
||||||
|
{
|
||||||
|
$this->content = null;
|
||||||
|
$this->parsedDescription = null;
|
||||||
|
$this->description = trim($description);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the parsed text of this description.
|
||||||
|
*
|
||||||
|
* @return array An array of strings and tag objects, in the order they
|
||||||
|
* occur within the description.
|
||||||
|
*/
|
||||||
|
public function getParsedDescription()
|
||||||
|
{
|
||||||
|
if (null === $this->parsedDescription) {
|
||||||
|
$description = new Description($this->description, $this->docblock);
|
||||||
|
$this->parsedDescription = $description->getParsedContents();
|
||||||
|
}
|
||||||
|
return $this->parsedDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the docblock this tag belongs to.
|
||||||
|
*
|
||||||
|
* @return DocBlock The docblock this tag belongs to.
|
||||||
|
*/
|
||||||
|
public function getDocBlock()
|
||||||
|
{
|
||||||
|
return $this->docblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the docblock this tag belongs to.
|
||||||
|
*
|
||||||
|
* @param DocBlock $docblock The new docblock this tag belongs to. Setting
|
||||||
|
* NULL removes any association.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDocBlock(?DocBlock $docblock = null)
|
||||||
|
{
|
||||||
|
$this->docblock = $docblock;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location of the tag.
|
||||||
|
*
|
||||||
|
* @return Location The tag's location.
|
||||||
|
*/
|
||||||
|
public function getLocation()
|
||||||
|
{
|
||||||
|
return $this->location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the location of the tag.
|
||||||
|
*
|
||||||
|
* @param Location $location The new location of the tag.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setLocation(?Location $location = null)
|
||||||
|
{
|
||||||
|
$this->location = $location;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the given tags should be together or apart.
|
||||||
|
*
|
||||||
|
* @param Tag $tag
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function inSameGroup(Tag $tag)
|
||||||
|
{
|
||||||
|
$firstName = $this->getName();
|
||||||
|
$secondName = $tag->getName();
|
||||||
|
|
||||||
|
if ($firstName === $secondName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$groups = array(
|
||||||
|
array('deprecated', 'link', 'see', 'since'),
|
||||||
|
array('author', 'copyright', 'license'),
|
||||||
|
array('category', 'package', 'subpackage'),
|
||||||
|
array('property', 'property-read', 'property-write'),
|
||||||
|
array('param', 'return'),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
if (in_array($firstName, $group, true) && in_array($secondName, $group, true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a string representation of this object.
|
||||||
|
*
|
||||||
|
* @todo determine the exact format as used by PHP Reflection and implement it.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @codeCoverageIgnore Not yet implemented
|
||||||
|
*/
|
||||||
|
public static function export()
|
||||||
|
{
|
||||||
|
throw new \Exception('Not yet implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the tag as a serialized string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return trim("@{$this->getName()} {$this->getContent()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for an @author tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class AuthorTag extends Tag
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* PCRE regular expression matching any valid value for the name component.
|
||||||
|
*/
|
||||||
|
const REGEX_AUTHOR_NAME = '[^\<]*';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PCRE regular expression matching any valid value for the email component.
|
||||||
|
*/
|
||||||
|
const REGEX_AUTHOR_EMAIL = '[^\>]*';
|
||||||
|
|
||||||
|
/** @var string The name of the author */
|
||||||
|
protected $authorName = '';
|
||||||
|
|
||||||
|
/** @var string The email of the author */
|
||||||
|
protected $authorEmail = '';
|
||||||
|
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = $this->authorName;
|
||||||
|
if ('' != $this->authorEmail) {
|
||||||
|
$this->content .= "<{$this->authorEmail}>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
parent::setContent($content);
|
||||||
|
if (preg_match(
|
||||||
|
'/^(' . self::REGEX_AUTHOR_NAME .
|
||||||
|
')(\<(' . self::REGEX_AUTHOR_EMAIL .
|
||||||
|
')\>)?$/u',
|
||||||
|
$this->description,
|
||||||
|
$matches
|
||||||
|
)) {
|
||||||
|
$this->authorName = trim($matches[1]);
|
||||||
|
if (isset($matches[3])) {
|
||||||
|
$this->authorEmail = trim($matches[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the author's name.
|
||||||
|
*
|
||||||
|
* @return string The author's name.
|
||||||
|
*/
|
||||||
|
public function getAuthorName()
|
||||||
|
{
|
||||||
|
return $this->authorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the author's name.
|
||||||
|
*
|
||||||
|
* @param string $authorName The new author name.
|
||||||
|
* An invalid value will set an empty string.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setAuthorName($authorName)
|
||||||
|
{
|
||||||
|
$this->content = null;
|
||||||
|
$this->authorName
|
||||||
|
= preg_match('/^' . self::REGEX_AUTHOR_NAME . '$/u', $authorName)
|
||||||
|
? $authorName : '';
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the author's email.
|
||||||
|
*
|
||||||
|
* @return string The author's email.
|
||||||
|
*/
|
||||||
|
public function getAuthorEmail()
|
||||||
|
{
|
||||||
|
return $this->authorEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the author's email.
|
||||||
|
*
|
||||||
|
* @param string $authorEmail The new author email.
|
||||||
|
* An invalid value will set an empty string.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setAuthorEmail($authorEmail)
|
||||||
|
{
|
||||||
|
$this->authorEmail
|
||||||
|
= preg_match('/^' . self::REGEX_AUTHOR_EMAIL . '$/u', $authorEmail)
|
||||||
|
? $authorEmail : '';
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-3
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor
|
* phpDocumentor
|
||||||
*
|
*
|
||||||
* PHP Version 5
|
* PHP Version 5.3
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
* @link http://phpdoc.org
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for a @covers tag in a Docblock.
|
* Reflection class for a @covers tag in a Docblock.
|
||||||
@@ -21,5 +21,4 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|||||||
*/
|
*/
|
||||||
class CoversTag extends SeeTag
|
class CoversTag extends SeeTag
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag\VersionTag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @deprecated tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class DeprecatedTag extends VersionTag
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @example tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ExampleTag extends SourceTag
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string Path to a file to use as an example.
|
||||||
|
* May also be an absolute URI.
|
||||||
|
*/
|
||||||
|
protected $filePath = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool Whether the file path component represents an URI.
|
||||||
|
* This determines how the file portion appears at {@link getContent()}.
|
||||||
|
*/
|
||||||
|
protected $isURI = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$filePath = '';
|
||||||
|
if ($this->isURI) {
|
||||||
|
if (false === strpos($this->filePath, ':')) {
|
||||||
|
$filePath = str_replace(
|
||||||
|
'%2F',
|
||||||
|
'/',
|
||||||
|
rawurlencode($this->filePath)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$filePath = $this->filePath;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$filePath = '"' . $this->filePath . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->content = $filePath . ' ' . parent::getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
Tag::setContent($content);
|
||||||
|
if (preg_match(
|
||||||
|
'/^
|
||||||
|
# File component
|
||||||
|
(?:
|
||||||
|
# File path in quotes
|
||||||
|
\"([^\"]+)\"
|
||||||
|
|
|
||||||
|
# File URI
|
||||||
|
(\S+)
|
||||||
|
)
|
||||||
|
# Remaining content (parsed by SourceTag)
|
||||||
|
(?:\s+(.*))?
|
||||||
|
$/sux',
|
||||||
|
$this->description,
|
||||||
|
$matches
|
||||||
|
)) {
|
||||||
|
if ('' !== $matches[1]) {
|
||||||
|
$this->setFilePath($matches[1]);
|
||||||
|
} else {
|
||||||
|
$this->setFileURI($matches[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($matches[3])) {
|
||||||
|
parent::setContent($matches[3]);
|
||||||
|
} else {
|
||||||
|
$this->setDescription('');
|
||||||
|
}
|
||||||
|
$this->content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the file path.
|
||||||
|
*
|
||||||
|
* @return string Path to a file to use as an example.
|
||||||
|
* May also be an absolute URI.
|
||||||
|
*/
|
||||||
|
public function getFilePath()
|
||||||
|
{
|
||||||
|
return $this->filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the file path.
|
||||||
|
*
|
||||||
|
* @param string $filePath The new file path to use for the example.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFilePath($filePath)
|
||||||
|
{
|
||||||
|
$this->isURI = false;
|
||||||
|
$this->filePath = trim($filePath);
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the file path as an URI.
|
||||||
|
*
|
||||||
|
* This function is equivalent to {@link setFilePath()}, except that it
|
||||||
|
* convers an URI to a file path before that.
|
||||||
|
*
|
||||||
|
* There is no getFileURI(), as {@link getFilePath()} is compatible.
|
||||||
|
*
|
||||||
|
* @param type $uri The new file URI to use as an example.
|
||||||
|
*/
|
||||||
|
public function setFileURI($uri)
|
||||||
|
{
|
||||||
|
$this->isURI = true;
|
||||||
|
if (false === strpos($uri, ':')) {
|
||||||
|
//Relative URL
|
||||||
|
$this->filePath = rawurldecode(
|
||||||
|
str_replace(array('/', '\\'), '%2F', $uri)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//Absolute URL or URI.
|
||||||
|
$this->filePath = $uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Ben Selby <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @link tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Ben Selby <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class LinkTag extends Tag
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
protected $link = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = "{$this->link} {$this->description}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
parent::setContent($content);
|
||||||
|
$parts = preg_split('/\s+/Su', $this->description, 2);
|
||||||
|
|
||||||
|
$this->link = $parts[0];
|
||||||
|
|
||||||
|
$this->setDescription(isset($parts[1]) ? $parts[1] : $parts[0]);
|
||||||
|
|
||||||
|
$this->content = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLink()
|
||||||
|
{
|
||||||
|
return $this->link;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the link
|
||||||
|
*
|
||||||
|
* @param string $link The link
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setLink($link)
|
||||||
|
{
|
||||||
|
$this->link = $link;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @method in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class MethodTag extends ReturnTag
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $method_name = '';
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $arguments = '';
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
protected $isStatic = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = '';
|
||||||
|
if ($this->isStatic) {
|
||||||
|
$this->content .= 'static ';
|
||||||
|
}
|
||||||
|
$this->content .= $this->type .
|
||||||
|
" {$this->method_name}({$this->arguments}) " .
|
||||||
|
$this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
Tag::setContent($content);
|
||||||
|
// 1. none or more whitespace
|
||||||
|
// 2. optionally the keyword "static" followed by whitespace
|
||||||
|
// 3. optionally a word with underscores followed by whitespace : as
|
||||||
|
// type for the return value
|
||||||
|
// 4. then optionally a word with underscores followed by () and
|
||||||
|
// whitespace : as method name as used by phpDocumentor
|
||||||
|
// 5. then a word with underscores, followed by ( and any character
|
||||||
|
// until a ) and whitespace : as method name with signature
|
||||||
|
// 6. any remaining text : as description
|
||||||
|
if (preg_match(
|
||||||
|
'/^
|
||||||
|
# Static keyword
|
||||||
|
# Declates a static method ONLY if type is also present
|
||||||
|
(?:
|
||||||
|
(static)
|
||||||
|
\s+
|
||||||
|
)?
|
||||||
|
# Return type
|
||||||
|
(?:
|
||||||
|
(
|
||||||
|
(?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
|
||||||
|
|
|
||||||
|
(?:
|
||||||
|
(?:[\w\|_\\\\]+(?:<[\s\S]*>)?)
|
||||||
|
# array notation
|
||||||
|
(?:\[\])*
|
||||||
|
)*
|
||||||
|
|
|
||||||
|
(?:\([\s\S]*\))?
|
||||||
|
)
|
||||||
|
\s+
|
||||||
|
)?
|
||||||
|
# Legacy method name (not captured)
|
||||||
|
(?:
|
||||||
|
[\w_]+\(\)\s+
|
||||||
|
)?
|
||||||
|
# Method name
|
||||||
|
([\w\|_\\\\]+)
|
||||||
|
# Arguments
|
||||||
|
\(([^\)]*)\)
|
||||||
|
\s*
|
||||||
|
# Description
|
||||||
|
(.*)
|
||||||
|
$/sux',
|
||||||
|
$this->description,
|
||||||
|
$matches
|
||||||
|
)) {
|
||||||
|
list(
|
||||||
|
,
|
||||||
|
$static,
|
||||||
|
$this->type,
|
||||||
|
$this->method_name,
|
||||||
|
$this->arguments,
|
||||||
|
$this->description
|
||||||
|
) = $matches;
|
||||||
|
if ($static) {
|
||||||
|
if (!$this->type) {
|
||||||
|
$this->type = 'static';
|
||||||
|
} else {
|
||||||
|
$this->isStatic = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!$this->type) {
|
||||||
|
$this->type = 'void';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->parsedDescription = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of this method.
|
||||||
|
*
|
||||||
|
* @param string $method_name The name of the method.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setMethodName($method_name)
|
||||||
|
{
|
||||||
|
$this->method_name = $method_name;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the method name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getMethodName()
|
||||||
|
{
|
||||||
|
return $this->method_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the arguments for this method.
|
||||||
|
*
|
||||||
|
* @param string $arguments A comma-separated arguments line.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setArguments($arguments)
|
||||||
|
{
|
||||||
|
$this->arguments = $arguments;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array containing each argument as array of type and name.
|
||||||
|
*
|
||||||
|
* Please note that the argument sub-array may only contain 1 element if no
|
||||||
|
* type was specified.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getArguments()
|
||||||
|
{
|
||||||
|
if (empty($this->arguments)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$arguments = explode(',', $this->arguments);
|
||||||
|
foreach ($arguments as $key => $value) {
|
||||||
|
$arguments[$key] = explode(' ', trim($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the method tag describes a static method or not.
|
||||||
|
*
|
||||||
|
* @return bool TRUE if the method declaration is for a static method, FALSE
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
public function isStatic()
|
||||||
|
{
|
||||||
|
return $this->isStatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new value for whether the method is static or not.
|
||||||
|
*
|
||||||
|
* @param bool $isStatic The new value to set.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setIsStatic($isStatic)
|
||||||
|
{
|
||||||
|
$this->isStatic = $isStatic;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @param tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ParamTag extends ReturnTag
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
protected $variableName = '';
|
||||||
|
|
||||||
|
/** @var bool determines whether this is a variadic argument */
|
||||||
|
protected $isVariadic = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content
|
||||||
|
= "{$this->type} {$this->variableName} {$this->description}";
|
||||||
|
}
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
Tag::setContent($content);
|
||||||
|
|
||||||
|
$parts = [];
|
||||||
|
$rest = $this->description;
|
||||||
|
|
||||||
|
// parsing generics and closures to detect types
|
||||||
|
for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) {
|
||||||
|
$char = $rest[$pos];
|
||||||
|
|
||||||
|
if(in_array($char, ['<', '(', '[', '{'])) {
|
||||||
|
array_unshift($stacks, $char);
|
||||||
|
}
|
||||||
|
if(
|
||||||
|
($char === '>' && isset($stacks[0]) && $stacks[0] === '<')
|
||||||
|
|| ($char === ')' && isset($stacks[0]) && $stacks[0] === '(')
|
||||||
|
|| ($char === ']' && isset($stacks[0]) && $stacks[0] === '[')
|
||||||
|
|| ($char === '}' && isset($stacks[0]) && $stacks[0] === '{')
|
||||||
|
) {
|
||||||
|
array_shift($stacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$stacks && preg_match('/\A(\s+)(.*)/su', substr($rest, $pos), $matches)) {
|
||||||
|
$parts[0] = substr($rest, 0, $pos);
|
||||||
|
$parts[1] = $matches[1];
|
||||||
|
$rest = $matches[2];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($parts, ...preg_split('/(\s+)/u', $rest, 2, PREG_SPLIT_DELIM_CAPTURE));
|
||||||
|
|
||||||
|
// if the first item that is encountered is not a variable; it is a type
|
||||||
|
if (isset($parts[0])
|
||||||
|
&& (strlen($parts[0]) > 0)
|
||||||
|
&& ($parts[0][0] !== '$')
|
||||||
|
) {
|
||||||
|
$this->type = array_shift($parts);
|
||||||
|
array_shift($parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the next item starts with a $ or ...$ it must be the variable name
|
||||||
|
if (isset($parts[0])
|
||||||
|
&& (strlen($parts[0]) > 0)
|
||||||
|
&& ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')
|
||||||
|
) {
|
||||||
|
$this->variableName = array_shift($parts);
|
||||||
|
array_shift($parts);
|
||||||
|
|
||||||
|
if (substr($this->variableName, 0, 3) === '...') {
|
||||||
|
$this->isVariadic = true;
|
||||||
|
$this->variableName = substr($this->variableName, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setDescription(implode('', $parts));
|
||||||
|
|
||||||
|
$this->content = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the variable's name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getVariableName()
|
||||||
|
{
|
||||||
|
return $this->variableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the variable's name.
|
||||||
|
*
|
||||||
|
* @param string $name The new name for this variable.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setVariableName($name)
|
||||||
|
{
|
||||||
|
$this->variableName = $name;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this tag is variadic.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isVariadic()
|
||||||
|
{
|
||||||
|
return $this->isVariadic;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-4
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor
|
* phpDocumentor
|
||||||
*
|
*
|
||||||
* PHP Version 5
|
* PHP Version 5.3
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
@@ -10,10 +10,10 @@
|
|||||||
* @link http://phpdoc.org
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for a {@property} tag in a Docblock.
|
* Reflection class for a @property-read tag in a Docblock.
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
@@ -21,5 +21,4 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|||||||
*/
|
*/
|
||||||
class PropertyReadTag extends PropertyTag
|
class PropertyReadTag extends PropertyTag
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor
|
* phpDocumentor
|
||||||
*
|
*
|
||||||
* PHP Version 5
|
* PHP Version 5.3
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
@@ -10,10 +10,10 @@
|
|||||||
* @link http://phpdoc.org
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for a {@property} tag in a Docblock.
|
* Reflection class for a @property tag in a Docblock.
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
@@ -21,5 +21,4 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|||||||
*/
|
*/
|
||||||
class PropertyTag extends ParamTag
|
class PropertyTag extends ParamTag
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor
|
* phpDocumentor
|
||||||
*
|
*
|
||||||
* PHP Version 5
|
* PHP Version 5.3
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
@@ -10,10 +10,10 @@
|
|||||||
* @link http://phpdoc.org
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for a {@property} tag in a Docblock.
|
* Reflection class for a @property-write tag in a Docblock.
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
@@ -21,5 +21,4 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|||||||
*/
|
*/
|
||||||
class PropertyWriteTag extends PropertyTag
|
class PropertyWriteTag extends PropertyTag
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Type\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @return tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ReturnTag extends Tag
|
||||||
|
{
|
||||||
|
/** @var string The raw type component. */
|
||||||
|
protected $type = '';
|
||||||
|
|
||||||
|
/** @var Collection The parsed type component. */
|
||||||
|
protected $types = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = "{$this->getType()} {$this->description}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
parent::setContent($content);
|
||||||
|
|
||||||
|
$parts = preg_split('/(?<!,)\s+/Su', $this->description, 2);
|
||||||
|
|
||||||
|
// any output is considered a type
|
||||||
|
$this->type = $parts[0];
|
||||||
|
$this->types = null;
|
||||||
|
|
||||||
|
$this->setDescription(isset($parts[1]) ? $parts[1] : '');
|
||||||
|
|
||||||
|
$this->content = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the unique types of the variable.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getTypes()
|
||||||
|
{
|
||||||
|
return $this->getTypesCollection()->getArrayCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type section of the variable.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return (string) $this->getTypesCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the type section of the variable
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setType($type)
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
$this->types = null;
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a type to the type section of the variable
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addType($type)
|
||||||
|
{
|
||||||
|
$this->type = $this->type . Collection::OPERATOR_OR . $type;
|
||||||
|
$this->types = null;
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type collection.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function getTypesCollection()
|
||||||
|
{
|
||||||
|
if (null === $this->types) {
|
||||||
|
$this->types = new Collection(
|
||||||
|
array($this->type),
|
||||||
|
$this->docblock ? $this->docblock->getContext() : null,
|
||||||
|
$this->docblock ? $this->docblock->getGenerics() : array()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $this->types;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @see tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SeeTag extends Tag
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
protected $refers = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = "{$this->refers} {$this->description}";
|
||||||
|
}
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
parent::setContent($content);
|
||||||
|
$parts = preg_split('/\s+/Su', $this->description, 2);
|
||||||
|
|
||||||
|
// any output is considered a type
|
||||||
|
$this->refers = $parts[0];
|
||||||
|
|
||||||
|
$this->setDescription(isset($parts[1]) ? $parts[1] : '');
|
||||||
|
|
||||||
|
$this->content = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the structural element this tag refers to.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getReference()
|
||||||
|
{
|
||||||
|
return $this->refers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the structural element this tag refers to.
|
||||||
|
*
|
||||||
|
* @param string $refers The new type this tag refers to.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setReference($refers)
|
||||||
|
{
|
||||||
|
$this->refers = $refers;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag\VersionTag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @since tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SinceTag extends VersionTag
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @source tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SourceTag extends Tag
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int The starting line, relative to the structural element's
|
||||||
|
* location.
|
||||||
|
*/
|
||||||
|
protected $startingLine = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int|null The number of lines, relative to the starting line. NULL
|
||||||
|
* means "to the end".
|
||||||
|
*/
|
||||||
|
protected $lineCount = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content
|
||||||
|
= "{$this->startingLine} {$this->lineCount} {$this->description}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
parent::setContent($content);
|
||||||
|
if (preg_match(
|
||||||
|
'/^
|
||||||
|
# Starting line
|
||||||
|
([1-9]\d*)
|
||||||
|
\s*
|
||||||
|
# Number of lines
|
||||||
|
(?:
|
||||||
|
((?1))
|
||||||
|
\s+
|
||||||
|
)?
|
||||||
|
# Description
|
||||||
|
(.*)
|
||||||
|
$/sux',
|
||||||
|
$this->description,
|
||||||
|
$matches
|
||||||
|
)) {
|
||||||
|
$this->startingLine = (int)$matches[1];
|
||||||
|
if (isset($matches[2]) && '' !== $matches[2]) {
|
||||||
|
$this->lineCount = (int)$matches[2];
|
||||||
|
}
|
||||||
|
$this->setDescription($matches[3]);
|
||||||
|
$this->content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the starting line.
|
||||||
|
*
|
||||||
|
* @return int The starting line, relative to the structural element's
|
||||||
|
* location.
|
||||||
|
*/
|
||||||
|
public function getStartingLine()
|
||||||
|
{
|
||||||
|
return $this->startingLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the starting line.
|
||||||
|
*
|
||||||
|
* @param int $startingLine The new starting line, relative to the
|
||||||
|
* structural element's location.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setStartingLine($startingLine)
|
||||||
|
{
|
||||||
|
$this->startingLine = $startingLine;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of lines.
|
||||||
|
*
|
||||||
|
* @return int|null The number of lines, relative to the starting line. NULL
|
||||||
|
* means "to the end".
|
||||||
|
*/
|
||||||
|
public function getLineCount()
|
||||||
|
{
|
||||||
|
return $this->lineCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the number of lines.
|
||||||
|
*
|
||||||
|
* @param int|null $lineCount The new number of lines, relative to the
|
||||||
|
* starting line. NULL means "to the end".
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setLineCount($lineCount)
|
||||||
|
{
|
||||||
|
$this->lineCount = $lineCount;
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Andrew Smith <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @SuppressWarnings tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Andrew Smith <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SuppressWarningsTag extends Tag
|
||||||
|
{
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return "@{$this->getName()}{$this->getContent()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @template tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author chack1172 <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class TemplateTag extends ParamTag
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
protected $templateName = null;
|
||||||
|
|
||||||
|
/** @var string|null */
|
||||||
|
protected $bound = null;
|
||||||
|
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = $this->templateName;
|
||||||
|
if (null !== $this->bound) {
|
||||||
|
$this->content .= ' of ' . $this->bound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
$parts = explode(' of ', $content);
|
||||||
|
$this->templateName = $parts[0];
|
||||||
|
if (isset($parts[1])) {
|
||||||
|
$this->bound = $parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setDescription('');
|
||||||
|
$this->content = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the template name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTemplateName()
|
||||||
|
{
|
||||||
|
return $this->templateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the template name
|
||||||
|
*
|
||||||
|
* @param string $templateName
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTemplateName($templateName)
|
||||||
|
{
|
||||||
|
$this->templateName = $templateName;
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the bound type
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getBound()
|
||||||
|
{
|
||||||
|
return $this->bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bound type
|
||||||
|
* @param string|null $bound
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setBound($bound)
|
||||||
|
{
|
||||||
|
$this->bound = $bound;
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-4
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor
|
* phpDocumentor
|
||||||
*
|
*
|
||||||
* PHP Version 5
|
* PHP Version 5.3
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
@@ -10,10 +10,10 @@
|
|||||||
* @link http://phpdoc.org
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for a {@throws} tag in a Docblock.
|
* Reflection class for a @throws tag in a Docblock.
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
@@ -21,5 +21,4 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|||||||
*/
|
*/
|
||||||
class ThrowsTag extends ReturnTag
|
class ThrowsTag extends ReturnTag
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor
|
* phpDocumentor
|
||||||
*
|
*
|
||||||
* PHP Version 5
|
* PHP Version 5.3
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
@@ -10,10 +10,10 @@
|
|||||||
* @link http://phpdoc.org
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for a {@uses} tag in a Docblock.
|
* Reflection class for a @uses tag in a Docblock.
|
||||||
*
|
*
|
||||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
@@ -21,5 +21,4 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|||||||
*/
|
*/
|
||||||
class UsesTag extends SeeTag
|
class UsesTag extends SeeTag
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @var tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class VarTag extends ParamTag
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reflection class for a @version tag in a Docblock.
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class VersionTag extends Tag
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* PCRE regular expression matching a version vector.
|
||||||
|
* Assumes the "x" modifier.
|
||||||
|
*/
|
||||||
|
const REGEX_VECTOR = '(?:
|
||||||
|
# Normal release vectors.
|
||||||
|
\d\S*
|
||||||
|
|
|
||||||
|
# VCS version vectors. Per PHPCS, they are expected to
|
||||||
|
# follow the form of the VCS name, followed by ":", followed
|
||||||
|
# by the version vector itself.
|
||||||
|
# By convention, popular VCSes like CVS, SVN and GIT use "$"
|
||||||
|
# around the actual version vector.
|
||||||
|
[^\s\:]+\:\s*\$[^\$]+\$
|
||||||
|
)';
|
||||||
|
|
||||||
|
/** @var string The version vector. */
|
||||||
|
protected $version = '';
|
||||||
|
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
if (null === $this->content) {
|
||||||
|
$this->content = "{$this->version} {$this->description}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
parent::setContent($content);
|
||||||
|
|
||||||
|
if (preg_match(
|
||||||
|
'/^
|
||||||
|
# The version vector
|
||||||
|
(' . self::REGEX_VECTOR . ')
|
||||||
|
\s*
|
||||||
|
# The description
|
||||||
|
(.+)?
|
||||||
|
$/sux',
|
||||||
|
$this->description,
|
||||||
|
$matches
|
||||||
|
)) {
|
||||||
|
$this->version = $matches[1];
|
||||||
|
$this->setDescription(isset($matches[2]) ? $matches[2] : '');
|
||||||
|
$this->content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the version section of the tag.
|
||||||
|
*
|
||||||
|
* @return string The version section of the tag.
|
||||||
|
*/
|
||||||
|
public function getVersion()
|
||||||
|
{
|
||||||
|
return $this->version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the version section of the tag.
|
||||||
|
*
|
||||||
|
* @param string $version The new version section of the tag.
|
||||||
|
* An invalid value will set an empty string.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setVersion($version)
|
||||||
|
{
|
||||||
|
$this->version
|
||||||
|
= preg_match('/^' . self::REGEX_VECTOR . '$/ux', $version)
|
||||||
|
? $version
|
||||||
|
: '';
|
||||||
|
|
||||||
|
$this->content = null;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Type;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class Collection extends \ArrayObject
|
||||||
|
{
|
||||||
|
/** @var string Definition of the OR operator for types */
|
||||||
|
const OPERATOR_OR = '|';
|
||||||
|
|
||||||
|
/** @var string Definition of the ARRAY operator for types */
|
||||||
|
const OPERATOR_ARRAY = '[]';
|
||||||
|
|
||||||
|
/** @var string Definition of the NAMESPACE operator in PHP */
|
||||||
|
const OPERATOR_NAMESPACE = '\\';
|
||||||
|
|
||||||
|
/** @var string[] List of recognized keywords */
|
||||||
|
protected static $keywords = array(
|
||||||
|
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
|
||||||
|
'object', 'mixed', 'array', 'resource', 'void', 'null', 'scalar',
|
||||||
|
'callback', 'callable', 'false', 'true', 'self', '$this', 'static',
|
||||||
|
'array-key', 'number', 'iterable', 'pure-callable', 'closed-resource',
|
||||||
|
'open-resource', 'positive-int', 'negative-int', 'non-positive-int',
|
||||||
|
'non-negative-int', 'non-zero-int', 'non-empty-array', 'list',
|
||||||
|
'non-empty-list', 'key-of', 'value-of', 'template-type', 'class-string',
|
||||||
|
'callable-string', 'numeric-string', 'non-empty-string',
|
||||||
|
'non-falsy-string', 'literal-string', 'lowercase-string', 'never',
|
||||||
|
'never-return', 'never-returns', 'no-return', 'int-mask', 'int-mask-of'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current invoking location.
|
||||||
|
*
|
||||||
|
* This is used to prepend to type with a relative location.
|
||||||
|
* May also be 'default' or 'global', in which case they are ignored.
|
||||||
|
*
|
||||||
|
* @var Context
|
||||||
|
*/
|
||||||
|
protected $context = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of generics types
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $generics = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the namespace and aliases; uses that to add and expand the
|
||||||
|
* given types.
|
||||||
|
*
|
||||||
|
* @param string[] $types Array containing a list of types to add to this
|
||||||
|
* container.
|
||||||
|
* @param Context $location The current invoking location.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
array $types = array(),
|
||||||
|
?Context $context = null,
|
||||||
|
array $generics = array()
|
||||||
|
) {
|
||||||
|
$this->context = null === $context ? new Context() : $context;
|
||||||
|
$this->generics = array_merge($this->context->getGenerics(), $generics);
|
||||||
|
|
||||||
|
foreach ($types as $type) {
|
||||||
|
$this->add($type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current invoking location.
|
||||||
|
*
|
||||||
|
* @return Context
|
||||||
|
*/
|
||||||
|
public function getContext()
|
||||||
|
{
|
||||||
|
return $this->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new type to the collection and expands it if it contains a
|
||||||
|
* relative namespace.
|
||||||
|
*
|
||||||
|
* If a class in the type contains a relative namespace than this collection
|
||||||
|
* will try to expand that into a FQCN.
|
||||||
|
*
|
||||||
|
* @param string $type A 'Type' as defined in the phpDocumentor
|
||||||
|
* documentation.
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException if a non-string argument is passed.
|
||||||
|
*
|
||||||
|
* @see http://phpdoc.org/docs/latest/for-users/types.html for the
|
||||||
|
* definition of a type.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function add($type)
|
||||||
|
{
|
||||||
|
if (!is_string($type)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'A type should be represented by a string, received: '
|
||||||
|
.var_export($type, true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// separate the type by the OR operator
|
||||||
|
$type_parts = $this->explode($type);
|
||||||
|
foreach ($type_parts as $part) {
|
||||||
|
$expanded_type = $this->expand($part);
|
||||||
|
if ($expanded_type) {
|
||||||
|
$this[] = $expanded_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the collection.
|
||||||
|
*
|
||||||
|
* @return string The resolved types across the collection, separated with
|
||||||
|
* {@link self::OPERATOR_OR}.
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return implode(self::OPERATOR_OR, $this->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the given union of types and returns separated by OR operator
|
||||||
|
* single types.
|
||||||
|
*
|
||||||
|
* @param string $type The type or union of types
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function explode($type)
|
||||||
|
{
|
||||||
|
$type_parts = [];
|
||||||
|
$curr_type = '';
|
||||||
|
$nest_level = 0;
|
||||||
|
|
||||||
|
foreach (str_split($type) as $char) {
|
||||||
|
if ($char === self::OPERATOR_OR && $nest_level === 0) {
|
||||||
|
$type_parts[] = $curr_type;
|
||||||
|
$curr_type = '';
|
||||||
|
} else {
|
||||||
|
if (in_array($char, ['<', '(', '[', '{'])) {
|
||||||
|
$nest_level++;
|
||||||
|
} else if (in_array($char, ['>', ')', ']', '}'])) {
|
||||||
|
$nest_level--;
|
||||||
|
}
|
||||||
|
|
||||||
|
$curr_type .= $char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$type_parts[] = $curr_type;
|
||||||
|
|
||||||
|
return $type_parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the given type and returns the FQCN variant.
|
||||||
|
*
|
||||||
|
* When a type is provided this method checks whether it is not a keyword or
|
||||||
|
* Fully Qualified Class Name. If so it will use the given namespace and
|
||||||
|
* aliases to expand the type to a FQCN representation.
|
||||||
|
*
|
||||||
|
* This method only works as expected if the namespace and aliases are set;
|
||||||
|
* no dynamic reflection is being performed here.
|
||||||
|
*
|
||||||
|
* @param string $type The relative or absolute type.
|
||||||
|
*
|
||||||
|
* @uses getNamespace to determine with what to prefix the type name.
|
||||||
|
* @uses getNamespaceAliases to check whether the first part of the relative
|
||||||
|
* type name should not be replaced with another namespace.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function expand($type)
|
||||||
|
{
|
||||||
|
$type = trim($type);
|
||||||
|
if (!$type) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for generics values and array shapes
|
||||||
|
if (preg_match('/^[\w-]+(<.+>|\[.+\]|{.+})$/', $type)) {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for callable types
|
||||||
|
if (preg_match('/\(.*?(?=\:)/', $type)) {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($type[0] === '(') {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Literal strings
|
||||||
|
if ($type[0] === '"' || $type[0] === "'") {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isTypeAnArray($type)) {
|
||||||
|
return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type) && !$this->isTypeAGeneric($type)) {
|
||||||
|
|
||||||
|
if($this->shouldBeAbsolute($type)){
|
||||||
|
return self::OPERATOR_NAMESPACE . $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
$type_parts = explode(self::OPERATOR_NAMESPACE, $type, 2);
|
||||||
|
|
||||||
|
$namespace_aliases = $this->context->getNamespaceAliases();
|
||||||
|
// if the first segment is not an alias; prepend namespace name and
|
||||||
|
// return
|
||||||
|
if (!isset($namespace_aliases[$type_parts[0]]) &&
|
||||||
|
!isset($namespace_aliases[strstr($type_parts[0], '::', true)])) {
|
||||||
|
$namespace = $this->context->getNamespace();
|
||||||
|
if ('' !== $namespace) {
|
||||||
|
$namespace .= self::OPERATOR_NAMESPACE;
|
||||||
|
}
|
||||||
|
return self::OPERATOR_NAMESPACE . $namespace . $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($type_parts[0], '::')) {
|
||||||
|
$type_parts[] = strstr($type_parts[0], '::');
|
||||||
|
$type_parts[0] = $namespace_aliases[strstr($type_parts[0], '::', true)];
|
||||||
|
return implode('', $type_parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
$type_parts[0] = $namespace_aliases[$type_parts[0]];
|
||||||
|
$type = implode(self::OPERATOR_NAMESPACE, $type_parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects whether the given type represents an array.
|
||||||
|
*
|
||||||
|
* @param string $type A relative or absolute type as defined in the
|
||||||
|
* phpDocumentor documentation.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isTypeAnArray($type)
|
||||||
|
{
|
||||||
|
return substr($type, -2) === self::OPERATOR_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects whether the given type represents a PHPDoc keyword.
|
||||||
|
*
|
||||||
|
* @param string $type A relative or absolute type as defined in the
|
||||||
|
* phpDocumentor documentation.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isTypeAKeyword($type)
|
||||||
|
{
|
||||||
|
return in_array(strtolower($type), static::$keywords, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects whether the given type represents a relative or absolute path.
|
||||||
|
*
|
||||||
|
* This method will detect keywords as being absolute; even though they are
|
||||||
|
* not preceeded by a namespace separator.
|
||||||
|
*
|
||||||
|
* @param string $type A relative or absolute type as defined in the
|
||||||
|
* phpDocumentor documentation.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isRelativeType($type)
|
||||||
|
{
|
||||||
|
return ($type[0] !== self::OPERATOR_NAMESPACE)
|
||||||
|
|| $this->isTypeAKeyword($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects whether the given type represents a generic.
|
||||||
|
*
|
||||||
|
* @param string $type A relative or absolute type as defined in the
|
||||||
|
* phpDocumentor documentation.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isTypeAGeneric($type)
|
||||||
|
{
|
||||||
|
return in_array($type, $this->generics, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects if the type should actually be absolute, by checking if it exists.
|
||||||
|
*
|
||||||
|
* @param string $type A relative or absolute type as defined in the
|
||||||
|
* phpDocumentor documentation.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function shouldBeAbsolute($type){
|
||||||
|
return class_exists($type);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,413 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the DocBlock for any structure.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class DocBlock implements \Reflector
|
|
||||||
{
|
|
||||||
/** @var string The opening line for this docblock. */
|
|
||||||
protected $short_description = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \phpDocumentor\Reflection\DocBlock\LongDescription The actual description
|
|
||||||
* for this docblock.
|
|
||||||
*/
|
|
||||||
protected $long_description = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \phpDocumentor\Reflection\DocBlock\Tags[] An array containing all the tags
|
|
||||||
* in this docblock; except inline.
|
|
||||||
*/
|
|
||||||
protected $tags = array();
|
|
||||||
|
|
||||||
/** @var string the current namespace */
|
|
||||||
protected $namespace = '\\';
|
|
||||||
|
|
||||||
/** @var string[] List of namespace aliases => Fully Qualified Namespace */
|
|
||||||
protected $namespace_aliases = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the given docblock and populates the member fields.
|
|
||||||
*
|
|
||||||
* The constructor may also receive namespace information such as the
|
|
||||||
* current namespace and aliases. This information is used in the
|
|
||||||
* {@link expandType()} method to transform a relative Type into a FQCN.
|
|
||||||
*
|
|
||||||
* For example the param and return tags use this to expand their type
|
|
||||||
* information.
|
|
||||||
*
|
|
||||||
* @param \Reflector|string $docblock A docblock comment (including asterisks)
|
|
||||||
* or reflector supporting the getDocComment method.
|
|
||||||
* @param string $namespace The namespace where this DocBlock resides in;
|
|
||||||
* defaults to `\`.
|
|
||||||
* @param string[] $namespace_aliases a list of namespace aliases as
|
|
||||||
* provided by the `use` keyword; the key of the array is the alias name
|
|
||||||
* or last part of the alias array if no alias name is provided.
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if the given argument does not have the
|
|
||||||
* getDocComment method.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
$docblock, $namespace = '\\', $namespace_aliases = array()
|
|
||||||
) {
|
|
||||||
if (is_object($docblock)) {
|
|
||||||
if (!method_exists($docblock, 'getDocComment')) {
|
|
||||||
throw new \InvalidArgumentException(
|
|
||||||
'Invalid object passed; the given reflector must support '
|
|
||||||
. 'the getDocComment method'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$docblock = $docblock->getDocComment();
|
|
||||||
}
|
|
||||||
|
|
||||||
$docblock = $this->cleanInput($docblock);
|
|
||||||
|
|
||||||
list($short, $long, $tags) = $this->splitDocBlock($docblock);
|
|
||||||
$this->short_description = $short;
|
|
||||||
$this->long_description = new DocBlock\LongDescription($long);
|
|
||||||
$this->parseTags($tags);
|
|
||||||
|
|
||||||
$this->namespace = $namespace;
|
|
||||||
$this->namespace_aliases = $namespace_aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strips the asterisks from the DocBlock comment.
|
|
||||||
*
|
|
||||||
* @param string $comment String containing the comment text.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function cleanInput($comment)
|
|
||||||
{
|
|
||||||
$comment = trim(
|
|
||||||
preg_replace(
|
|
||||||
'#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// reg ex above is not able to remove */ from a single line docblock
|
|
||||||
if (substr($comment, -2) == '*/') {
|
|
||||||
$comment = trim(substr($comment, 0, -2));
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalize strings
|
|
||||||
$comment = str_replace(array("\r\n", "\r"), "\n", $comment);
|
|
||||||
|
|
||||||
return $comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits the DocBlock into a short description, long description and
|
|
||||||
* block of tags.
|
|
||||||
*
|
|
||||||
* @param string $comment Comment to split into the sub-parts.
|
|
||||||
*
|
|
||||||
* @author RichardJ Special thanks to RichardJ for the regex responsible
|
|
||||||
* for the split/
|
|
||||||
*
|
|
||||||
* @return string[] containing the short-, long description and an element
|
|
||||||
* containing the tags.
|
|
||||||
*/
|
|
||||||
protected function splitDocBlock($comment)
|
|
||||||
{
|
|
||||||
if (strpos($comment, '@') === 0) {
|
|
||||||
$matches = array('', '', $comment);
|
|
||||||
} else {
|
|
||||||
// clears all extra horizontal whitespace from the line endings
|
|
||||||
// to prevent parsing issues
|
|
||||||
$comment = preg_replace('~(?m)\h*$~u', '', $comment);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Splits the docblock into a short description, long description and
|
|
||||||
* tags section
|
|
||||||
* - The short description is started from the first character until
|
|
||||||
* a dot is encountered followed by a whitespace OR
|
|
||||||
* two consecutive newlines (horizontal whitespace is taken into
|
|
||||||
* account to consider spacing errors)
|
|
||||||
* - The long description, any character until a new line is
|
|
||||||
* encountered followed by an @ and word characters (a tag).
|
|
||||||
* This is optional.
|
|
||||||
* - Tags; the remaining characters
|
|
||||||
*
|
|
||||||
* Big thanks to RichardJ for contributing this Regular Expression
|
|
||||||
*/
|
|
||||||
preg_match(
|
|
||||||
'/(?x)
|
|
||||||
\A (
|
|
||||||
[^\n.]+
|
|
||||||
(?:
|
|
||||||
(?! \. \s | \n{2} ) # disallow the first seperator here
|
|
||||||
[\n.] (?! [ \t]* @\pL ) # disallow second seperator
|
|
||||||
[^\n.]+
|
|
||||||
)*
|
|
||||||
\.?
|
|
||||||
)
|
|
||||||
(?:
|
|
||||||
\s* # first seperator (actually newlines but it\'s all whitespace)
|
|
||||||
(?! @\pL ) # disallow the rest, to make sure this one doesn\'t match,
|
|
||||||
#if it doesn\'t exist
|
|
||||||
(
|
|
||||||
[^\n]+
|
|
||||||
(?: \n+
|
|
||||||
(?! [ \t]* @\pL ) # disallow second seperator (@param)
|
|
||||||
[^\n]+
|
|
||||||
)*
|
|
||||||
)
|
|
||||||
)?
|
|
||||||
(\s+ [\s\S]*)? # everything that follows
|
|
||||||
/u', $comment, $matches
|
|
||||||
);
|
|
||||||
array_shift($matches);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (count($matches) < 3) {
|
|
||||||
$matches[] = '';
|
|
||||||
}
|
|
||||||
return $matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag objects.
|
|
||||||
*
|
|
||||||
* @param string $tags Tag block to parse.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function parseTags($tags)
|
|
||||||
{
|
|
||||||
$result = array();
|
|
||||||
foreach (explode("\n", trim($tags)) as $tag_line) {
|
|
||||||
if (trim($tag_line) === '') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($tag_line[0]) && ($tag_line[0] === '@')) {
|
|
||||||
$result[] = $tag_line;
|
|
||||||
} else {
|
|
||||||
if (count($result) == 0) {
|
|
||||||
throw new \LogicException(
|
|
||||||
'A tag block started with text instead of an actual tag,'
|
|
||||||
. ' this makes the tag block invalid: ' . $tags
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result[count($result) - 1] .= PHP_EOL . $tag_line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create proper Tag objects
|
|
||||||
foreach ($result as $key => $tag_line) {
|
|
||||||
$tag = DocBlock\Tag::createInstance($tag_line);
|
|
||||||
$tag->setDocBlock($this);
|
|
||||||
$result[$key] = $tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->tags = $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the opening line or also known as short description.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getShortDescription()
|
|
||||||
{
|
|
||||||
return $this->short_description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the full description or also known as long description.
|
|
||||||
*
|
|
||||||
* @return \phpDocumentor\Reflection\DocBlock\LongDescription
|
|
||||||
*/
|
|
||||||
public function getLongDescription()
|
|
||||||
{
|
|
||||||
return $this->long_description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the tags for this DocBlock.
|
|
||||||
*
|
|
||||||
* @return \phpDocumentor\Reflection\DocBlock\Tag[]
|
|
||||||
*/
|
|
||||||
public function getTags()
|
|
||||||
{
|
|
||||||
return $this->tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of tags matching the given name; if no tags are found
|
|
||||||
* an empty array is returned.
|
|
||||||
*
|
|
||||||
* @param string $name String to search by.
|
|
||||||
*
|
|
||||||
* @return \phpDocumentor\Reflection\DocBlock_Tag[]
|
|
||||||
*/
|
|
||||||
public function getTagsByName($name)
|
|
||||||
{
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
/** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */
|
|
||||||
foreach ($this->getTags() as $tag) {
|
|
||||||
if ($tag->getName() != $name) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result[] = $tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a tag of a certain type is present in this DocBlock.
|
|
||||||
*
|
|
||||||
* @param string $name Tag name to check for.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function hasTag($name)
|
|
||||||
{
|
|
||||||
/** @var \phpDocumentor\Reflection\DocBlock\Tag $tag */
|
|
||||||
foreach ($this->getTags() as $tag) {
|
|
||||||
if ($tag->getName() == $name) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to expand a type to it's full namespaced equivalent (FQCN).
|
|
||||||
*
|
|
||||||
* This method will take the given type and examine the current namespace
|
|
||||||
* and namespace aliases to see whether it should expand it into a FQCN
|
|
||||||
* as defined by the rules in PHP.
|
|
||||||
*
|
|
||||||
* @param string $type Type to expand into full namespaced
|
|
||||||
* equivalent.
|
|
||||||
* @param string[] $ignore_keywords Whether to ignore given keywords, when
|
|
||||||
* null it will use the default keywords: 'string', 'int', 'integer',
|
|
||||||
* 'bool', 'boolean', 'float', 'double', 'object', 'mixed', 'array',
|
|
||||||
* 'resource', 'void', 'null', 'callback', 'false', 'true'.
|
|
||||||
* Default value for this parameter is null.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function expandType($type, $ignore_keywords = null)
|
|
||||||
{
|
|
||||||
if ($type === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($ignore_keywords === null) {
|
|
||||||
$ignore_keywords = array(
|
|
||||||
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
|
|
||||||
'object', 'mixed', 'array', 'resource', 'void', 'null',
|
|
||||||
'callback', 'false', 'true', 'self', '$this', 'callable'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$namespace = '\\';
|
|
||||||
if ($this->namespace != 'default' && $this->namespace != 'global') {
|
|
||||||
$namespace = rtrim($this->namespace, '\\') . '\\';
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = explode('|', $type);
|
|
||||||
foreach ($type as &$item) {
|
|
||||||
$item = trim($item);
|
|
||||||
|
|
||||||
// add support for array notation
|
|
||||||
$is_array = false;
|
|
||||||
if (substr($item, -2) == '[]') {
|
|
||||||
$item = substr($item, 0, -2);
|
|
||||||
$is_array = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((substr($item, 0, 1) != '\\')
|
|
||||||
&& (!in_array(strtolower($item), $ignore_keywords))
|
|
||||||
) {
|
|
||||||
$type_parts = explode('\\', $item);
|
|
||||||
|
|
||||||
// if the first segment is an alias; replace with full name
|
|
||||||
if (isset($this->namespace_aliases[$type_parts[0]])) {
|
|
||||||
$type_parts[0] = $this->namespace_aliases[$type_parts[0]];
|
|
||||||
$item = implode('\\', $type_parts);
|
|
||||||
} else {
|
|
||||||
// otherwise prepend the current namespace
|
|
||||||
$item = $namespace . $item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// full paths always start with a slash
|
|
||||||
if (isset($item[0]) && ($item[0] !== '\\')
|
|
||||||
&& (!in_array(strtolower($item), $ignore_keywords))
|
|
||||||
) {
|
|
||||||
$item = '\\' . $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
// re-add the array notation markers
|
|
||||||
if ($is_array) {
|
|
||||||
$item .= '[]';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode('|', $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a string representation of this object.
|
|
||||||
*
|
|
||||||
* @todo determine the exact format as used by PHP Reflection and
|
|
||||||
* implement it.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
static public function export()
|
|
||||||
{
|
|
||||||
throw new \Exception('Not yet implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exported information (we should use the export static method
|
|
||||||
* BUT this throws an exception at this point).
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return 'Not yet implemented';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNamespace()
|
|
||||||
{
|
|
||||||
return $this->namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNamespaceAliases()
|
|
||||||
{
|
|
||||||
return $this->namespace_aliases;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5.3
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a Long Description of a DocBlock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class LongDescription implements \Reflector
|
|
||||||
{
|
|
||||||
/** @var string */
|
|
||||||
protected $contents = '';
|
|
||||||
|
|
||||||
/** @var array The contents, as an array of strings and Tag objects. */
|
|
||||||
protected $parsedContents = null;
|
|
||||||
|
|
||||||
/** @var \phpDocumentor\Reflection\DocBlock\Tags[] */
|
|
||||||
protected $tags = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the string for inline tags and if the Markdown class is included;
|
|
||||||
* format the found text.
|
|
||||||
*
|
|
||||||
* @param string $content the DocBlock contents without asterisks.
|
|
||||||
*/
|
|
||||||
public function __construct($content)
|
|
||||||
{
|
|
||||||
$this->contents = trim($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the text of this description.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getContents()
|
|
||||||
{
|
|
||||||
return $this->contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns the parsed text of this description.
|
|
||||||
*
|
|
||||||
* @return array An array of strings and tag objects, in the order they
|
|
||||||
* occur within the description.
|
|
||||||
*/
|
|
||||||
public function getParsedContents()
|
|
||||||
{
|
|
||||||
if (null === $this->parsedContents) {
|
|
||||||
$this->parsedContents = preg_split(
|
|
||||||
'/\{(\@.*?)\}/uS', $this->contents,
|
|
||||||
null, PREG_SPLIT_DELIM_CAPTURE
|
|
||||||
);
|
|
||||||
for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) {
|
|
||||||
$this->parsedContents[$i] = Tag::createInstance(
|
|
||||||
$this->parsedContents[$i]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->parsedContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a formatted variant of the Long Description using MarkDown.
|
|
||||||
*
|
|
||||||
* @todo this should become a more intelligent piece of code where the
|
|
||||||
* configuration contains a setting what format long descriptions are.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getFormattedContents()
|
|
||||||
{
|
|
||||||
$result = $this->contents;
|
|
||||||
|
|
||||||
// if the long description contains a plain HTML <code> element, surround
|
|
||||||
// it with a pre element. Please note that we explicitly used str_replace
|
|
||||||
// and not preg_replace to gain performance
|
|
||||||
if (strpos($result, '<code>') !== false) {
|
|
||||||
$result = str_replace(
|
|
||||||
array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'),
|
|
||||||
array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'),
|
|
||||||
$result
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (class_exists('dflydev\markdown\MarkdownExtraParser')) {
|
|
||||||
$md = new \dflydev\markdown\MarkdownExtraParser();
|
|
||||||
$result = $md->transformMarkdown($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return trim($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a string representation of this object.
|
|
||||||
*
|
|
||||||
* @todo determine the exact format as used by PHP Reflection and implement it.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
static public function export()
|
|
||||||
{
|
|
||||||
throw new \Exception('Not yet implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exported information (we should use the export static method
|
|
||||||
* BUT this throws an exception at this point).
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return 'Not yet implemented';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag definition for a DocBlock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class Tag implements \Reflector
|
|
||||||
{
|
|
||||||
/** @var string Name of the tag */
|
|
||||||
protected $tag = '';
|
|
||||||
|
|
||||||
/** @var string Content of the tag */
|
|
||||||
protected $content = '';
|
|
||||||
|
|
||||||
/** @var string Description of the content of this tag */
|
|
||||||
protected $description = '';
|
|
||||||
|
|
||||||
/** @var array The description, as an array of strings and Tag objects. */
|
|
||||||
protected $parsedDescription = null;
|
|
||||||
|
|
||||||
/** @var int Line number of the tag */
|
|
||||||
protected $line_number = 0;
|
|
||||||
|
|
||||||
/** @var \phpDocumentor\Reflection\DocBlock docblock class */
|
|
||||||
protected $docblock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method responsible for instantiating the correct sub type.
|
|
||||||
*
|
|
||||||
* @param string $tag_line The text for this tag, including description.
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if an invalid tag line was presented.
|
|
||||||
*
|
|
||||||
* @return \phpDocumentor\Reflection\DocBlock\Tag
|
|
||||||
*/
|
|
||||||
public static function createInstance($tag_line)
|
|
||||||
{
|
|
||||||
if (!preg_match(
|
|
||||||
'/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us', $tag_line, $matches
|
|
||||||
)) {
|
|
||||||
throw new \InvalidArgumentException(
|
|
||||||
'Invalid tag_line detected: ' . $tag_line
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// support hypphen separated tag names
|
|
||||||
$tag_name = str_replace(
|
|
||||||
' ', '', ucwords(str_replace('-', ' ', $matches[1]))
|
|
||||||
).'Tag';
|
|
||||||
$class_name = 'phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name;
|
|
||||||
|
|
||||||
return (@class_exists($class_name))
|
|
||||||
? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '')
|
|
||||||
: new self($matches[1], isset($matches[2]) ? $matches[2] : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Name of the tag.
|
|
||||||
* @param string $content The contents of the given tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$this->content = $content;
|
|
||||||
$this->description = $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of this tag.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the content of this tag.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getContent()
|
|
||||||
{
|
|
||||||
return $this->content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the description component of this tag.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDescription()
|
|
||||||
{
|
|
||||||
return $this->description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns the parsed text of this description.
|
|
||||||
*
|
|
||||||
* @return array An array of strings and tag objects, in the order they
|
|
||||||
* occur within the description.
|
|
||||||
*/
|
|
||||||
public function getParsedDescription()
|
|
||||||
{
|
|
||||||
if (null === $this->parsedDescription) {
|
|
||||||
$description = new LongDescription($this->description);
|
|
||||||
$this->parsedDescription = $description->getParsedContents();
|
|
||||||
}
|
|
||||||
return $this->parsedDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tag line number
|
|
||||||
*
|
|
||||||
* @param int $number the line number of the tag
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setLineNumber($number)
|
|
||||||
{
|
|
||||||
$this->line_number = (int)$number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the line number of the tag
|
|
||||||
*
|
|
||||||
* @return int tag line number
|
|
||||||
*/
|
|
||||||
public function getLineNumber()
|
|
||||||
{
|
|
||||||
return $this->line_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inject the docblock class
|
|
||||||
*
|
|
||||||
* This exposes some common functionality contained in the docblock abstract.
|
|
||||||
*
|
|
||||||
* @param object $docblock Object containing the DocBlock.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setDocBlock($docblock)
|
|
||||||
{
|
|
||||||
$this->docblock = $docblock;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a string representation of this object.
|
|
||||||
*
|
|
||||||
* @todo determine the exact format as used by PHP Reflection and implement it.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
static public function export()
|
|
||||||
{
|
|
||||||
throw new \Exception('Not yet implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the exported information (we should use the export static method
|
|
||||||
* BUT this throws an exception at this point).
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return 'Not yet implemented';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for an @author tag in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class AuthorTag extends Tag
|
|
||||||
{
|
|
||||||
/** @var string The name of the author */
|
|
||||||
protected $name = '';
|
|
||||||
|
|
||||||
/** @var string The email of the author */
|
|
||||||
protected $email = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Name of the tag.
|
|
||||||
* @param string $content The contents of the given tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
parent::__construct($type, $content);
|
|
||||||
if (preg_match('/^([^\<]*)(\<([^\>]*)\>)?$/', $content, $matches)) {
|
|
||||||
$this->name = trim($matches[1]);
|
|
||||||
if (isset($matches[3])) {
|
|
||||||
$this->email = trim($matches[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the author's name.
|
|
||||||
*
|
|
||||||
* @return string The author's name.
|
|
||||||
*/
|
|
||||||
public function getAuthorName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the author's email.
|
|
||||||
*
|
|
||||||
* @return string The author's email.
|
|
||||||
*/
|
|
||||||
public function getAuthorEmail()
|
|
||||||
{
|
|
||||||
return $this->email;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Ben Selby <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a @link tag in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Ben Selby <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class LinkTag extends Tag
|
|
||||||
{
|
|
||||||
/** @var string */
|
|
||||||
protected $link = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag type
|
|
||||||
* @param string $content Content of the tag
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$pieces = explode(' ', $content);
|
|
||||||
|
|
||||||
if (count($pieces) > 1) {
|
|
||||||
$this->link = array_shift($pieces);
|
|
||||||
$this->description = implode(' ', $pieces);
|
|
||||||
} else {
|
|
||||||
$this->link = $content;
|
|
||||||
$this->description = $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->content = $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the link
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getLink()
|
|
||||||
{
|
|
||||||
return $this->link;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the link
|
|
||||||
*
|
|
||||||
* @param string $link The link
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setLink($link)
|
|
||||||
{
|
|
||||||
$this->link = $link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a {@method} in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class MethodTag extends ParamTag
|
|
||||||
{
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
protected $method_name = '';
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
protected $arguments = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag identifier for this tag (should be 'return')
|
|
||||||
* @param string $content Contents for this tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$this->content = $content;
|
|
||||||
|
|
||||||
$matches = array();
|
|
||||||
// 1. none or more whitespace
|
|
||||||
// 2. optionally a word with underscores followed by whitespace : as
|
|
||||||
// type for the return value
|
|
||||||
// 3. then optionally a word with underscores followed by () and
|
|
||||||
// whitespace : as method name as used by phpDocumentor
|
|
||||||
// 4. then a word with underscores, followed by ( and any character
|
|
||||||
// until a ) and whitespace : as method name with signature
|
|
||||||
// 5. any remaining text : as description
|
|
||||||
if (preg_match(
|
|
||||||
'/^[\s]*(?:([\w\|_\\\\]+)[\s]+)?(?:[\w_]+\(\)[\s]+)?([\w\|_\\\\]+)\(([^\)]*)\)'
|
|
||||||
.'[\s]*(.*)/u',
|
|
||||||
$content,
|
|
||||||
$matches
|
|
||||||
)) {
|
|
||||||
list(
|
|
||||||
,
|
|
||||||
$this->type,
|
|
||||||
$this->method_name,
|
|
||||||
$this->arguments,
|
|
||||||
$this->description
|
|
||||||
) = $matches;
|
|
||||||
if (!$this->type)
|
|
||||||
{
|
|
||||||
$this->type = 'void';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo date('c') . ' ERR (3): @method contained invalid contents: '
|
|
||||||
. $this->content . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the name of this method.
|
|
||||||
*
|
|
||||||
* @param string $method_name The name of the method.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setMethodName($method_name)
|
|
||||||
{
|
|
||||||
$this->method_name = $method_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the method name.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMethodName()
|
|
||||||
{
|
|
||||||
return $this->method_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the arguments for this method.
|
|
||||||
*
|
|
||||||
* @param string $arguments A comma-separated arguments line.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setArguments($arguments)
|
|
||||||
{
|
|
||||||
$this->arguments = $arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array containing each argument as array of type and name.
|
|
||||||
*
|
|
||||||
* Please note that the argument sub-array may only contain 1 element if no
|
|
||||||
* type was specified.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public function getArguments()
|
|
||||||
{
|
|
||||||
if (empty($this->arguments)) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$arguments = explode(',', $this->arguments);
|
|
||||||
foreach ($arguments as $key => $value) {
|
|
||||||
$arguments[$key] = explode(' ', trim($value));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a {@param} tag in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class ParamTag extends Tag
|
|
||||||
{
|
|
||||||
/** @var string */
|
|
||||||
protected $type = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $variableName = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag identifier for this tag (should be 'param')
|
|
||||||
* @param string $content Contents for this tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$this->content = $content;
|
|
||||||
$content = preg_split('/\s+/u', $content);
|
|
||||||
|
|
||||||
// if the first item that is encountered is not a variable; it is a type
|
|
||||||
if (isset($content[0]) && (strlen($content[0]) > 0) && ($content[0][0] !== '$')) {
|
|
||||||
$this->type = array_shift($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the next item starts with a $ it must be the variable name
|
|
||||||
if (isset($content[0]) && (strlen($content[0]) > 0) && ($content[0][0] == '$')) {
|
|
||||||
$this->variableName = array_shift($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->description = implode(' ', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the unique types of the variable.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public function getTypes()
|
|
||||||
{
|
|
||||||
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
|
|
||||||
array($this->type),
|
|
||||||
$this->docblock ? $this->docblock->getNamespace() : null,
|
|
||||||
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
|
|
||||||
);
|
|
||||||
|
|
||||||
return $types->getArrayCopy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type section of the variable.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getType()
|
|
||||||
{
|
|
||||||
return implode('|', $this->getTypes());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the variable's name.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getVariableName()
|
|
||||||
{
|
|
||||||
return $this->variableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the variable's name.
|
|
||||||
*
|
|
||||||
* @param string $name The new name for this variable.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setVariableName($name)
|
|
||||||
{
|
|
||||||
$this->variableName = $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a {@return} tag in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class ReturnTag extends ParamTag
|
|
||||||
{
|
|
||||||
/** @var string */
|
|
||||||
protected $type = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag identifier for this tag (should be 'return')
|
|
||||||
* @param string $content Contents for this tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$this->content = $content;
|
|
||||||
|
|
||||||
$content = preg_split('/[\ \t]+/u', $content, 2);
|
|
||||||
|
|
||||||
// any output is considered a type
|
|
||||||
$this->type = array_shift($content);
|
|
||||||
|
|
||||||
$this->description = implode(' ', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a {@see} tag in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class SeeTag extends Tag
|
|
||||||
{
|
|
||||||
/** @var string */
|
|
||||||
protected $refers = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag identifier for this tag (should be 'return')
|
|
||||||
* @param string $content Contents for this tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$this->content = $content;
|
|
||||||
$content = preg_split('/\s+/u', $content);
|
|
||||||
|
|
||||||
// any output is considered a type
|
|
||||||
$this->refers = array_shift($content);
|
|
||||||
|
|
||||||
$this->description = implode(' ', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type of the variable.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getReference()
|
|
||||||
{
|
|
||||||
return $this->refers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a mistyped @throws tag called @throw in a Docblock.
|
|
||||||
*
|
|
||||||
* This is a very common error, so @throw is aliased to be @throws
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class ThrowTag extends ThrowsTag
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Sets the type to {@throws} and lets parent parse the tag and populates the
|
|
||||||
* member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag identifier for this tag (should be 'return')
|
|
||||||
* @param string $content Contents for this tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
if ('throw' !== $type) {
|
|
||||||
throw new \InvalidArgumentException(
|
|
||||||
'Internal error, ' . __CLASS__ . ' was called with ' . $type
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct('throws', $content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection class for a {@var} tag in a Docblock.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
|
||||||
* @link http://phpdoc.org
|
|
||||||
*/
|
|
||||||
class VarTag extends ParamTag
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Parses a tag and populates the member variables.
|
|
||||||
*
|
|
||||||
* @param string $type Tag identifier for this tag (should be 'return')
|
|
||||||
* @param string $content Contents for this tag.
|
|
||||||
*/
|
|
||||||
public function __construct($type, $content)
|
|
||||||
{
|
|
||||||
$this->tag = $type;
|
|
||||||
$this->content = $content;
|
|
||||||
$content = preg_split('/\s+/u', $content);
|
|
||||||
|
|
||||||
if (count($content) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// var always starts with the variable name
|
|
||||||
$this->type = array_shift($content);
|
|
||||||
|
|
||||||
// if the next item starts with a $ it must be the variable name
|
|
||||||
if ((count($content) > 0)
|
|
||||||
&& (strlen($content[0]) > 0)
|
|
||||||
&& ($content[0][0] == '$')
|
|
||||||
) {
|
|
||||||
$this->variableName = array_shift($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->description = implode(' ', $content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Type;
|
|
||||||
|
|
||||||
class Collection extends \ArrayObject
|
|
||||||
{
|
|
||||||
/** @var string Definition of the OR operator for types */
|
|
||||||
const OPERATOR_OR = '|';
|
|
||||||
|
|
||||||
/** @var string Definition of the ARRAY operator for types */
|
|
||||||
const OPERATOR_ARRAY = '[]';
|
|
||||||
|
|
||||||
/** @var string Definition of the NAMESPACE operator in PHP */
|
|
||||||
const OPERATOR_NAMESPACE = '\\';
|
|
||||||
|
|
||||||
/** @var string[] List of recognized keywords */
|
|
||||||
protected $keywords = array(
|
|
||||||
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
|
|
||||||
'object', 'mixed', 'array', 'resource', 'void', 'null',
|
|
||||||
'callback', 'callable', 'false', 'true', 'self', '$this', 'static'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current namespace of the invoking location.
|
|
||||||
*
|
|
||||||
* This string is used to prepend to type with a relative location.
|
|
||||||
* May also be 'default' or 'global', in which case they are ignored.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $namespace = '\\';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Associative array of alias => namespace pairs.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $namespace_aliases = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the namespace and aliases; uses that to add and expand the
|
|
||||||
* given types.
|
|
||||||
*
|
|
||||||
* @param string[] $types Array containing a list of types
|
|
||||||
* to add to this container.
|
|
||||||
* @param string|null $namespace The namespace where the types in
|
|
||||||
* this container are relative to; used to expand any relative
|
|
||||||
* namespaces.
|
|
||||||
* @param string[] $namespace_aliases An array containing alias => FQNN
|
|
||||||
* pairs that are used in the resolving process.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
array $types = array(), $namespace = null,
|
|
||||||
array $namespace_aliases = array()
|
|
||||||
) {
|
|
||||||
// only set the namespace if overridden
|
|
||||||
if (is_string($namespace)) {
|
|
||||||
$this->setNamespace($namespace);
|
|
||||||
}
|
|
||||||
$this->namespace_aliases = $namespace_aliases;
|
|
||||||
|
|
||||||
foreach($types as $type) {
|
|
||||||
$this->add($type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the namespace name used to expand relative namespaces with.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNamespace()
|
|
||||||
{
|
|
||||||
return $this->namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the namespace which is used to resolve types with relative
|
|
||||||
* namespaces.
|
|
||||||
*
|
|
||||||
* Unless the name of the current namespace if default or global we make
|
|
||||||
* sure the namespace is succeeded with a '\'. This makes it clear for
|
|
||||||
* the processing functions that a leading slash is present.
|
|
||||||
*
|
|
||||||
* @param string $namespace
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setNamespace($namespace)
|
|
||||||
{
|
|
||||||
if ($namespace != 'default' && $namespace != 'global') {
|
|
||||||
$namespace = self::OPERATOR_NAMESPACE
|
|
||||||
. trim($namespace, self::OPERATOR_NAMESPACE)
|
|
||||||
. self::OPERATOR_NAMESPACE;
|
|
||||||
} else {
|
|
||||||
$namespace = '\\';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->namespace = $namespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of namespace aliases used to expand the typed with.
|
|
||||||
*
|
|
||||||
* @return string[] An associative array of Alias => Fully Qualified
|
|
||||||
* Namespace Names.
|
|
||||||
*/
|
|
||||||
public function getNamespaceAliases()
|
|
||||||
{
|
|
||||||
return $this->namespace_aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the namespace aliases to expand the added types.
|
|
||||||
*
|
|
||||||
* @param string[] $namespace_aliases An associative array of Alias => Fully
|
|
||||||
* Qualified Namespace Names.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setNamespaceAliases($namespace_aliases)
|
|
||||||
{
|
|
||||||
$this->namespace_aliases = $namespace_aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new type to the collection and expands it if it contains a
|
|
||||||
* relative namespace.
|
|
||||||
*
|
|
||||||
* If a class in the type contains a relative namespace than this collection
|
|
||||||
* will try to expand that into a FQCN.
|
|
||||||
*
|
|
||||||
* @param string $type A 'Type' as defined in the phpDocumentor
|
|
||||||
* documentation.
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException if a non-string argument is passed.
|
|
||||||
*
|
|
||||||
* @see http://phpdoc.org/docs/latest/for-users/types.html for the
|
|
||||||
* definition of a type.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function add($type)
|
|
||||||
{
|
|
||||||
if (!is_string($type)) {
|
|
||||||
throw new \InvalidArgumentException(
|
|
||||||
'A type should be represented by a string, received: '
|
|
||||||
.var_export($type, true)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// separate the type by the OR operator
|
|
||||||
$type_parts = explode(self::OPERATOR_OR, $type);
|
|
||||||
foreach($type_parts as $part) {
|
|
||||||
$expanded_type = $this->expand($part);
|
|
||||||
if ($expanded_type) {
|
|
||||||
$this[] = $expanded_type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Analyzes the given type and returns the FQCN variant.
|
|
||||||
*
|
|
||||||
* When a type is provided this method checks whether it is not a keyword or
|
|
||||||
* Fully Qualified Class Name. If so it will use the given namespace and
|
|
||||||
* aliases to expand the type to a FQCN representation.
|
|
||||||
*
|
|
||||||
* This method only works as expected if the namespace and aliases are set;
|
|
||||||
* no dynamic reflection is being performed here.
|
|
||||||
*
|
|
||||||
* @uses getNamespace to determine with what to prefix the type name.
|
|
||||||
* @uses getNamespaceAliases to check whether the first part of the relative
|
|
||||||
* type name should not be replaced with another namespace.
|
|
||||||
*
|
|
||||||
* @param string $type The relative or absolute type.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function expand($type)
|
|
||||||
{
|
|
||||||
$type = trim($type);
|
|
||||||
if (!$type) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isTypeAnArray($type)) {
|
|
||||||
return $this->expand(substr($type, 0, -2)).self::OPERATOR_ARRAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type)) {
|
|
||||||
$type_parts = explode(self::OPERATOR_NAMESPACE, $type);
|
|
||||||
|
|
||||||
// if the first segment is not an alias; prepend namespace name and
|
|
||||||
// return
|
|
||||||
if (!isset($this->namespace_aliases[$type_parts[0]])) {
|
|
||||||
return $this->getNamespace() . $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type_parts[0] = $this->namespace_aliases[$type_parts[0]];
|
|
||||||
$type = implode(self::OPERATOR_NAMESPACE, $type_parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detects whether the given type represents an array.
|
|
||||||
*
|
|
||||||
* @param string $type A relative or absolute type as defined in the
|
|
||||||
* phpDocumentor documentation.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isTypeAnArray($type)
|
|
||||||
{
|
|
||||||
return (substr($type, -2) == self::OPERATOR_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detects whether the given type represents a PHPDoc keyword.
|
|
||||||
*
|
|
||||||
* @param string $type A relative or absolute type as defined in the
|
|
||||||
* phpDocumentor documentation.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isTypeAKeyword($type)
|
|
||||||
{
|
|
||||||
return in_array(strtolower($type), $this->keywords);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detects whether the given type represents a relative or absolute path.
|
|
||||||
*
|
|
||||||
* This method will detect keywords as being absolute; even though they are
|
|
||||||
* not preceeded by a namespace separator.
|
|
||||||
*
|
|
||||||
* @param string $type A relative or absolute type as defined in the
|
|
||||||
* phpDocumentor documentation.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isRelativeType($type)
|
|
||||||
{
|
|
||||||
return ($type[0] !== self::OPERATOR_NAMESPACE)
|
|
||||||
|| $this->isTypeAKeyword($type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* This file is part of phpDocumentor.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
// Added imports on purpose as mock for the unit tests, please do not remove.
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag as m, Barryvdh;
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
// yes, the slash is part of the test
|
||||||
|
use PHPUnit\Framework\{
|
||||||
|
Assert,
|
||||||
|
Exception as e
|
||||||
|
};
|
||||||
|
use \ReflectionClass;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass \phpDocumentor\Reflection\Types\ContextFactory
|
||||||
|
* @covers ::<private>
|
||||||
|
*/
|
||||||
|
class ContextFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers ::createFromReflector
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testReadsNamespaceFromClassReflection(): void
|
||||||
|
{
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createFromReflector(new ReflectionClass($this));
|
||||||
|
|
||||||
|
$this->assertSame(__NAMESPACE__, $context->getNamespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createFromReflector
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testReadsAliasesFromClassReflection(): void
|
||||||
|
{
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createFromReflector(new ReflectionClass($this));
|
||||||
|
|
||||||
|
$this->assertNamespaceAliasesFrom($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testReadsNamespaceFromProvidedNamespaceAndContent(): void
|
||||||
|
{
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createForNamespace(__NAMESPACE__, file_get_contents(__FILE__));
|
||||||
|
|
||||||
|
$this->assertSame(__NAMESPACE__, $context->getNamespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testReadsAliasesFromProvidedNamespaceAndContent(): void
|
||||||
|
{
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createForNamespace(__NAMESPACE__, file_get_contents(__FILE__));
|
||||||
|
|
||||||
|
$this->assertNamespaceAliasesFrom($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testTraitUseIsNotDetectedAsNamespaceUse(): void
|
||||||
|
{
|
||||||
|
$php = '<?php declare(strict_types=1);
|
||||||
|
namespace Foo;
|
||||||
|
|
||||||
|
trait FooTrait {}
|
||||||
|
|
||||||
|
class FooClass {
|
||||||
|
use FooTrait;
|
||||||
|
}
|
||||||
|
';
|
||||||
|
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createForNamespace('Foo', $php);
|
||||||
|
|
||||||
|
$this->assertSame([], $context->getNamespaceAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testAllOpeningBracesAreCheckedWhenSearchingForEndOfClass(): void
|
||||||
|
{
|
||||||
|
$php = '<?php declare(strict_types=1);
|
||||||
|
namespace Foo;
|
||||||
|
|
||||||
|
trait FooTrait {}
|
||||||
|
trait BarTrait {}
|
||||||
|
|
||||||
|
class FooClass {
|
||||||
|
use FooTrait;
|
||||||
|
|
||||||
|
public function bar()
|
||||||
|
{
|
||||||
|
echo "{$baz}";
|
||||||
|
echo "${baz}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BarClass {
|
||||||
|
use BarTrait;
|
||||||
|
|
||||||
|
public function bar()
|
||||||
|
{
|
||||||
|
echo "{$baz}";
|
||||||
|
echo "${baz}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
';
|
||||||
|
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createForNamespace('Foo', $php);
|
||||||
|
|
||||||
|
$this->assertSame([], $context->getNamespaceAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createForNamespace
|
||||||
|
* @uses Barryvdh\Reflection\DocBlock\Context
|
||||||
|
*/
|
||||||
|
public function testTraitContainsClosureWithUseStatement(): void
|
||||||
|
{
|
||||||
|
$php = '<?php declare(strict_types=1);
|
||||||
|
namespace Foo;
|
||||||
|
|
||||||
|
trait FooTrait {
|
||||||
|
protected function check(array $data, string $key) : void
|
||||||
|
{
|
||||||
|
array_walk($data, function(&$item) use ($key) {
|
||||||
|
// update item based on the key
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooClass {
|
||||||
|
use FooTrait;
|
||||||
|
}
|
||||||
|
';
|
||||||
|
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createForNamespace('Foo', $php);
|
||||||
|
|
||||||
|
$this->assertSame([], $context->getNamespaceAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createFromReflector
|
||||||
|
*/
|
||||||
|
public function testEmptyFileName(): void
|
||||||
|
{
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createFromReflector(new ReflectionClass(stdClass::class));
|
||||||
|
|
||||||
|
$this->assertSame([], $context->getNamespaceAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::createFromReflector
|
||||||
|
*/
|
||||||
|
public function testEvalDClass(): void
|
||||||
|
{
|
||||||
|
eval(
|
||||||
|
<<<PHP
|
||||||
|
namespace Foo;
|
||||||
|
|
||||||
|
class Bar
|
||||||
|
{
|
||||||
|
}
|
||||||
|
PHP
|
||||||
|
);
|
||||||
|
$fixture = new ContextFactory();
|
||||||
|
$context = $fixture->createFromReflector(new ReflectionClass('Foo\Bar'));
|
||||||
|
|
||||||
|
$this->assertSame([], $context->getNamespaceAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assertNamespaceAliasesFrom(Context $context)
|
||||||
|
{
|
||||||
|
$expected = [
|
||||||
|
'm' => '\\' . m::class,
|
||||||
|
'DocBlock' => '\\' . DocBlock::class,
|
||||||
|
'Tag' => '\\' . Tag::class,
|
||||||
|
'Barryvdh' => '\\' . 'Barryvdh',
|
||||||
|
'TestCase' => '\\' . TestCase::class,
|
||||||
|
'Assert' => '\\' . Assert::class,
|
||||||
|
'e' => '\\' . e::class,
|
||||||
|
ReflectionClass::class => '\\' . ReflectionClass::class,
|
||||||
|
\stdClass::class => '\\' . \stdClass::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
$actual = $context->getNamespaceAliases();
|
||||||
|
|
||||||
|
// sort so that order differences don't break it
|
||||||
|
asort($expected);
|
||||||
|
asort($actual);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Description Test
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Description
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class DescriptionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testConstruct()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame($fixture, $parsedContents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInlineTagParsing()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a {@link http://phpdoc.org/ description} that uses inline
|
||||||
|
tags.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame('This is text for a ', $parsedContents[0]);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag\LinkTag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
' that uses inline
|
||||||
|
tags.',
|
||||||
|
$parsedContents[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInlineTagAtStartParsing()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
{@link http://phpdoc.org/ This} is text for a description that uses inline
|
||||||
|
tags.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
|
||||||
|
$this->assertSame('', $parsedContents[0]);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag\LinkTag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
' is text for a description that uses inline
|
||||||
|
tags.',
|
||||||
|
$parsedContents[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedInlineTagParsing()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with {@internal inline tag with
|
||||||
|
{@link http://phpdoc.org another inline tag} in it}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
|
||||||
|
$parsedDescription = $parsedContents[1]->getParsedDescription();
|
||||||
|
$this->assertCount(3, $parsedDescription);
|
||||||
|
$this->assertSame("inline tag with", trim($parsedDescription[0]));
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag\LinkTag',
|
||||||
|
$parsedDescription[1]
|
||||||
|
);
|
||||||
|
$this->assertSame(' in it', $parsedDescription[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLiteralOpeningDelimiter()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description containing { that is literal.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame($fixture, $parsedContents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedLiteralOpeningDelimiter()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description containing {@internal inline tag that has { that
|
||||||
|
is literal}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description containing ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
array('inline tag that has { that
|
||||||
|
is literal'),
|
||||||
|
$parsedContents[1]->getParsedDescription()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLiteralClosingDelimiter()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with {} that is not a tag.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with } that is not a tag.',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedLiteralClosingDelimiter()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with {@internal inline tag with {} that is not an
|
||||||
|
inline tag}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
array('inline tag with } that is not an
|
||||||
|
inline tag'),
|
||||||
|
$parsedContents[1]->getParsedDescription()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInlineTagEscapingSequence()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with literal {{@}link}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with literal {@link}.',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedInlineTagEscapingSequence()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with an {@internal inline tag with literal
|
||||||
|
{{@}link{} in it}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new Description($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with an ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
array('inline tag with literal
|
||||||
|
{@link} in it'),
|
||||||
|
$parsedContents[1]->getParsedDescription()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Covers Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\CoversTag
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class CoversTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\CoversTag can create
|
||||||
|
* a link for the covers doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exReference
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\CoversTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exReference
|
||||||
|
) {
|
||||||
|
$tag = new CoversTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exReference, $tag->getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exReference
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'covers',
|
||||||
|
'Foo::bar()',
|
||||||
|
'Foo::bar()',
|
||||||
|
'',
|
||||||
|
'Foo::bar()'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'covers',
|
||||||
|
'Foo::bar() Testing',
|
||||||
|
'Foo::bar() Testing',
|
||||||
|
'Testing',
|
||||||
|
'Foo::bar()',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'covers',
|
||||||
|
'Foo::bar() Testing comments',
|
||||||
|
'Foo::bar() Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
'Foo::bar()',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Deprecated Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\DeprecatedTag
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class DeprecatedTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\LinkTag can create
|
||||||
|
* a link for the @deprecated doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exDescription
|
||||||
|
* @param string $exVersion
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\DeprecatedTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exVersion
|
||||||
|
) {
|
||||||
|
$tag = new DeprecatedTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exVersion, $tag->getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exVersion
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
'1.0 First release.',
|
||||||
|
'1.0 First release.',
|
||||||
|
'First release.',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
"1.0\nFirst release.",
|
||||||
|
"1.0\nFirst release.",
|
||||||
|
'First release.',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
"1.0\nFirst\nrelease.",
|
||||||
|
"1.0\nFirst\nrelease.",
|
||||||
|
"First\nrelease.",
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
'Unfinished release',
|
||||||
|
'Unfinished release',
|
||||||
|
'Unfinished release',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
'1.0',
|
||||||
|
'1.0',
|
||||||
|
'',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
'GIT: $Id$',
|
||||||
|
'GIT: $Id$',
|
||||||
|
'',
|
||||||
|
'GIT: $Id$'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'deprecated',
|
||||||
|
'GIT: $Id$ Dev build',
|
||||||
|
'GIT: $Id$ Dev build',
|
||||||
|
'Dev build',
|
||||||
|
'GIT: $Id$'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Example Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\ExampleTag
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ExampleTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\SourceTag can
|
||||||
|
* understand the @source DocBlock.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exStartingLine
|
||||||
|
* @param string $exLineCount
|
||||||
|
* @param string $exFilepath
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\ExampleTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exStartingLine,
|
||||||
|
$exLineCount,
|
||||||
|
$exFilePath
|
||||||
|
) {
|
||||||
|
$tag = new ExampleTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exStartingLine, $tag->getStartingLine());
|
||||||
|
$this->assertEquals($exLineCount, $tag->getLineCount());
|
||||||
|
$this->assertEquals($exFilePath, $tag->getFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type,
|
||||||
|
// $content,
|
||||||
|
// $exContent,
|
||||||
|
// $exDescription,
|
||||||
|
// $exStartingLine,
|
||||||
|
// $exLineCount,
|
||||||
|
// $exFilePath
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'file.php',
|
||||||
|
'file.php',
|
||||||
|
'',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'file.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
'comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'Testing'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'file.php 2 Testing',
|
||||||
|
'file.php 2 Testing',
|
||||||
|
'Testing',
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
'file.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'file.php 2 3 Testing comments',
|
||||||
|
'file.php 2 3 Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
'file.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'file.php 2 -1 Testing comments',
|
||||||
|
'file.php 2 -1 Testing comments',
|
||||||
|
'-1 Testing comments',
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
'file.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'file.php -1 1 Testing comments',
|
||||||
|
'file.php -1 1 Testing comments',
|
||||||
|
'-1 1 Testing comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'file.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'"file with spaces.php" Testing comments',
|
||||||
|
'"file with spaces.php" Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'"file with spaces.php" 2 Testing comments',
|
||||||
|
'"file with spaces.php" 2 Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
'file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'"file with spaces.php" 2 3 Testing comments',
|
||||||
|
'"file with spaces.php" 2 3 Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
'file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'"file with spaces.php" 2 -3 Testing comments',
|
||||||
|
'"file with spaces.php" 2 -3 Testing comments',
|
||||||
|
'-3 Testing comments',
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
'file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'"file with spaces.php" -2 3 Testing comments',
|
||||||
|
'"file with spaces.php" -2 3 Testing comments',
|
||||||
|
'-2 3 Testing comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'file%20with%20spaces.php Testing comments',
|
||||||
|
'file%20with%20spaces.php Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'folder/file%20with%20spaces.php Testing comments',
|
||||||
|
'folder/file%20with%20spaces.php Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'folder/file with spaces.php'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'example',
|
||||||
|
'http://example.com/file%20with%20spaces.php Testing comments',
|
||||||
|
'http://example.com/file%20with%20spaces.php Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
'http://example.com/file%20with%20spaces.php'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-30
@@ -2,51 +2,56 @@
|
|||||||
/**
|
/**
|
||||||
* phpDocumentor Link Tag Test
|
* phpDocumentor Link Tag Test
|
||||||
*
|
*
|
||||||
* @author Ben Selby <benmatselby@gmail.com>
|
* PHP version 5.3
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\LinkTag
|
|
||||||
*
|
*
|
||||||
* @author Ben Selby <benmatselby@gmail.com>
|
* @author Ben Selby <benmatselby@gmail.com>
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
*/
|
*/
|
||||||
class LinkTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\LinkTag
|
||||||
|
*
|
||||||
|
* @author Ben Selby <benmatselby@gmail.com>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class LinkTagTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\LinkTag can create
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\LinkTag can create
|
||||||
* a link for the @link doc block
|
* a link for the @link doc block.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @param string $exName
|
|
||||||
* @param string $exContent
|
* @param string $exContent
|
||||||
* @param string $exDescription
|
* @param string $exDescription
|
||||||
* @param string $exLink
|
* @param string $exLink
|
||||||
*
|
*
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\LinkTag
|
||||||
* @dataProvider provideDataForConstuctor
|
* @dataProvider provideDataForConstuctor
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testConstructorParesInputsIntoCorrectFields(
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
$type, $content, $exName, $exContent, $exDescription, $exLink
|
$type,
|
||||||
)
|
$content,
|
||||||
{
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exLink
|
||||||
|
) {
|
||||||
$tag = new LinkTag($type, $content);
|
$tag = new LinkTag($type, $content);
|
||||||
|
|
||||||
$actualName = $tag->getName();
|
$this->assertEquals($type, $tag->getName());
|
||||||
$actualContent = $tag->getContent();
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
$actualDescription = $tag->getDescription();
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
$actualLink = $tag->getLink();
|
$this->assertEquals($exLink, $tag->getLink());
|
||||||
|
|
||||||
$this->assertEquals($exName, $actualName);
|
|
||||||
$this->assertEquals($exContent, $actualContent);
|
|
||||||
$this->assertEquals($exDescription, $actualDescription);
|
|
||||||
$this->assertEquals($exLink, $actualLink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,12 +61,11 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function provideDataForConstuctor()
|
public function provideDataForConstuctor()
|
||||||
{
|
{
|
||||||
// $type, $content, $exName, $exContent, $exDescription, $exLink
|
// $type, $content, $exContent, $exDescription, $exLink
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'link',
|
'link',
|
||||||
'http://www.phpdoc.org/',
|
'http://www.phpdoc.org/',
|
||||||
'link',
|
|
||||||
'http://www.phpdoc.org/',
|
'http://www.phpdoc.org/',
|
||||||
'http://www.phpdoc.org/',
|
'http://www.phpdoc.org/',
|
||||||
'http://www.phpdoc.org/'
|
'http://www.phpdoc.org/'
|
||||||
@@ -69,7 +73,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
'link',
|
'link',
|
||||||
'http://www.phpdoc.org/ Testing',
|
'http://www.phpdoc.org/ Testing',
|
||||||
'link',
|
|
||||||
'http://www.phpdoc.org/ Testing',
|
'http://www.phpdoc.org/ Testing',
|
||||||
'Testing',
|
'Testing',
|
||||||
'http://www.phpdoc.org/'
|
'http://www.phpdoc.org/'
|
||||||
@@ -77,7 +80,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
'link',
|
'link',
|
||||||
'http://www.phpdoc.org/ Testing comments',
|
'http://www.phpdoc.org/ Testing comments',
|
||||||
'link',
|
|
||||||
'http://www.phpdoc.org/ Testing comments',
|
'http://www.phpdoc.org/ Testing comments',
|
||||||
'Testing comments',
|
'Testing comments',
|
||||||
'http://www.phpdoc.org/'
|
'http://www.phpdoc.org/'
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Method Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\MethodTag
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class MethodTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $signature The signature to test.
|
||||||
|
* @param bool $valid Whether the given signature is expected to
|
||||||
|
* be valid.
|
||||||
|
* @param string $expected_name The method name that is expected from this
|
||||||
|
* signature.
|
||||||
|
* @param string $expected_return The return type that is expected from this
|
||||||
|
* signature.
|
||||||
|
* @param bool $paramCount Number of parameters in the signature.
|
||||||
|
* @param string $description The short description mentioned in the
|
||||||
|
* signature.
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\MethodTag
|
||||||
|
* @dataProvider getTestSignatures
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstruct(
|
||||||
|
$signature,
|
||||||
|
$valid,
|
||||||
|
$expected_name,
|
||||||
|
$expected_return,
|
||||||
|
$expected_isStatic,
|
||||||
|
$paramCount,
|
||||||
|
$description
|
||||||
|
) {
|
||||||
|
ob_start();
|
||||||
|
$tag = new MethodTag('method', $signature);
|
||||||
|
$stdout = ob_get_clean();
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$valid,
|
||||||
|
empty($stdout),
|
||||||
|
'No error should have been output if the signature is valid'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected_name, $tag->getMethodName());
|
||||||
|
$this->assertEquals($expected_return, $tag->getType());
|
||||||
|
$this->assertEquals($description, $tag->getDescription());
|
||||||
|
$this->assertEquals($expected_isStatic, $tag->isStatic());
|
||||||
|
$this->assertCount($paramCount, $tag->getArguments());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTestSignatures()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// TODO: Verify this case
|
||||||
|
// array(
|
||||||
|
// 'foo',
|
||||||
|
// false, 'foo', '', false, 0, ''
|
||||||
|
// ),
|
||||||
|
array(
|
||||||
|
'foo()',
|
||||||
|
true, 'foo', 'void', false, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'foo() description',
|
||||||
|
true, 'foo', 'void', false, 0, 'description'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo()',
|
||||||
|
true, 'foo', 'int', false, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo() description',
|
||||||
|
true, 'foo', 'int', false, 0, 'description'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo($a, $b)',
|
||||||
|
true, 'foo', 'int', false, 2, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo() foo(int $a, int $b)',
|
||||||
|
true, 'foo', 'int', false, 2, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo(int $a, int $b)',
|
||||||
|
true, 'foo', 'int', false, 2, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'null|int foo(int $a, int $b)',
|
||||||
|
true, 'foo', 'null|int', false, 2, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo(null|int $a, int $b)',
|
||||||
|
true, 'foo', 'int', false, 2, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'\Exception foo() foo(Exception $a, Exception $b)',
|
||||||
|
true, 'foo', '\Exception', false, 2, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo() foo(Exception $a, Exception $b) description',
|
||||||
|
true, 'foo', 'int', false, 2, 'description'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int foo() foo(\Exception $a, \Exception $b) description',
|
||||||
|
true, 'foo', 'int', false, 2, 'description'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'void()',
|
||||||
|
true, 'void', 'void', false, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'static foo()',
|
||||||
|
true, 'foo', 'static', false, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'static void foo()',
|
||||||
|
true, 'foo', 'void', true, 0, ''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'static static foo()',
|
||||||
|
true, 'foo', 'static', true, 0, ''
|
||||||
|
),
|
||||||
|
|
||||||
|
// generic array
|
||||||
|
array(
|
||||||
|
'array<int, string> foo()',
|
||||||
|
true, 'foo', 'array<int, string>', false, 0, ''
|
||||||
|
),
|
||||||
|
|
||||||
|
// nested generics
|
||||||
|
array(
|
||||||
|
'array<int, array<string, mixed>> foo()',
|
||||||
|
true, 'foo', 'array<int, array<string, mixed>>', false, 0, ''
|
||||||
|
),
|
||||||
|
|
||||||
|
// closure
|
||||||
|
array(
|
||||||
|
'(\Closure(int, string): bool) foo()',
|
||||||
|
true, 'foo', '(\Closure(int, string): bool)', false, 0, ''
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Param tag test.
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\ParamTag
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ParamTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\ParamTag can
|
||||||
|
* understand the @param DocBlock.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $extractedType
|
||||||
|
* @param string $extractedTypes
|
||||||
|
* @param string $extractedVarName
|
||||||
|
* @param string $extractedDescription
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\ParamTag
|
||||||
|
* @dataProvider provideDataForConstructor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParsesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$extractedType,
|
||||||
|
$extractedTypes,
|
||||||
|
$extractedVarName,
|
||||||
|
$extractedDescription
|
||||||
|
) {
|
||||||
|
$tag = new ParamTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($extractedType, $tag->getType());
|
||||||
|
$this->assertEquals($extractedTypes, $tag->getTypes());
|
||||||
|
$this->assertEquals($extractedVarName, $tag->getVariableName());
|
||||||
|
$this->assertEquals($extractedDescription, $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstructor()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('param', 'int', 'int', array('int'), '', ''),
|
||||||
|
array('param', '$bob', '', array(), '$bob', ''),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'int Number of bobs',
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'',
|
||||||
|
'Number of bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'int $bob',
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'$bob',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'int $bob Number of bobs',
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'$bob',
|
||||||
|
'Number of bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
"int Description \n on multiple lines",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'',
|
||||||
|
"Description \n on multiple lines"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
"int \n\$bob Variable name on a new line",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'$bob',
|
||||||
|
"Variable name on a new line"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
"\nint \$bob Type on a new line",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'$bob',
|
||||||
|
"Type on a new line"
|
||||||
|
),
|
||||||
|
|
||||||
|
// generic array
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'array<int, string> $names',
|
||||||
|
'array<int, string>',
|
||||||
|
array('array<int, string>'),
|
||||||
|
'$names',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
|
||||||
|
// nested generics
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'array<int, array<string, mixed>> $arrays',
|
||||||
|
'array<int, array<string, mixed>>',
|
||||||
|
array('array<int, array<string, mixed>>'),
|
||||||
|
'$arrays',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
|
||||||
|
// closure
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'(\Closure(int, string): bool) $callback',
|
||||||
|
'(\Closure(int, string): bool)',
|
||||||
|
array('(\Closure(int, string): bool)'),
|
||||||
|
'$callback',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
|
||||||
|
// generic array in closure
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'(\Closure(array<int, string>): bool) $callback',
|
||||||
|
'(\Closure(array<int, string>): bool)',
|
||||||
|
array('(\Closure(array<int, string>): bool)'),
|
||||||
|
'$callback',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
|
||||||
|
// union types in closure
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'(\Closure(int|string): bool)|bool $callback',
|
||||||
|
'(\Closure(int|string): bool)|bool',
|
||||||
|
array('(\Closure(int|string): bool)', 'bool'),
|
||||||
|
'$callback',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
|
||||||
|
// example from Laravel Framework - Eloquent Builder)
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>|string $relations',
|
||||||
|
'array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>|string',
|
||||||
|
array('array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>', 'string'),
|
||||||
|
'$relations',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null $callback',
|
||||||
|
'(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null',
|
||||||
|
array('(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)', 'string', 'null'),
|
||||||
|
'$callback',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
|
||||||
|
// array shapes
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'array{foo: string, bar: int} $array',
|
||||||
|
'array{foo: string, bar: int}',
|
||||||
|
array('array{foo: string, bar: int}'),
|
||||||
|
'$array',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'param',
|
||||||
|
'MyArray[\'key\'] $value',
|
||||||
|
'MyArray[\'key\']',
|
||||||
|
array('MyArray[\'key\']'),
|
||||||
|
'$value',
|
||||||
|
''
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Return tag test.
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\ReturnTag
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ReturnTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\ReturnTag can
|
||||||
|
* understand the @return DocBlock.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $extractedType
|
||||||
|
* @param string $extractedTypes
|
||||||
|
* @param string $extractedDescription
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\ReturnTag
|
||||||
|
* @dataProvider provideDataForConstructor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParsesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$extractedType,
|
||||||
|
$extractedTypes,
|
||||||
|
$extractedDescription
|
||||||
|
) {
|
||||||
|
$tag = new ReturnTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($extractedType, $tag->getType());
|
||||||
|
$this->assertEquals($extractedTypes, $tag->getTypes());
|
||||||
|
$this->assertEquals($extractedDescription, $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstructor()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('return', '', '', array(), ''),
|
||||||
|
array('return', 'int', 'int', array('int'), ''),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
'int Number of Bobs',
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'Number of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
'int|double Number of Bobs',
|
||||||
|
'int|double',
|
||||||
|
array('int', 'double'),
|
||||||
|
'Number of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
"int Number of \n Bobs",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
"Number of \n Bobs"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
" int Number of Bobs",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
"Number of Bobs"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
"int\nNumber of Bobs",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
"Number of Bobs"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
'array<int, string> Types of Bobs',
|
||||||
|
'array<int, string>',
|
||||||
|
array('array<int, string>'),
|
||||||
|
'Types of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
'array<int, string>|string Types of Bobs',
|
||||||
|
'array<int, string>|string',
|
||||||
|
array('array<int, string>', 'string'),
|
||||||
|
'Types of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
'array<int, string|bool>|string Types of Bobs',
|
||||||
|
'array<int, string|bool>|string',
|
||||||
|
array('array<int, string|bool>', 'string'),
|
||||||
|
'Types of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'return',
|
||||||
|
'MyArray[\'key\'] Type of Bobs',
|
||||||
|
'MyArray[\'key\']',
|
||||||
|
array('MyArray[\'key\']'),
|
||||||
|
'Type of Bobs'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor See Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\SeeTag
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SeeTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
|
||||||
|
* for the @see doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exReference
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\SeeTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exReference
|
||||||
|
) {
|
||||||
|
$tag = new SeeTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exReference, $tag->getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exReference
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'see',
|
||||||
|
'Foo::bar()',
|
||||||
|
'Foo::bar()',
|
||||||
|
'',
|
||||||
|
'Foo::bar()'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'see',
|
||||||
|
'Foo::bar() Testing',
|
||||||
|
'Foo::bar() Testing',
|
||||||
|
'Testing',
|
||||||
|
'Foo::bar()',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'see',
|
||||||
|
'Foo::bar() Testing comments',
|
||||||
|
'Foo::bar() Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
'Foo::bar()',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Since Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\SinceTag
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SinceTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\LinkTag can create
|
||||||
|
* a link for the @since doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exDescription
|
||||||
|
* @param string $exVersion
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\SinceTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exVersion
|
||||||
|
) {
|
||||||
|
$tag = new SinceTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exVersion, $tag->getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exVersion
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
'1.0 First release.',
|
||||||
|
'1.0 First release.',
|
||||||
|
'First release.',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
"1.0\nFirst release.",
|
||||||
|
"1.0\nFirst release.",
|
||||||
|
'First release.',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
"1.0\nFirst\nrelease.",
|
||||||
|
"1.0\nFirst\nrelease.",
|
||||||
|
"First\nrelease.",
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
'Unfinished release',
|
||||||
|
'Unfinished release',
|
||||||
|
'Unfinished release',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
'1.0',
|
||||||
|
'1.0',
|
||||||
|
'',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
'GIT: $Id$',
|
||||||
|
'GIT: $Id$',
|
||||||
|
'',
|
||||||
|
'GIT: $Id$'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'since',
|
||||||
|
'GIT: $Id$ Dev build',
|
||||||
|
'GIT: $Id$ Dev build',
|
||||||
|
'Dev build',
|
||||||
|
'GIT: $Id$'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Source Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\SourceTag
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SourceTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\SourceTag can
|
||||||
|
* understand the @source DocBlock.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exStartingLine
|
||||||
|
* @param string $exLineCount
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\SourceTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exStartingLine,
|
||||||
|
$exLineCount
|
||||||
|
) {
|
||||||
|
$tag = new SourceTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exStartingLine, $tag->getStartingLine());
|
||||||
|
$this->assertEquals($exLineCount, $tag->getLineCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exStartingLine, $exLineCount
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'source',
|
||||||
|
'2',
|
||||||
|
'2',
|
||||||
|
'',
|
||||||
|
2,
|
||||||
|
null
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'source',
|
||||||
|
'Testing',
|
||||||
|
'Testing',
|
||||||
|
'Testing',
|
||||||
|
1,
|
||||||
|
null
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'source',
|
||||||
|
'2 Testing',
|
||||||
|
'2 Testing',
|
||||||
|
'Testing',
|
||||||
|
2,
|
||||||
|
null
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'source',
|
||||||
|
'2 3 Testing comments',
|
||||||
|
'2 3 Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'source',
|
||||||
|
'2 -1 Testing comments',
|
||||||
|
'2 -1 Testing comments',
|
||||||
|
'-1 Testing comments',
|
||||||
|
2,
|
||||||
|
null
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'source',
|
||||||
|
'-1 1 Testing comments',
|
||||||
|
'-1 1 Testing comments',
|
||||||
|
'-1 1 Testing comments',
|
||||||
|
1,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor SuppressWarnings Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Andrew Smith <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag
|
||||||
|
*
|
||||||
|
* @author Andrew Smith <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class SuppressWarningsTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag can
|
||||||
|
* understand the @SuppressWarnings doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exType
|
||||||
|
* @param string $exVariable
|
||||||
|
* @param string $exDescription
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$description
|
||||||
|
) {
|
||||||
|
$tag = new SuppressWarningsTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($description, $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $description
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'SuppressWarnings',
|
||||||
|
'SuppressWarnings(PHPMD)',
|
||||||
|
'SuppressWarnings(PHPMD)',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'SuppressWarnings',
|
||||||
|
'SuppressWarnings(PHPMD.TooManyMethods)',
|
||||||
|
'SuppressWarnings(PHPMD.TooManyMethods)',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* phpDocumentor Template Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\TemplateTag
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class TemplateTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
|
||||||
|
* for the @see doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exReference
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\SeeTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exTemplateName,
|
||||||
|
$exBound
|
||||||
|
) {
|
||||||
|
$tag = new TemplateTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exTemplateName, $tag->getTemplateName());
|
||||||
|
$this->assertEquals($exBound, $tag->getBound());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exTemplateName, $exBound
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'template',
|
||||||
|
'TValue',
|
||||||
|
'TValue',
|
||||||
|
'',
|
||||||
|
'TValue',
|
||||||
|
null,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'template',
|
||||||
|
'TValue of string',
|
||||||
|
'TValue of string',
|
||||||
|
'',
|
||||||
|
'TValue',
|
||||||
|
'string',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Throws tag test.
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\ThrowsTag
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class ThrowsTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\ThrowsTag can
|
||||||
|
* understand the @throws DocBlock.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $extractedType
|
||||||
|
* @param string $extractedTypes
|
||||||
|
* @param string $extractedDescription
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\ThrowsTag
|
||||||
|
* @dataProvider provideDataForConstructor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParsesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$extractedType,
|
||||||
|
$extractedTypes,
|
||||||
|
$extractedDescription
|
||||||
|
) {
|
||||||
|
$tag = new ThrowsTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($extractedType, $tag->getType());
|
||||||
|
$this->assertEquals($extractedTypes, $tag->getTypes());
|
||||||
|
$this->assertEquals($extractedDescription, $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstructor()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('throws', '', '', array(), ''),
|
||||||
|
array('throws', 'int', 'int', array('int'), ''),
|
||||||
|
array(
|
||||||
|
'throws',
|
||||||
|
'int Number of Bobs',
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
'Number of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'throws',
|
||||||
|
'int|double Number of Bobs',
|
||||||
|
'int|double',
|
||||||
|
array('int', 'double'),
|
||||||
|
'Number of Bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'throws',
|
||||||
|
"int Number of \n Bobs",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
"Number of \n Bobs"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'throws',
|
||||||
|
" int Number of Bobs",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
"Number of Bobs"
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'throws',
|
||||||
|
"int\nNumber of Bobs",
|
||||||
|
'int',
|
||||||
|
array('int'),
|
||||||
|
"Number of Bobs"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Uses Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\UsesTag
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class UsesTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\UsesTag can create
|
||||||
|
* a link for the @uses doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exReference
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\UsesTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exReference
|
||||||
|
) {
|
||||||
|
$tag = new UsesTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exReference, $tag->getReference());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exReference
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'uses',
|
||||||
|
'Foo::bar()',
|
||||||
|
'Foo::bar()',
|
||||||
|
'',
|
||||||
|
'Foo::bar()'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'uses',
|
||||||
|
'Foo::bar() Testing',
|
||||||
|
'Foo::bar() Testing',
|
||||||
|
'Testing',
|
||||||
|
'Foo::bar()',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'uses',
|
||||||
|
'Foo::bar() Testing comments',
|
||||||
|
'Foo::bar() Testing comments',
|
||||||
|
'Testing comments',
|
||||||
|
'Foo::bar()',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Var Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\VarTag
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class VarTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\VarTag can
|
||||||
|
* understand the @var doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exType
|
||||||
|
* @param string $exVariable
|
||||||
|
* @param string $exDescription
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\VarTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exType,
|
||||||
|
$exVariable,
|
||||||
|
$exDescription
|
||||||
|
) {
|
||||||
|
$tag = new VarTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exType, $tag->getType());
|
||||||
|
$this->assertEquals($exVariable, $tag->getVariableName());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exType, $exVariable, $exDescription
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'var',
|
||||||
|
'int',
|
||||||
|
'int',
|
||||||
|
'',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'var',
|
||||||
|
'int $bob',
|
||||||
|
'int',
|
||||||
|
'$bob',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'var',
|
||||||
|
'int $bob Number of bobs',
|
||||||
|
'int',
|
||||||
|
'$bob',
|
||||||
|
'Number of bobs'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'var',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Version Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\VersionTag
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class VersionTagTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\LinkTag can create
|
||||||
|
* a link for the @version doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exContent
|
||||||
|
* @param string $exDescription
|
||||||
|
* @param string $exVersion
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag\VersionTag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exContent,
|
||||||
|
$exDescription,
|
||||||
|
$exVersion
|
||||||
|
) {
|
||||||
|
$tag = new VersionTag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($exContent, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($exVersion, $tag->getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exContent, $exDescription, $exVersion
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
'1.0 First release.',
|
||||||
|
'1.0 First release.',
|
||||||
|
'First release.',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
"1.0\nFirst release.",
|
||||||
|
"1.0\nFirst release.",
|
||||||
|
'First release.',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
"1.0\nFirst\nrelease.",
|
||||||
|
"1.0\nFirst\nrelease.",
|
||||||
|
"First\nrelease.",
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
'Unfinished release',
|
||||||
|
'Unfinished release',
|
||||||
|
'Unfinished release',
|
||||||
|
''
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
'1.0',
|
||||||
|
'1.0',
|
||||||
|
'',
|
||||||
|
'1.0'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
'GIT: $Id$',
|
||||||
|
'GIT: $Id$',
|
||||||
|
'',
|
||||||
|
'GIT: $Id$'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'version',
|
||||||
|
'GIT: $Id$ Dev build',
|
||||||
|
'GIT: $Id$ Dev build',
|
||||||
|
'Dev build',
|
||||||
|
'GIT: $Id$'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Var Tag Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Tag\VarTag
|
||||||
|
*
|
||||||
|
* @author Daniel O'Connor <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class TagTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testInvalidTagLine()
|
||||||
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
Tag::createInstance('Invalid tag line');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTagHandlerUnregistration()
|
||||||
|
{
|
||||||
|
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
|
||||||
|
$tagPreUnreg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPreUnreg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPreUnreg
|
||||||
|
);
|
||||||
|
|
||||||
|
Tag::registerTagHandler('var', null);
|
||||||
|
|
||||||
|
$tagPostUnreg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertNotInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPostUnreg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPostUnreg
|
||||||
|
);
|
||||||
|
|
||||||
|
Tag::registerTagHandler('var', $currentHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTagHandlerCorrectRegistration()
|
||||||
|
{
|
||||||
|
if (!ini_get('allow_url_include')) {
|
||||||
|
$this->markTestSkipped('"data" URIs for includes are required.');
|
||||||
|
}
|
||||||
|
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
|
||||||
|
$tagPreReg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
|
||||||
|
include 'data:text/plain;base64,'. base64_encode(
|
||||||
|
<<<TAG_HANDLER
|
||||||
|
<?php
|
||||||
|
class MyTagHandler extends \Barryvdh\Reflection\DocBlock\Tag {}
|
||||||
|
TAG_HANDLER
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
|
||||||
|
|
||||||
|
$tagPostReg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertNotInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
'\MyTagHandler',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testTagHandlerCorrectRegistration
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::createInstance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNamespacedTagHandlerCorrectRegistration()
|
||||||
|
{
|
||||||
|
$tagPreReg = Tag::createInstance('@T something');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
$this->assertNotInstanceOf(
|
||||||
|
'\MyTagHandler',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler')
|
||||||
|
);
|
||||||
|
|
||||||
|
$tagPostReg = Tag::createInstance(
|
||||||
|
'@T something',
|
||||||
|
new DocBlock(
|
||||||
|
'',
|
||||||
|
new Context('', array('T' => '\MyNamespace\MyTag'))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
'\MyTagHandler',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
Tag::registerTagHandler('\MyNamespace\MyTag', null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testTagHandlerCorrectRegistration
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::createInstance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNamespacedTagHandlerIncorrectRegistration()
|
||||||
|
{
|
||||||
|
$tagPreReg = Tag::createInstance('@T something');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
$this->assertNotInstanceOf(
|
||||||
|
'\MyTagHandler',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertFalse(
|
||||||
|
Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler')
|
||||||
|
);
|
||||||
|
|
||||||
|
$tagPostReg = Tag::createInstance(
|
||||||
|
'@T something',
|
||||||
|
new DocBlock(
|
||||||
|
'',
|
||||||
|
new Context('', array('T' => '\MyNamespace\MyTag'))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
$this->assertNotInstanceOf(
|
||||||
|
'\MyTagHandler',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNonExistentTagHandlerRegistration()
|
||||||
|
{
|
||||||
|
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
|
||||||
|
$tagPreReg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
|
||||||
|
|
||||||
|
$tagPostReg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag::registerTagHandler
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIncompatibleTagHandlerRegistration()
|
||||||
|
{
|
||||||
|
$currentHandler = __NAMESPACE__ . '\Tag\VarTag';
|
||||||
|
$tagPreReg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPreReg
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertFalse(
|
||||||
|
Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
|
||||||
|
);
|
||||||
|
|
||||||
|
$tagPostReg = Tag::createInstance('@var mixed');
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$currentHandler,
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$tagPostReg
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the \Barryvdh\Reflection\DocBlock\Tag\VarTag can
|
||||||
|
* understand the @var doc block.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $content
|
||||||
|
* @param string $exDescription
|
||||||
|
*
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock\Tag
|
||||||
|
* @dataProvider provideDataForConstuctor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructorParesInputsIntoCorrectFields(
|
||||||
|
$type,
|
||||||
|
$content,
|
||||||
|
$exDescription
|
||||||
|
) {
|
||||||
|
$tag = new Tag($type, $content);
|
||||||
|
|
||||||
|
$this->assertEquals($type, $tag->getName());
|
||||||
|
$this->assertEquals($content, $tag->getContent());
|
||||||
|
$this->assertEquals($exDescription, $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provideDataForConstuctor()
|
||||||
|
{
|
||||||
|
// $type, $content, $exDescription
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'unknown',
|
||||||
|
'some content',
|
||||||
|
'some content',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'unknown',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,374 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Collection Test
|
||||||
|
*
|
||||||
|
* PHP version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection\DocBlock\Type;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for \Barryvdh\Reflection\DocBlock\Type\Collection
|
||||||
|
*
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class CollectionTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::getContext
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstruct()
|
||||||
|
{
|
||||||
|
$collection = new Collection();
|
||||||
|
$this->assertCount(0, $collection);
|
||||||
|
$this->assertEquals('', $collection->getContext()->getNamespace());
|
||||||
|
$this->assertCount(0, $collection->getContext()->getNamespaceAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructWithTypes()
|
||||||
|
{
|
||||||
|
$collection = new Collection(array('integer', 'string'));
|
||||||
|
$this->assertCount(2, $collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructWithNamespace()
|
||||||
|
{
|
||||||
|
$collection = new Collection(array(), new Context('\My\Space'));
|
||||||
|
$this->assertEquals('My\Space', $collection->getContext()->getNamespace());
|
||||||
|
|
||||||
|
$collection = new Collection(array(), new Context('My\Space'));
|
||||||
|
$this->assertEquals('My\Space', $collection->getContext()->getNamespace());
|
||||||
|
|
||||||
|
$collection = new Collection(array(), null);
|
||||||
|
$this->assertEquals('', $collection->getContext()->getNamespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructWithNamespaceAliases()
|
||||||
|
{
|
||||||
|
$fixture = array('a' => 'b');
|
||||||
|
$collection = new Collection(array(), new Context(null, $fixture));
|
||||||
|
$this->assertEquals(
|
||||||
|
array('a' => '\b'),
|
||||||
|
$collection->getContext()->getNamespaceAliases()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fixture
|
||||||
|
* @param array $expected
|
||||||
|
*
|
||||||
|
* @dataProvider provideTypesToExpand
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAdd($fixture, $expected)
|
||||||
|
{
|
||||||
|
$collection = new Collection(
|
||||||
|
array(),
|
||||||
|
new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'))
|
||||||
|
);
|
||||||
|
$collection->add($fixture);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $collection->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fixture
|
||||||
|
* @param array $expected
|
||||||
|
*
|
||||||
|
* @dataProvider provideTypesToExpandWithoutNamespace
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddWithoutNamespace($fixture, $expected)
|
||||||
|
{
|
||||||
|
$collection = new Collection(
|
||||||
|
array(),
|
||||||
|
new Context(null, array('Alias' => '\My\Space\Aliasing'))
|
||||||
|
);
|
||||||
|
$collection->add($fixture);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $collection->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fixture
|
||||||
|
* @param array $expected
|
||||||
|
*
|
||||||
|
* @dataProvider provideTypesToExpandWithPropertyOrMethod
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddMethodsAndProperties($fixture, $expected)
|
||||||
|
{
|
||||||
|
$collection = new Collection(
|
||||||
|
array(),
|
||||||
|
new Context(null, array('LinkDescriptor' => '\phpDocumentor\LinkDescriptor'))
|
||||||
|
);
|
||||||
|
$collection->add($fixture);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $collection->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fixture
|
||||||
|
* @param array $expected
|
||||||
|
*
|
||||||
|
* @dataProvider provideTypesToExpandWithGenerics
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddWithGenerics($fixture, $expected)
|
||||||
|
{
|
||||||
|
$collection = new Collection(
|
||||||
|
array(),
|
||||||
|
new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'), '', array('TParent')),
|
||||||
|
array('TValue')
|
||||||
|
);
|
||||||
|
$collection->add($fixture);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $collection->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddWithInvalidArgument()
|
||||||
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->add(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the types and their expected values to test the retrieval of
|
||||||
|
* types.
|
||||||
|
*
|
||||||
|
* @param string $method Name of the method consuming this data provider.
|
||||||
|
* @param string $namespace Name of the namespace to user as basis.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function provideTypesToExpand($method, $namespace = '\My\Space\\')
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('', array()),
|
||||||
|
array(' ', array()),
|
||||||
|
array('int', array('int')),
|
||||||
|
array('int ', array('int')),
|
||||||
|
array('string', array('string')),
|
||||||
|
array('DocBlock', array($namespace.'DocBlock')),
|
||||||
|
array('DocBlock[]', array($namespace.'DocBlock[]')),
|
||||||
|
array(' DocBlock ', array($namespace.'DocBlock')),
|
||||||
|
array('\My\Space\DocBlock', array('\My\Space\DocBlock')),
|
||||||
|
array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')),
|
||||||
|
array(
|
||||||
|
'DocBlock|Tag',
|
||||||
|
array($namespace .'DocBlock', $namespace .'Tag')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'DocBlock|null',
|
||||||
|
array($namespace.'DocBlock', 'null')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'\My\Space\DocBlock|Tag',
|
||||||
|
array('\My\Space\DocBlock', $namespace.'Tag')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'DocBlock[]|null',
|
||||||
|
array($namespace.'DocBlock[]', 'null')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'DocBlock[]|int[]',
|
||||||
|
array($namespace.'DocBlock[]', 'int[]')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'array<string>',
|
||||||
|
array('array<string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'array<int, string>',
|
||||||
|
array('array<int, string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'array<int, string>|string',
|
||||||
|
array('array<int, string>', 'string')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'array<int, float|bool>|string',
|
||||||
|
array('array<int, float|bool>', 'string')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'array<int, string|array<int, bool>>|array<int, float>|string',
|
||||||
|
array('array<int, string|array<int, bool>>', 'array<int, float>', 'string')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'array{ 0: string, 1: string|int }',
|
||||||
|
array('array{ 0: string, 1: string|int }')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
"array{ 'key': string, 'value': string|int }",
|
||||||
|
array("array{ 'key': string, 'value': string|int }")
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
"MyArray['bar']",
|
||||||
|
array("MyArray['bar']")
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'LinkDescriptor::setLink()',
|
||||||
|
array($namespace.'LinkDescriptor::setLink()')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'Alias\LinkDescriptor::setLink()',
|
||||||
|
array('\My\Space\Aliasing\LinkDescriptor::setLink()')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'int<0, 100>',
|
||||||
|
array('int<0, 100>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'non-empty-array<string>',
|
||||||
|
array('non-empty-array<string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'non-empty-array<int, string>',
|
||||||
|
array('non-empty-array<int, string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'list<string>',
|
||||||
|
array('list<string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'non-empty-list<string>',
|
||||||
|
array('non-empty-list<string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'key-of<MyClass::ARRAY_CONST>',
|
||||||
|
array('key-of<MyClass::ARRAY_CONST>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'value-of<MyClass::ARRAY_CONST>',
|
||||||
|
array('value-of<MyClass::ARRAY_CONST>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'value-of<MyBackedEnum>',
|
||||||
|
array('value-of<MyBackedEnum>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'iterable<string>',
|
||||||
|
array('iterable<string>')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'callable',
|
||||||
|
array('callable')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'callable(int, string): int',
|
||||||
|
array('callable(int, string): int')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
"'text'",
|
||||||
|
array("'text'")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the types and their expected values to test the retrieval of
|
||||||
|
* types when no namespace is available.
|
||||||
|
*
|
||||||
|
* @param string $method Name of the method consuming this data provider.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function provideTypesToExpandWithoutNamespace($method)
|
||||||
|
{
|
||||||
|
return $this->provideTypesToExpand($method, '\\');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the method and property types and their expected values to test
|
||||||
|
* the retrieval of types.
|
||||||
|
*
|
||||||
|
* @param string $method Name of the method consuming this data provider.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function provideTypesToExpandWithPropertyOrMethod($method)
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'LinkDescriptor::setLink()',
|
||||||
|
array('\phpDocumentor\LinkDescriptor::setLink()')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'phpDocumentor\LinkDescriptor::setLink()',
|
||||||
|
array('\phpDocumentor\LinkDescriptor::setLink()')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'LinkDescriptor::$link',
|
||||||
|
array('\phpDocumentor\LinkDescriptor::$link')
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'phpDocumentor\LinkDescriptor::$link',
|
||||||
|
array('\phpDocumentor\LinkDescriptor::$link')
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the types and their expected values to test the retrieval of
|
||||||
|
* types including generics.
|
||||||
|
*
|
||||||
|
* @param string $method Name of the method consuming this data provider.
|
||||||
|
* @param string $namespace Name of the namespace to user as basis.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function provideTypesToExpandWithGenerics($method, $namespace = '\My\Space\\')
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('TValue', array('TValue')),
|
||||||
|
array('TValue[]', array('TValue[]')),
|
||||||
|
array('TValue|DocBlock', array('TValue', $namespace . 'DocBlock')),
|
||||||
|
array('TParent', array('TParent')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,357 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor DocBlock Test
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Barryvdh\Reflection;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Location;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Barryvdh\Reflection\DocBlock
|
||||||
|
*
|
||||||
|
* @author Mike van Riel <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class DocBlockTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstruct()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* This is a short description
|
||||||
|
*
|
||||||
|
* This is a long description
|
||||||
|
*
|
||||||
|
* @see \MyClass
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock(
|
||||||
|
$fixture,
|
||||||
|
new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')),
|
||||||
|
new Location(2)
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'This is a short description',
|
||||||
|
$object->getShortDescription()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'This is a long description',
|
||||||
|
$object->getLongDescription()->getContents()
|
||||||
|
);
|
||||||
|
$this->assertCount(2, $object->getTags());
|
||||||
|
$this->assertTrue($object->hasTag('see'));
|
||||||
|
$this->assertTrue($object->hasTag('return'));
|
||||||
|
$this->assertFalse($object->hasTag('category'));
|
||||||
|
|
||||||
|
$this->assertSame('MyNamespace', $object->getContext()->getNamespace());
|
||||||
|
$this->assertSame(
|
||||||
|
array('PHPDoc' => '\phpDocumentor'),
|
||||||
|
$object->getContext()->getNamespaceAliases()
|
||||||
|
);
|
||||||
|
$this->assertSame(2, $object->getLocation()->getLineNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::splitDocBlock
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructWithTagsOnly()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* @see \MyClass
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEquals('', $object->getShortDescription());
|
||||||
|
$this->assertEquals('', $object->getLongDescription()->getContents());
|
||||||
|
$this->assertCount(2, $object->getTags());
|
||||||
|
$this->assertTrue($object->hasTag('see'));
|
||||||
|
$this->assertTrue($object->hasTag('return'));
|
||||||
|
$this->assertFalse($object->hasTag('category'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::isTemplateStart
|
||||||
|
*/
|
||||||
|
public function testIfStartOfTemplateIsDiscovered()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**#@+
|
||||||
|
* @see \MyClass
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEquals('', $object->getShortDescription());
|
||||||
|
$this->assertEquals('', $object->getLongDescription()->getContents());
|
||||||
|
$this->assertCount(2, $object->getTags());
|
||||||
|
$this->assertTrue($object->hasTag('see'));
|
||||||
|
$this->assertTrue($object->hasTag('return'));
|
||||||
|
$this->assertFalse($object->hasTag('category'));
|
||||||
|
$this->assertTrue($object->isTemplateStart());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::isTemplateEnd
|
||||||
|
*/
|
||||||
|
public function testIfEndOfTemplateIsDiscovered()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**#@-*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEquals('', $object->getShortDescription());
|
||||||
|
$this->assertEquals('', $object->getLongDescription()->getContents());
|
||||||
|
$this->assertTrue($object->isTemplateEnd());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::cleanInput
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructOneLiner()
|
||||||
|
{
|
||||||
|
$fixture = '/** Short description and nothing more. */';
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEquals(
|
||||||
|
'Short description and nothing more.',
|
||||||
|
$object->getShortDescription()
|
||||||
|
);
|
||||||
|
$this->assertEquals('', $object->getLongDescription()->getContents());
|
||||||
|
$this->assertCount(0, $object->getTags());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::__construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConstructFromReflector()
|
||||||
|
{
|
||||||
|
$object = new DocBlock(new \ReflectionClass($this));
|
||||||
|
$this->assertEquals(
|
||||||
|
'Test class for Barryvdh\Reflection\DocBlock',
|
||||||
|
$object->getShortDescription()
|
||||||
|
);
|
||||||
|
$this->assertEquals('', $object->getLongDescription()->getContents());
|
||||||
|
$this->assertCount(4, $object->getTags());
|
||||||
|
$this->assertTrue($object->hasTag('author'));
|
||||||
|
$this->assertTrue($object->hasTag('copyright'));
|
||||||
|
$this->assertTrue($object->hasTag('license'));
|
||||||
|
$this->assertTrue($object->hasTag('link'));
|
||||||
|
$this->assertFalse($object->hasTag('category'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExceptionOnInvalidObject()
|
||||||
|
{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
new DocBlock($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDotSeperation()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* This is a short description.
|
||||||
|
* This is a long description.
|
||||||
|
* This is a continuation of the long description.
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEquals(
|
||||||
|
'This is a short description.',
|
||||||
|
$object->getShortDescription()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
"This is a long description.\nThis is a continuation of the long "
|
||||||
|
."description.",
|
||||||
|
$object->getLongDescription()->getContents()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::parseTags
|
||||||
|
* @expectedException \LogicException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testInvalidTagBlock()
|
||||||
|
{
|
||||||
|
if (!ini_get('allow_url_include')) {
|
||||||
|
$this->markTestSkipped('"data" URIs for includes are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'data:text/plain;base64,'. base64_encode(
|
||||||
|
<<<DOCBLOCK_EXTENSION
|
||||||
|
<?php
|
||||||
|
class MyReflectionDocBlock extends \Barryvdh\Reflection\DocBlock {
|
||||||
|
protected function splitDocBlock(\$comment) {
|
||||||
|
return array('', '', 'Invalid tag block');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DOCBLOCK_EXTENSION
|
||||||
|
);
|
||||||
|
new \MyReflectionDocBlock('');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTagCaseSensitivity()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* This is a short description.
|
||||||
|
*
|
||||||
|
* This is a long description.
|
||||||
|
*
|
||||||
|
* @method null something()
|
||||||
|
* @Method({"GET", "POST"})
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEquals(
|
||||||
|
'This is a short description.',
|
||||||
|
$object->getShortDescription()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'This is a long description.',
|
||||||
|
$object->getLongDescription()->getContents()
|
||||||
|
);
|
||||||
|
$tags = $object->getTags();
|
||||||
|
$this->assertCount(2, $tags);
|
||||||
|
$this->assertTrue($object->hasTag('method'));
|
||||||
|
$this->assertTrue($object->hasTag('Method'));
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\DocBlock\Tag\MethodTag',
|
||||||
|
$tags[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\DocBlock\Tag',
|
||||||
|
$tags[1]
|
||||||
|
);
|
||||||
|
$this->assertNotInstanceOf(
|
||||||
|
__NAMESPACE__ . '\DocBlock\Tag\MethodTag',
|
||||||
|
$tags[1]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testConstructFromReflector
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::getTagsByName
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetTagsByNameZeroAndOneMatch()
|
||||||
|
{
|
||||||
|
$object = new DocBlock(new \ReflectionClass($this));
|
||||||
|
$this->assertEmpty($object->getTagsByName('category'));
|
||||||
|
$this->assertCount(1, $object->getTagsByName('author'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testConstructWithTagsOnly
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::parseTags
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testParseMultilineTag()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* @return void Content on
|
||||||
|
* multiple lines.
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertCount(1, $object->getTags());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testConstructWithTagsOnly
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::parseTags
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testParseMultilineTagWithLineBreaks()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* @return void Content on
|
||||||
|
* multiple lines.
|
||||||
|
*
|
||||||
|
* One more, after the break.
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertCount(1, $tags = $object->getTags());
|
||||||
|
/** @var ReturnTag $tag */
|
||||||
|
$tag = reset($tags);
|
||||||
|
$this->assertEquals("Content on\n multiple lines.\n\n One more, after the break.", $tag->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testConstructWithTagsOnly
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::getTagsByName
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetTagsByNameMultipleMatch()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* @param string
|
||||||
|
* @param int
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertEmpty($object->getTagsByName('category'));
|
||||||
|
$this->assertCount(1, $object->getTagsByName('return'));
|
||||||
|
$this->assertCount(2, $object->getTagsByName('param'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Barryvdh\Reflection\DocBlock::parseTags
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGenericsAreParsed()
|
||||||
|
{
|
||||||
|
$fixture = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* @template TValue
|
||||||
|
* @param TValue
|
||||||
|
* @return TValue
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
$object = new DocBlock($fixture);
|
||||||
|
$this->assertSame(array('TValue'), $object->getGenerics());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor Covers Tag Test
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Covers
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class CoversTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\Covers can create a link
|
|
||||||
* for the covers doc block
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $content
|
|
||||||
* @param string $exName
|
|
||||||
* @param string $exContent
|
|
||||||
* @param string $exReference
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\Covers::__construct
|
|
||||||
* @dataProvider provideDataForConstuctor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstructorParesInputsIntoCorrectFields(
|
|
||||||
$type, $content, $exName, $exContent, $exDescription, $exReference
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$tag = new CoversTag($type, $content);
|
|
||||||
|
|
||||||
$actualName = $tag->getName();
|
|
||||||
$actualContent = $tag->getContent();
|
|
||||||
$actualDescription = $tag->getDescription();
|
|
||||||
$actualReference = $tag->getReference();
|
|
||||||
|
|
||||||
$this->assertEquals($exName, $actualName);
|
|
||||||
$this->assertEquals($exContent, $actualContent);
|
|
||||||
$this->assertEquals($exDescription, $actualDescription);
|
|
||||||
$this->assertEquals($exReference, $actualReference);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provideDataForConstuctor()
|
|
||||||
{
|
|
||||||
// $type, $content, $exName, $exContent, $exDescription, $exReference
|
|
||||||
return array(
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar()',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar()',
|
|
||||||
'',
|
|
||||||
'Foo::bar()'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing',
|
|
||||||
'Testing',
|
|
||||||
'Foo::bar()',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing comments',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing comments',
|
|
||||||
'Testing comments',
|
|
||||||
'Foo::bar()',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor Method Tag Test
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class MethodTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @dataProvider getTestSignatures
|
|
||||||
*
|
|
||||||
* @param string $signature The signature to test
|
|
||||||
* @param bool $valid Whether the given signature is expected to
|
|
||||||
* be valid.
|
|
||||||
* @param string $expected_name The method name that is expected from this
|
|
||||||
* signature
|
|
||||||
* @param string $expected_return The return type that is expected from this
|
|
||||||
* signature
|
|
||||||
* @param bool $has_params whether this signature features parameters.
|
|
||||||
* @param string $description The short description mentioned in the
|
|
||||||
* signature.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstruct($signature, $valid, $expected_name,
|
|
||||||
$expected_return, $has_params, $description)
|
|
||||||
{
|
|
||||||
ob_start();
|
|
||||||
$tag = new MethodTag('method', $signature);
|
|
||||||
$stdout = ob_get_clean();
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
$valid, empty($stdout),
|
|
||||||
'No error should have been output if the signature is valid'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$valid) return;
|
|
||||||
|
|
||||||
$this->assertEquals($expected_name, $tag->getMethodName());
|
|
||||||
$this->assertEquals($expected_return, $tag->getType());
|
|
||||||
$this->assertEquals($description, $tag->getDescription());
|
|
||||||
$this->assertSame(
|
|
||||||
$has_params, (bool)(count($tag->getArguments()) > 0),
|
|
||||||
'Number of found arguments should exceed 0'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTestSignatures()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(
|
|
||||||
'foo',
|
|
||||||
false, 'foo', '', false, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'foo()',
|
|
||||||
true, 'foo', 'void', false, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'foo() description',
|
|
||||||
true, 'foo', 'void', false, 'description'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo()',
|
|
||||||
true, 'foo', 'int', false, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo() description',
|
|
||||||
true, 'foo', 'int', false, 'description'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo($a, $b)',
|
|
||||||
true, 'foo', 'int', true, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo() foo(int $a, int $b)',
|
|
||||||
true, 'foo', 'int', true, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo(int $a, int $b)',
|
|
||||||
true, 'foo', 'int', true, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'null|int foo(int $a, int $b)',
|
|
||||||
true, 'foo', 'null|int', true, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo(null|int $a, int $b)',
|
|
||||||
true, 'foo', 'int', true, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'\Exception foo() foo(Exception $a, Exception $b)',
|
|
||||||
true, 'foo', '\Exception', true, ''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo() foo(Exception $a, Exception $b) description',
|
|
||||||
true, 'foo', 'int', true, 'description'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'int foo() foo(\Exception $a, \Exception $b) description',
|
|
||||||
true, 'foo', 'int', true, 'description'
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor Param tag test.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock_Param.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class ParamTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ParamTag can
|
|
||||||
* understand the param DocBlock.
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $content
|
|
||||||
* @param string $extracted_type
|
|
||||||
* @param string $extracted_variable_name
|
|
||||||
* @param string $extracted_description
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::__construct
|
|
||||||
*
|
|
||||||
* @dataProvider provideDataForConstructor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstructorParsesInputsIntoCorrectFields(
|
|
||||||
$type, $content, $extracted_type, $extracted_variable_name,
|
|
||||||
$extracted_description
|
|
||||||
) {
|
|
||||||
$tag = new ParamTag($type, $content);
|
|
||||||
|
|
||||||
$this->assertEquals($extracted_type, $tag->getTypes());
|
|
||||||
$this->assertEquals($extracted_variable_name, $tag->getVariableName());
|
|
||||||
$this->assertEquals($extracted_description, $tag->getDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provideDataForConstructor()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('param', 'int', array('int'), '', ''),
|
|
||||||
array('param', '$bob', array(), '$bob', ''),
|
|
||||||
array(
|
|
||||||
'param', 'int Number of bobs', array('int'), '',
|
|
||||||
'Number of bobs'
|
|
||||||
),
|
|
||||||
array('param', 'int $bob', array('int'), '$bob', ''),
|
|
||||||
array(
|
|
||||||
'param', 'int $bob Number of bobs', array('int'), '$bob',
|
|
||||||
'Number of bobs'
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor Return tag test.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock_ReturnTag.
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class ReturnTagTest extends ParamTagTest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can
|
|
||||||
* understand the Return DocBlock.
|
|
||||||
*
|
|
||||||
* @param string $content
|
|
||||||
* @param string $extracted_type
|
|
||||||
* @param string $extracted_description
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct
|
|
||||||
*
|
|
||||||
* @dataProvider provideDataForConstructor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstructorParsesInputsIntoCorrectFields(
|
|
||||||
$content, $extracted_type, $extracted_description
|
|
||||||
) {
|
|
||||||
$tag = new ReturnTag('return', $content);
|
|
||||||
|
|
||||||
$this->assertEquals($extracted_type, $tag->getTypes());
|
|
||||||
$this->assertEquals($extracted_description, $tag->getDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for testConstructorParsesInputsIntoCorrectFields()
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provideDataForConstructor()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('', array(), ''),
|
|
||||||
array('int', array('int'), ''),
|
|
||||||
array('int Number of Bobs', array('int'), 'Number of Bobs'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor See Tag Test
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_See
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class SeeTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
|
|
||||||
* for the @see doc block
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $content
|
|
||||||
* @param string $exName
|
|
||||||
* @param string $exContent
|
|
||||||
* @param string $exReference
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct
|
|
||||||
* @dataProvider provideDataForConstuctor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstructorParesInputsIntoCorrectFields(
|
|
||||||
$type, $content, $exName, $exContent, $exDescription, $exReference
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$tag = new SeeTag($type, $content);
|
|
||||||
|
|
||||||
$actualName = $tag->getName();
|
|
||||||
$actualContent = $tag->getContent();
|
|
||||||
$actualDescription = $tag->getDescription();
|
|
||||||
$actualReference = $tag->getReference();
|
|
||||||
|
|
||||||
$this->assertEquals($exName, $actualName);
|
|
||||||
$this->assertEquals($exContent, $actualContent);
|
|
||||||
$this->assertEquals($exDescription, $actualDescription);
|
|
||||||
$this->assertEquals($exReference, $actualReference);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provideDataForConstuctor()
|
|
||||||
{
|
|
||||||
// $type, $content, $exName, $exContent, $exDescription, $exReference
|
|
||||||
return array(
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar()',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar()',
|
|
||||||
'',
|
|
||||||
'Foo::bar()'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing',
|
|
||||||
'Testing',
|
|
||||||
'Foo::bar()',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing comments',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing comments',
|
|
||||||
'Testing comments',
|
|
||||||
'Foo::bar()',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor Uses Tag Test
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Uses
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class UsesTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\UsesTag can create
|
|
||||||
* a link for the @uses doc block
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $content
|
|
||||||
* @param string $exName
|
|
||||||
* @param string $exContent
|
|
||||||
* @param string $exReference
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct
|
|
||||||
* @dataProvider provideDataForConstuctor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstructorParesInputsIntoCorrectFields(
|
|
||||||
$type, $content, $exName, $exContent, $exDescription, $exReference
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$tag = new UsesTag($type, $content);
|
|
||||||
|
|
||||||
$actualName = $tag->getName();
|
|
||||||
$actualContent = $tag->getContent();
|
|
||||||
$actualDescription = $tag->getDescription();
|
|
||||||
$actualReference = $tag->getReference();
|
|
||||||
|
|
||||||
$this->assertEquals($exName, $actualName);
|
|
||||||
$this->assertEquals($exContent, $actualContent);
|
|
||||||
$this->assertEquals($exDescription, $actualDescription);
|
|
||||||
$this->assertEquals($exReference, $actualReference);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provideDataForConstuctor()
|
|
||||||
{
|
|
||||||
// $type, $content, $exName, $exContent, $exDescription, $exReference
|
|
||||||
return array(
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar()',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar()',
|
|
||||||
'',
|
|
||||||
'Foo::bar()'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing',
|
|
||||||
'Testing',
|
|
||||||
'Foo::bar()',
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing comments',
|
|
||||||
'uses',
|
|
||||||
'Foo::bar() Testing comments',
|
|
||||||
'Testing comments',
|
|
||||||
'Foo::bar()',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor Var Tag Test
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock_Tag_Link
|
|
||||||
*
|
|
||||||
* @author Daniel O'Connor <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class VarTagTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can understand
|
|
||||||
* the @var doc block
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $content
|
|
||||||
* @param string $exType
|
|
||||||
* @param string $exVariable
|
|
||||||
* @param string $exDescription
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\VarTag::__construct
|
|
||||||
* @dataProvider provideDataForConstuctor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testConstructorParesInputsIntoCorrectFields(
|
|
||||||
$type, $content, $exType, $exVariable, $exDescription
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$tag = new VarTag($type, $content);
|
|
||||||
|
|
||||||
$this->assertEquals($exType, $tag->getType());
|
|
||||||
$this->assertEquals($exVariable, $tag->getVariableName());
|
|
||||||
$this->assertEquals($exDescription, $tag->getDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function provideDataForConstuctor()
|
|
||||||
{
|
|
||||||
// $type, $content
|
|
||||||
return array(
|
|
||||||
array(
|
|
||||||
'var',
|
|
||||||
'int',
|
|
||||||
'int',
|
|
||||||
'',
|
|
||||||
''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'var',
|
|
||||||
'int $bob',
|
|
||||||
'int',
|
|
||||||
'$bob',
|
|
||||||
''
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'var',
|
|
||||||
'int $bob Number of bobs',
|
|
||||||
'int',
|
|
||||||
'$bob',
|
|
||||||
'Number of bobs'
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection
|
|
||||||
*/
|
|
||||||
class CollectionTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
|
|
||||||
*/
|
|
||||||
public function testConstruct()
|
|
||||||
{
|
|
||||||
$collection = new Collection();
|
|
||||||
$this->assertCount(0, $collection);
|
|
||||||
$this->assertEquals('\\', $collection->getNamespace());
|
|
||||||
$this->assertCount(0, $collection->getNamespaceAliases());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
|
||||||
*/
|
|
||||||
public function testConstructWithTypes()
|
|
||||||
{
|
|
||||||
$collection = new Collection(array('integer', 'string'));
|
|
||||||
$this->assertCount(2, $collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
|
|
||||||
*/
|
|
||||||
public function testConstructWithNamespace()
|
|
||||||
{
|
|
||||||
$collection = new Collection(array(), '\My\Space');
|
|
||||||
$this->assertEquals('\My\Space\\', $collection->getNamespace());
|
|
||||||
|
|
||||||
$collection = new Collection(array(), 'My\Space');
|
|
||||||
$this->assertEquals('\My\Space\\', $collection->getNamespace());
|
|
||||||
|
|
||||||
$collection = new Collection(array(), null);
|
|
||||||
$this->assertEquals('\\', $collection->getNamespace());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
|
|
||||||
*/
|
|
||||||
public function testConstructWithNamespaceAliases()
|
|
||||||
{
|
|
||||||
$fixture = array('a' => 'b');
|
|
||||||
$collection = new Collection(array(), null, $fixture);
|
|
||||||
$this->assertEquals($fixture, $collection->getNamespaceAliases());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::setNamespace
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace
|
|
||||||
*/
|
|
||||||
public function testSetAndGetNamespace()
|
|
||||||
{
|
|
||||||
$collection = new Collection();
|
|
||||||
$this->assertEquals('\\', $collection->getNamespace());
|
|
||||||
|
|
||||||
$collection->setNamespace('My');
|
|
||||||
$this->assertEquals('\My\\', $collection->getNamespace());
|
|
||||||
|
|
||||||
$collection->setNamespace('\My');
|
|
||||||
$this->assertEquals('\My\\', $collection->getNamespace());
|
|
||||||
|
|
||||||
$collection->setNamespace('\My\\');
|
|
||||||
$this->assertEquals('\My\\', $collection->getNamespace());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::setNamespaceAliases
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases
|
|
||||||
*/
|
|
||||||
public function testSetAndGetNamespaceAliases()
|
|
||||||
{
|
|
||||||
$collection = new Collection();
|
|
||||||
$this->assertEmpty($collection->getNamespaceAliases());
|
|
||||||
|
|
||||||
$collection->setNamespaceAliases(array('My'));
|
|
||||||
$this->assertEquals(array('My'), $collection->getNamespaceAliases());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $fixture
|
|
||||||
* @param $expected
|
|
||||||
*
|
|
||||||
* @dataProvider provideTypesToExpand
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
|
|
||||||
*/
|
|
||||||
public function testAdd($fixture, $expected)
|
|
||||||
{
|
|
||||||
$collection = new Collection();
|
|
||||||
$collection->setNamespace('\My\Space');
|
|
||||||
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
|
|
||||||
$collection->add($fixture);
|
|
||||||
|
|
||||||
$this->assertSame($expected, $collection->getArrayCopy());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $fixture
|
|
||||||
* @param $expected
|
|
||||||
*
|
|
||||||
* @dataProvider provideTypesToExpandWithoutNamespace
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
|
|
||||||
*/
|
|
||||||
public function testAddWithoutNamespace($fixture, $expected)
|
|
||||||
{
|
|
||||||
$collection = new Collection();
|
|
||||||
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
|
|
||||||
$collection->add($fixture);
|
|
||||||
|
|
||||||
$this->assertSame($expected, $collection->getArrayCopy());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add
|
|
||||||
* @expectedException InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function testAddWithInvalidArgument()
|
|
||||||
{
|
|
||||||
$collection = new Collection();
|
|
||||||
$collection->add(array());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the types and their expected values to test the retrieval of
|
|
||||||
* types.
|
|
||||||
*
|
|
||||||
* @param string $method Name of the method consuming this data provider.
|
|
||||||
* @param string $namespace Name of the namespace to user as basis.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public function provideTypesToExpand($method, $namespace = '\My\Space\\')
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('', array()),
|
|
||||||
array(' ', array()),
|
|
||||||
array('int', array('int')),
|
|
||||||
array('int ', array('int')),
|
|
||||||
array('string', array('string')),
|
|
||||||
array('DocBlock', array($namespace.'DocBlock')),
|
|
||||||
array('DocBlock[]', array($namespace.'DocBlock[]')),
|
|
||||||
array(' DocBlock ', array($namespace.'DocBlock')),
|
|
||||||
array('\My\Space\DocBlock', array('\My\Space\DocBlock')),
|
|
||||||
array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')),
|
|
||||||
array(
|
|
||||||
'DocBlock|Tag',
|
|
||||||
array($namespace .'DocBlock', $namespace .'Tag')
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'DocBlock|null',
|
|
||||||
array($namespace.'DocBlock', 'null')
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'\My\Space\DocBlock|Tag',
|
|
||||||
array('\My\Space\DocBlock', $namespace.'Tag')
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'DocBlock[]|null',
|
|
||||||
array($namespace.'DocBlock[]', 'null')
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'DocBlock[]|int[]',
|
|
||||||
array($namespace.'DocBlock[]', 'int[]')
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the types and their expected values to test the retrieval of
|
|
||||||
* types when no namespace is available.
|
|
||||||
*
|
|
||||||
* @param string $method Name of the method consuming this data provider.
|
|
||||||
* @param string $namespace Name of the namespace to user as basis.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public function provideTypesToExpandWithoutNamespace($method)
|
|
||||||
{
|
|
||||||
return $this->provideTypesToExpand($method, '\\');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* phpDocumentor DocBlock Test
|
|
||||||
*
|
|
||||||
* PHP Version 5
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace phpDocumentor\Reflection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for phpDocumentor_Reflection_DocBlock
|
|
||||||
*
|
|
||||||
* @author Mike van Riel <[email protected]>
|
|
||||||
* @copyright Copyright (c) 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
|
||||||
*/
|
|
||||||
class DocBlockTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
public function testConstruct()
|
|
||||||
{
|
|
||||||
$fixture = <<<DOCBLOCK
|
|
||||||
/**
|
|
||||||
* This is a short description.
|
|
||||||
*
|
|
||||||
* This is a long description.
|
|
||||||
*
|
|
||||||
* @see \MyClass
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
DOCBLOCK;
|
|
||||||
$object = new DocBlock($fixture);
|
|
||||||
$this->assertEquals(
|
|
||||||
'This is a short description.', $object->getShortDescription()
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
'This is a long description.',
|
|
||||||
$object->getLongDescription()->getContents()
|
|
||||||
);
|
|
||||||
$this->assertEquals(2, count($object->getTags()));
|
|
||||||
$this->assertTrue($object->hasTag('see'));
|
|
||||||
$this->assertTrue($object->hasTag('return'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDotSeperation()
|
|
||||||
{
|
|
||||||
$fixture = <<<DOCBLOCK
|
|
||||||
/**
|
|
||||||
* This is a short description. This is a long description.
|
|
||||||
* This is a continuation of the long description.
|
|
||||||
*/
|
|
||||||
DOCBLOCK;
|
|
||||||
$object = new DocBlock($fixture);
|
|
||||||
$this->assertEquals(
|
|
||||||
'This is a short description.', $object->getShortDescription()
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
"This is a long description.\nThis is a continuation of the long "
|
|
||||||
."description.", $object->getLongDescription()->getContents()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether a type is expanded with the given namespace and that a
|
|
||||||
* keyword is not expanded.
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock::expandType()
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testExpandTypeUsingNamespace()
|
|
||||||
{
|
|
||||||
$docblock = new DocBlock('', '\My\Namespace');
|
|
||||||
$this->assertEquals('\My\Namespace\Mine', $docblock->expandType('Mine'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether a type is expanded when no namespace is given.
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock::expandType()
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testExpandTypeWithoutNamespace()
|
|
||||||
{
|
|
||||||
$docblock = new DocBlock('');
|
|
||||||
$this->assertEquals('\Mine', $docblock->expandType('Mine'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether a type is expanded with the given namespace when an alias
|
|
||||||
* is provided.
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock::expandType()
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testExpandTypeUsingNamespaceAlias()
|
|
||||||
{
|
|
||||||
$docblock = new DocBlock(
|
|
||||||
'', '\My\Namespace', array('Alias' => '\My\Namespace\Alias')
|
|
||||||
);
|
|
||||||
|
|
||||||
// first try a normal resolution without alias
|
|
||||||
$this->assertEquals(
|
|
||||||
'\My\Namespace\Al', $docblock->expandType('Al')
|
|
||||||
);
|
|
||||||
|
|
||||||
// try to use the alias
|
|
||||||
$this->assertEquals(
|
|
||||||
'\My\Namespace\Alias\Al', $docblock->expandType('Alias\Al')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether the keywords that should not be converted are not converted.
|
|
||||||
*
|
|
||||||
* @param string $keyword The keyword that is to be tested; this is provided
|
|
||||||
* by the dataprovider.
|
|
||||||
*
|
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock::expandType()
|
|
||||||
*
|
|
||||||
* @dataProvider getNonExpandableKeywordsForExpandType
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testThatExpandTypeDoesNotExpandAllKeywords($keyword)
|
|
||||||
{
|
|
||||||
$docblock = new DocBlock('', '\My\Namespace');
|
|
||||||
$this->assertEquals($keyword, $docblock->expandType($keyword));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNonExpandableKeywordsForExpandType()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('string'), array('int'), array('integer'), array('bool'),
|
|
||||||
array('boolean'), array('float'), array('double'), array('object'),
|
|
||||||
array('mixed'), array('array'), array('resource'), array('void'),
|
|
||||||
array('null'), array('callback'), array('false'), array('true')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user