updated backend
This commit is contained in:
parent
1fea0f4fe7
commit
11521c2339
3459 changed files with 72735 additions and 168535 deletions
|
|
@ -10,16 +10,12 @@ that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest
|
|||
With this component, a library can provide support for annotations via DocBlocks
|
||||
or otherwise retrieve information that is embedded in a DocBlock.
|
||||
|
||||
> **Note**: *this is a core component of phpDocumentor and is constantly being
|
||||
> optimized for performance.*
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
You can install the component in the following ways:
|
||||
|
||||
* Use the official Github repository (https://github.com/phpDocumentor/ReflectionDocBlock)
|
||||
* Via Composer (http://packagist.org/packages/phpdocumentor/reflection-docblock)
|
||||
```bash
|
||||
composer require phpdocumentor/reflection-docblock
|
||||
```
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
|
@ -52,18 +48,20 @@ $docblock = $factory->create($docComment);
|
|||
```
|
||||
|
||||
The `create` method will yield an object of type `\phpDocumentor\Reflection\DocBlock`
|
||||
whose methods can be queried as shown in the following example.
|
||||
whose methods can be queried:
|
||||
|
||||
```php
|
||||
// Should contain the summary for this DocBlock
|
||||
// Contains the summary for this DocBlock
|
||||
$summary = $docblock->getSummary();
|
||||
|
||||
// Contains an object of type \phpDocumentor\Reflection\DocBlock\Description;
|
||||
// you can either cast it to string or use the render method to get a string
|
||||
// representation of the Description.
|
||||
// Contains \phpDocumentor\Reflection\DocBlock\Description object
|
||||
$description = $docblock->getDescription();
|
||||
|
||||
// You can either cast it to string
|
||||
$description = (string) $docblock->getDescription();
|
||||
|
||||
// Or use the render method to get a string representation of the Description.
|
||||
$description = $docblock->getDescription()->render();
|
||||
```
|
||||
|
||||
> For more examples it would be best to review the scripts in the `/examples`
|
||||
> folder.
|
||||
|
||||
> For more examples it would be best to review the scripts in the [`/examples` folder](/examples).
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.6 || ^7.0",
|
||||
"phpdocumentor/reflection-common": "^1.0.0",
|
||||
"phpdocumentor/type-resolver": "^0.4.0",
|
||||
"php": "^7.0",
|
||||
"phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0",
|
||||
"phpdocumentor/type-resolver": "~0.4 || ^1.0.0",
|
||||
"webmozart/assert": "^1.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
|
@ -22,7 +22,14 @@
|
|||
"psr-4": {"phpDocumentor\\Reflection\\": ["tests/unit"]}
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^0.9.4",
|
||||
"phpunit/phpunit": "^4.4"
|
||||
"mockery/mockery": "^1.0",
|
||||
"phpdocumentor/type-resolver": "0.4.*",
|
||||
"phpunit/phpunit": "^6.4",
|
||||
"doctrine/instantiator": "^1.0.5"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ final class DocBlock
|
|||
private $description = null;
|
||||
|
||||
/** @var Tag[] An array containing all the tags in this docblock; except inline. */
|
||||
private $tags = array();
|
||||
private $tags = [];
|
||||
|
||||
/** @var Types\Context Information about the context of this DocBlock. */
|
||||
private $context = null;
|
||||
|
|
@ -55,8 +55,7 @@ final class DocBlock
|
|||
Location $location = null,
|
||||
$isTemplateStart = false,
|
||||
$isTemplateEnd = false
|
||||
)
|
||||
{
|
||||
) {
|
||||
Assert::string($summary);
|
||||
Assert::boolean($isTemplateStart);
|
||||
Assert::boolean($isTemplateEnd);
|
||||
|
|
@ -171,11 +170,11 @@ final class DocBlock
|
|||
{
|
||||
Assert::string($name);
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($this->getTags() as $tag) {
|
||||
if ($tag->getName() != $name) {
|
||||
if ($tag->getName() !== $name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +197,7 @@ final class DocBlock
|
|||
|
||||
/** @var Tag $tag */
|
||||
foreach ($this->getTags() as $tag) {
|
||||
if ($tag->getName() == $name) {
|
||||
if ($tag->getName() === $name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -206,6 +205,23 @@ final class DocBlock
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a tag from this DocBlock.
|
||||
*
|
||||
* @param Tag $tag The tag to remove.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeTag(Tag $tagToRemove)
|
||||
{
|
||||
foreach ($this->tags as $key => $tag) {
|
||||
if ($tag === $tagToRemove) {
|
||||
unset($this->tags[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tag to this DocBlock.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class Description
|
|||
$this->bodyTemplate = $bodyTemplate;
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the tags for this DocBlock.
|
||||
*
|
||||
|
|
@ -98,6 +98,7 @@ class Description
|
|||
foreach ($this->tags as $tag) {
|
||||
$tags[] = '{' . $formatter->format($tag) . '}';
|
||||
}
|
||||
|
||||
return vsprintf($this->bodyTemplate, $tags);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,5 +188,4 @@ class DescriptionFactory
|
|||
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class ExampleFinder
|
|||
private $sourceDirectory = '';
|
||||
|
||||
/** @var string[] */
|
||||
private $exampleDirectories = array();
|
||||
private $exampleDirectories = [];
|
||||
|
||||
/**
|
||||
* Attempts to find the example contents for the given descriptor.
|
||||
|
|
|
|||
|
|
@ -81,7 +81,12 @@ class Serializer
|
|||
)
|
||||
);
|
||||
|
||||
$comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n";
|
||||
$comment = "{$firstIndent}/**\n";
|
||||
if ($text) {
|
||||
$comment .= "{$indent} * {$text}\n";
|
||||
$comment .= "{$indent} *\n";
|
||||
}
|
||||
|
||||
$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
|
||||
$comment .= $indent . ' */';
|
||||
|
||||
|
|
@ -121,6 +126,7 @@ class Serializer
|
|||
$text = wordwrap($text, $wrapLength);
|
||||
return $text;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
|
@ -138,6 +144,7 @@ class Serializer
|
|||
if ($wrapLength !== null) {
|
||||
$tagText = wordwrap($tagText, $wrapLength);
|
||||
}
|
||||
|
||||
$tagText = str_replace("\n", "\n{$indent} * ", $tagText);
|
||||
|
||||
$comment .= "{$indent} * {$tagText}\n";
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ final class StandardTagFactory implements TagFactory
|
|||
*/
|
||||
private function extractTagParts($tagLine)
|
||||
{
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
|
||||
|
|
@ -196,8 +196,7 @@ final class StandardTagFactory implements TagFactory
|
|||
$arguments = $this->getArgumentsForParametersFromWiring(
|
||||
$this->fetchParametersForHandlerFactoryMethod($handlerClassName),
|
||||
$this->getServiceLocatorWithDynamicParameters($context, $name, $body)
|
||||
)
|
||||
;
|
||||
);
|
||||
|
||||
return call_user_func_array([$handlerClassName, 'create'], $arguments);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of phpDocumentor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -49,8 +49,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
|
|||
DescriptionFactory $descriptionFactory = null,
|
||||
FqsenResolver $resolver = null,
|
||||
TypeContext $context = null
|
||||
)
|
||||
{
|
||||
) {
|
||||
Assert::string($body);
|
||||
Assert::notEmpty($body);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}example tag in a Docblock.
|
||||
*/
|
||||
final class Example extends BaseTag
|
||||
final class Example extends BaseTag implements Factory\StaticMethod
|
||||
{
|
||||
/**
|
||||
* @var string Path to a file to use as an example. May also be an absolute URI.
|
||||
|
|
@ -33,12 +33,12 @@ final class Example extends BaseTag
|
|||
private $isURI = false;
|
||||
|
||||
/**
|
||||
* @var
|
||||
* @var int
|
||||
*/
|
||||
private $startingLine;
|
||||
|
||||
/**
|
||||
* @var
|
||||
* @var int
|
||||
*/
|
||||
private $lineCount;
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Generic extends BaseTag implements Factory\StaticMethod
|
|||
Assert::stringNotEmpty($name);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
$description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null;
|
||||
$description = $descriptionFactory && $body !== "" ? $descriptionFactory->create($body, $context) : null;
|
||||
|
||||
return new static($name, $description);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,12 +102,8 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||
)
|
||||
\s+
|
||||
)?
|
||||
# Legacy method name (not captured)
|
||||
(?:
|
||||
[\w_]+\(\)\s+
|
||||
)?
|
||||
# Method name
|
||||
([\w\|_\\\\]+)
|
||||
([\w_]+)
|
||||
# Arguments
|
||||
(?:
|
||||
\(([^\)]*)\)
|
||||
|
|
@ -135,7 +131,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||
|
||||
if (is_string($arguments) && strlen($arguments) > 0) {
|
||||
$arguments = explode(',', $arguments);
|
||||
foreach($arguments as &$argument) {
|
||||
foreach ($arguments as &$argument) {
|
||||
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
|
||||
if ($argument[0][0] === '$') {
|
||||
$argumentName = substr($argument[0], 1);
|
||||
|
|
@ -214,10 +210,13 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||
if (is_string($argument)) {
|
||||
$argument = [ 'name' => $argument ];
|
||||
}
|
||||
|
||||
if (! isset($argument['type'])) {
|
||||
$argument['type'] = new Void_();
|
||||
}
|
||||
|
||||
$keys = array_keys($argument);
|
||||
sort($keys);
|
||||
if ($keys !== [ 'name', 'type' ]) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true)
|
||||
|
|
|
|||
|
|
@ -22,14 +22,8 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for the {@}param tag in a Docblock.
|
||||
*/
|
||||
final class Param extends BaseTag implements Factory\StaticMethod
|
||||
final class Param extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'param';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
private $variableName = '';
|
||||
|
||||
|
|
@ -47,6 +41,7 @@ final class Param extends BaseTag implements Factory\StaticMethod
|
|||
Assert::string($variableName);
|
||||
Assert::boolean($isVariadic);
|
||||
|
||||
$this->name = 'param';
|
||||
$this->variableName = $variableName;
|
||||
$this->type = $type;
|
||||
$this->isVariadic = $isVariadic;
|
||||
|
|
@ -65,19 +60,25 @@ final class Param extends BaseTag implements Factory\StaticMethod
|
|||
Assert::stringNotEmpty($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
$isVariadic = false;
|
||||
|
||||
// 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] !== '$')) {
|
||||
$type = $typeResolver->resolve(array_shift($parts), $context);
|
||||
array_shift($parts);
|
||||
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
|
||||
$type = $typeResolver->resolve($firstPart, $context);
|
||||
} else {
|
||||
// first part is not a type; we should prepend it to the parts array for further processing
|
||||
array_unshift($parts, $firstPart);
|
||||
}
|
||||
|
||||
// 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) === '...$')) {
|
||||
if (isset($parts[0])
|
||||
&& (strlen($parts[0]) > 0)
|
||||
&& ($parts[0][0] === '$' || substr($parts[0], 0, 4) === '...$')
|
||||
) {
|
||||
$variableName = array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
|
|
@ -106,16 +107,6 @@ final class Param extends BaseTag implements Factory\StaticMethod
|
|||
return $this->variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable's type or null if unknown.
|
||||
*
|
||||
* @return Type|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this tag is variadic.
|
||||
*
|
||||
|
|
@ -134,8 +125,8 @@ final class Param extends BaseTag implements Factory\StaticMethod
|
|||
public function __toString()
|
||||
{
|
||||
return ($this->type ? $this->type . ' ' : '')
|
||||
. ($this->isVariadic() ? '...' : '')
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
. ($this->isVariadic() ? '...' : '')
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,26 +22,21 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}property tag in a Docblock.
|
||||
*/
|
||||
class Property extends BaseTag implements Factory\StaticMethod
|
||||
class Property extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'property';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
protected $variableName = '';
|
||||
|
||||
/**
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param Description $description
|
||||
*/
|
||||
public function __construct($variableName, Type $type = null, Description $description = null)
|
||||
{
|
||||
Assert::string($variableName);
|
||||
|
||||
$this->name = 'property';
|
||||
$this->variableName = $variableName;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
|
|
@ -59,18 +54,21 @@ class Property extends BaseTag implements Factory\StaticMethod
|
|||
Assert::stringNotEmpty($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
// 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] !== '$')) {
|
||||
$type = $typeResolver->resolve(array_shift($parts), $context);
|
||||
array_shift($parts);
|
||||
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
|
||||
$type = $typeResolver->resolve($firstPart, $context);
|
||||
} else {
|
||||
// first part is not a type; we should prepend it to the parts array for further processing
|
||||
array_unshift($parts, $firstPart);
|
||||
}
|
||||
|
||||
// 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] == '$')) {
|
||||
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) {
|
||||
$variableName = array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
|
|
@ -94,16 +92,6 @@ class Property extends BaseTag implements Factory\StaticMethod
|
|||
return $this->variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable's type or null if unknown.
|
||||
*
|
||||
* @return Type|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for this tag.
|
||||
*
|
||||
|
|
@ -112,7 +100,7 @@ class Property extends BaseTag implements Factory\StaticMethod
|
|||
public function __toString()
|
||||
{
|
||||
return ($this->type ? $this->type . ' ' : '')
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,26 +22,21 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}property-read tag in a Docblock.
|
||||
*/
|
||||
class PropertyRead extends BaseTag implements Factory\StaticMethod
|
||||
class PropertyRead extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'property-read';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
protected $variableName = '';
|
||||
|
||||
/**
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param Description $description
|
||||
*/
|
||||
public function __construct($variableName, Type $type = null, Description $description = null)
|
||||
{
|
||||
Assert::string($variableName);
|
||||
|
||||
$this->name = 'property-read';
|
||||
$this->variableName = $variableName;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
|
|
@ -59,18 +54,21 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
|
|||
Assert::stringNotEmpty($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
// 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] !== '$')) {
|
||||
$type = $typeResolver->resolve(array_shift($parts), $context);
|
||||
array_shift($parts);
|
||||
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
|
||||
$type = $typeResolver->resolve($firstPart, $context);
|
||||
} else {
|
||||
// first part is not a type; we should prepend it to the parts array for further processing
|
||||
array_unshift($parts, $firstPart);
|
||||
}
|
||||
|
||||
// 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] == '$')) {
|
||||
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) {
|
||||
$variableName = array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
|
|
@ -94,16 +92,6 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
|
|||
return $this->variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable's type or null if unknown.
|
||||
*
|
||||
* @return Type|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for this tag.
|
||||
*
|
||||
|
|
@ -112,7 +100,7 @@ class PropertyRead extends BaseTag implements Factory\StaticMethod
|
|||
public function __toString()
|
||||
{
|
||||
return ($this->type ? $this->type . ' ' : '')
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,26 +22,21 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}property-write tag in a Docblock.
|
||||
*/
|
||||
class PropertyWrite extends BaseTag implements Factory\StaticMethod
|
||||
class PropertyWrite extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'property-write';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
protected $variableName = '';
|
||||
|
||||
/**
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param Description $description
|
||||
*/
|
||||
public function __construct($variableName, Type $type = null, Description $description = null)
|
||||
{
|
||||
Assert::string($variableName);
|
||||
|
||||
$this->name = 'property-write';
|
||||
$this->variableName = $variableName;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
|
|
@ -59,18 +54,21 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
|
|||
Assert::stringNotEmpty($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
// 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] !== '$')) {
|
||||
$type = $typeResolver->resolve(array_shift($parts), $context);
|
||||
array_shift($parts);
|
||||
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
|
||||
$type = $typeResolver->resolve($firstPart, $context);
|
||||
} else {
|
||||
// first part is not a type; we should prepend it to the parts array for further processing
|
||||
array_unshift($parts, $firstPart);
|
||||
}
|
||||
|
||||
// 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] == '$')) {
|
||||
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) {
|
||||
$variableName = array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
|
|
@ -94,16 +92,6 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
|
|||
return $this->variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable's type or null if unknown.
|
||||
*
|
||||
* @return Type|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for this tag.
|
||||
*
|
||||
|
|
@ -112,7 +100,7 @@ class PropertyWrite extends BaseTag implements Factory\StaticMethod
|
|||
public function __toString()
|
||||
{
|
||||
return ($this->type ? $this->type . ' ' : '')
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
. '$' . $this->variableName
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,11 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}return tag in a Docblock.
|
||||
*/
|
||||
final class Return_ extends BaseTag implements Factory\StaticMethod
|
||||
final class Return_ extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
protected $name = 'return';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
public function __construct(Type $type, Description $description = null)
|
||||
{
|
||||
$this->name = 'return';
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
|
@ -43,29 +39,18 @@ final class Return_ extends BaseTag implements Factory\StaticMethod
|
|||
TypeResolver $typeResolver = null,
|
||||
DescriptionFactory $descriptionFactory = null,
|
||||
TypeContext $context = null
|
||||
)
|
||||
{
|
||||
) {
|
||||
Assert::string($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/\s+/Su', $body, 2);
|
||||
list($type, $description) = self::extractTypeFromBody($body);
|
||||
|
||||
$type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context);
|
||||
$description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context);
|
||||
$type = $typeResolver->resolve($type, $context);
|
||||
$description = $descriptionFactory->create($description, $context);
|
||||
|
||||
return new static($type, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type section of the variable.
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->type . ' ' . $this->description;
|
||||
|
|
|
|||
|
|
@ -12,14 +12,13 @@
|
|||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Reference;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ final class Source extends BaseTag implements Factory\StaticMethod
|
|||
if (isset($matches[2]) && $matches[2] !== '') {
|
||||
$lineCount = (int)$matches[2];
|
||||
}
|
||||
|
||||
$description = $matches[3];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,16 +22,12 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}throws tag in a Docblock.
|
||||
*/
|
||||
final class Throws extends BaseTag implements Factory\StaticMethod
|
||||
final class Throws extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
protected $name = 'throws';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
public function __construct(Type $type, Description $description = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->name = 'throws';
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
|
|
@ -47,24 +43,14 @@ final class Throws extends BaseTag implements Factory\StaticMethod
|
|||
Assert::string($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/\s+/Su', $body, 2);
|
||||
list($type, $description) = self::extractTypeFromBody($body);
|
||||
|
||||
$type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context);
|
||||
$description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context);
|
||||
$type = $typeResolver->resolve($type, $context);
|
||||
$description = $descriptionFactory->create($description, $context);
|
||||
|
||||
return new static($type, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type section of the variable.
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->type . ' ' . $this->description;
|
||||
|
|
|
|||
|
|
@ -22,29 +22,24 @@ use Webmozart\Assert\Assert;
|
|||
/**
|
||||
* Reflection class for a {@}var tag in a Docblock.
|
||||
*/
|
||||
class Var_ extends BaseTag implements Factory\StaticMethod
|
||||
class Var_ extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'var';
|
||||
|
||||
/** @var Type */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
protected $variableName = '';
|
||||
|
||||
/**
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param string $variableName
|
||||
* @param Type $type
|
||||
* @param Description $description
|
||||
*/
|
||||
public function __construct($variableName, Type $type = null, Description $description = null)
|
||||
{
|
||||
Assert::string($variableName);
|
||||
|
||||
$this->name = 'var';
|
||||
$this->variableName = $variableName;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,18 +54,21 @@ class Var_ extends BaseTag implements Factory\StaticMethod
|
|||
Assert::stringNotEmpty($body);
|
||||
Assert::allNotNull([$typeResolver, $descriptionFactory]);
|
||||
|
||||
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$type = null;
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$type = null;
|
||||
$variableName = '';
|
||||
|
||||
// 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] !== '$')) {
|
||||
$type = $typeResolver->resolve(array_shift($parts), $context);
|
||||
array_shift($parts);
|
||||
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
|
||||
$type = $typeResolver->resolve($firstPart, $context);
|
||||
} else {
|
||||
// first part is not a type; we should prepend it to the parts array for further processing
|
||||
array_unshift($parts, $firstPart);
|
||||
}
|
||||
|
||||
// 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] == '$')) {
|
||||
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) {
|
||||
$variableName = array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
|
|
@ -94,16 +92,6 @@ class Var_ extends BaseTag implements Factory\StaticMethod
|
|||
return $this->variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the variable's type or null if unknown.
|
||||
*
|
||||
* @return Type|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for this tag.
|
||||
*
|
||||
|
|
@ -111,8 +99,8 @@ class Var_ extends BaseTag implements Factory\StaticMethod
|
|||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return ($this->type ? $this->type.' ' : '')
|
||||
.(empty($this->variableName) ? null : ('$'.$this->variableName))
|
||||
.($this->description ? ' '.$this->description : '');
|
||||
return ($this->type ? $this->type . ' ' : '')
|
||||
. (empty($this->variableName) ? null : ('$' . $this->variableName))
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||
return new DocBlock(
|
||||
$summary,
|
||||
$description ? $this->descriptionFactory->create($description, $context) : null,
|
||||
array_filter($this->parseTagBlock($tags, $context), function($tag) {
|
||||
array_filter($this->parseTagBlock($tags, $context), function ($tag) {
|
||||
return $tag instanceof Tag;
|
||||
}),
|
||||
$context,
|
||||
|
|
@ -120,11 +120,11 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||
$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) == '*/') {
|
||||
if (substr($comment, -2) === '*/') {
|
||||
$comment = trim(substr($comment, 0, -2));
|
||||
}
|
||||
|
||||
return str_replace(array("\r\n", "\r"), "\n", $comment);
|
||||
return str_replace(["\r\n", "\r"], "\n", $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,7 +143,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||
// 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);
|
||||
return ['', '', '', $comment];
|
||||
}
|
||||
|
||||
// clears all extra horizontal whitespace from the line endings to prevent parsing issues
|
||||
|
|
@ -241,7 +241,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||
*/
|
||||
private function splitTagBlockIntoTagLines($tags)
|
||||
{
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach (explode("\n", $tags) as $tag_line) {
|
||||
if (isset($tag_line[0]) && ($tag_line[0] === '@')) {
|
||||
$result[] = $tag_line;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue