updated backend
This commit is contained in:
parent
1fea0f4fe7
commit
11521c2339
3459 changed files with 72735 additions and 168535 deletions
|
|
@ -1,2 +1,12 @@
|
|||
# ReflectionCommon
|
||||
[](https://travis-ci.org/phpDocumentor/ReflectionCommon)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://travis-ci.org/phpDocumentor/ReflectionCommon)
|
||||
[](https://ci.appveyor.com/project/phpDocumentor/ReflectionCommon/branch/master)
|
||||
[](https://coveralls.io/github/phpDocumentor/ReflectionCommon?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionCommon/?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionCommon/?branch=master)
|
||||
[](https://packagist.org/packages/phpDocumentor/Reflection-Common)
|
||||
[](https://packagist.org/packages/phpDocumentor/Reflection-Common)
|
||||
|
||||
|
||||
ReflectionCommon
|
||||
================
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5"
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"autoload" : {
|
||||
"psr-4" : {
|
||||
"phpDocumentor\\Reflection\\": ["src"]
|
||||
"phpDocumentor\\Reflection\\": "src/"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.6"
|
||||
"phpunit/phpunit": "~6"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
"dev-master": "2.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5.5
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
|
@ -18,15 +21,11 @@ interface Element
|
|||
{
|
||||
/**
|
||||
* Returns the Fqsen of the element.
|
||||
*
|
||||
* @return Fqsen
|
||||
*/
|
||||
public function getFqsen();
|
||||
public function getFqsen(): Fqsen;
|
||||
|
||||
/**
|
||||
* Returns the name of the element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
}
|
||||
public function getName(): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
|
@ -19,22 +21,16 @@ interface File
|
|||
{
|
||||
/**
|
||||
* Returns the content of the file as a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContents();
|
||||
public function getContents(): string;
|
||||
|
||||
/**
|
||||
* Returns md5 hash of the file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function md5();
|
||||
public function md5(): string;
|
||||
|
||||
/**
|
||||
* Returns an relative path to the file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function path();
|
||||
public function path(): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,21 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5.5
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @copyright 2010-2018 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;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Value Object for Fqsen.
|
||||
*
|
||||
|
|
@ -31,21 +36,19 @@ final class Fqsen
|
|||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param string $fqsen
|
||||
*
|
||||
* @throws \InvalidArgumentException when $fqsen is not matching the format.
|
||||
* @throws InvalidArgumentException when $fqsen is not matching the format.
|
||||
*/
|
||||
public function __construct($fqsen)
|
||||
public function __construct(string $fqsen)
|
||||
{
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
$result = preg_match(
|
||||
'/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/',
|
||||
$fqsen,
|
||||
$matches
|
||||
$fqsen,
|
||||
$matches
|
||||
);
|
||||
|
||||
if ($result === 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('"%s" is not a valid Fqsen.', $fqsen)
|
||||
);
|
||||
}
|
||||
|
|
@ -62,20 +65,16 @@ final class Fqsen
|
|||
|
||||
/**
|
||||
* converts this class to string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->fqsen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the element without path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
|
@ -17,7 +19,7 @@ namespace phpDocumentor\Reflection;
|
|||
*/
|
||||
final class Location
|
||||
{
|
||||
/** @var int */
|
||||
/** @var int */
|
||||
private $lineNumber = 0;
|
||||
|
||||
/** @var int */
|
||||
|
|
@ -25,32 +27,25 @@ final class Location
|
|||
|
||||
/**
|
||||
* Initializes the location for an element using its line number in the file and optionally the column number.
|
||||
*
|
||||
* @param int $lineNumber
|
||||
* @param int $columnNumber
|
||||
*/
|
||||
public function __construct($lineNumber, $columnNumber = 0)
|
||||
public function __construct(int $lineNumber, int $columnNumber = 0)
|
||||
{
|
||||
$this->lineNumber = $lineNumber;
|
||||
$this->lineNumber = $lineNumber;
|
||||
$this->columnNumber = $columnNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the line number that is covered by this location.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLineNumber()
|
||||
public function getLineNumber(): int
|
||||
{
|
||||
return $this->lineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column number (character position on a line) for this location object.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getColumnNumber()
|
||||
public function getColumnNumber(): int
|
||||
{
|
||||
return $this->columnNumber;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5.5
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
|
@ -18,8 +21,6 @@ interface Project
|
|||
{
|
||||
/**
|
||||
* Returns the name of the project.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
public function getName(): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5.5
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @copyright 2010-2018 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;
|
||||
|
||||
/**
|
||||
|
|
@ -23,5 +27,5 @@ interface ProjectFactory
|
|||
* @param File[] $files
|
||||
* @return Project
|
||||
*/
|
||||
public function create($name, array $files);
|
||||
public function create($name, array $files): Project;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,13 @@
|
|||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://travis-ci.org/phpDocumentor/TypeResolver)
|
||||
[](https://ci.appveyor.com/project/phpDocumentor/TypeResolver/branch/master)
|
||||
[](https://coveralls.io/github/phpDocumentor/TypeResolver?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/phpDocumentor/TypeResolver/?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/phpDocumentor/TypeResolver/?branch=master)
|
||||
[](https://packagist.org/packages/phpDocumentor/TypeResolver)
|
||||
[](https://packagist.org/packages/phpDocumentor/TypeResolver)
|
||||
|
||||
|
||||
TypeResolver and FqsenResolver
|
||||
==============================
|
||||
|
||||
|
|
@ -22,8 +32,7 @@ The easiest way to install this library is with [Composer](https://getcomposer.o
|
|||
|
||||
## Examples
|
||||
|
||||
Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and
|
||||
check which type of action that your want to accomplish.
|
||||
Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and check which type of action that your want to accomplish.
|
||||
|
||||
## On Types and Element Names
|
||||
|
||||
|
|
@ -39,6 +48,7 @@ The TypeResolver can resolve:
|
|||
- a php primitive or pseudo-primitive such as a string or void (`@var string` or `@return void`).
|
||||
- a composite such as an array of string (`@var string[]`).
|
||||
- a compound such as a string or integer (`@var string|integer`).
|
||||
- an array expression (`@var (string|TypeResolver)[]`)
|
||||
- an object or interface such as the TypeResolver class (`@var TypeResolver`
|
||||
or `@var \phpDocumentor\Reflection\TypeResolver`)
|
||||
|
||||
|
|
@ -58,8 +68,7 @@ Where the FqsenResolver can resolve:
|
|||
|
||||
## Resolving a type
|
||||
|
||||
In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver`
|
||||
and call its `resolve` method like this:
|
||||
In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver` and call its `resolve` method like this:
|
||||
|
||||
```php
|
||||
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();
|
||||
|
|
@ -70,31 +79,30 @@ In this example you will receive a Value Object of class `\phpDocumentor\Reflect
|
|||
elements, one of type `\phpDocumentor\Reflection\Types\String_` and one of type
|
||||
`\phpDocumentor\Reflection\Types\Integer`.
|
||||
|
||||
The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but
|
||||
in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver
|
||||
in which namespace the given expression occurs and which namespace aliases (or imports) apply.
|
||||
The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
|
||||
|
||||
### Resolving nullable types
|
||||
|
||||
Php 7.1 introduced nullable types e.g. `?string`. Type resolver will resolve the original type without the nullable notation `?`
|
||||
just like it would do without the `?`. After that the type is wrapped in a `\phpDocumentor\Reflection\Types\Nullable` object.
|
||||
The `Nullable` type has a method to fetch the actual type.
|
||||
|
||||
## Resolving an FQSEN
|
||||
|
||||
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using
|
||||
the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this:
|
||||
A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this:
|
||||
|
||||
```php
|
||||
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
|
||||
$fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()');
|
||||
```
|
||||
|
||||
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class
|
||||
name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`.
|
||||
In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`.
|
||||
|
||||
The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural
|
||||
Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will
|
||||
inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
|
||||
The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply.
|
||||
|
||||
## Resolving partial Classes and Structural Element Names
|
||||
|
||||
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class
|
||||
names.
|
||||
Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class names.
|
||||
|
||||
For example, you have this file:
|
||||
|
||||
|
|
@ -116,9 +124,8 @@ class Classy
|
|||
```
|
||||
|
||||
Suppose that you would want to resolve (and expand) the type in the `@var` tag and the element name in the `@see` tag.
|
||||
For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating
|
||||
a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in
|
||||
play.
|
||||
|
||||
For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in play.
|
||||
|
||||
### Creating a Context
|
||||
|
||||
|
|
@ -131,9 +138,7 @@ $context = new \phpDocumentor\Reflection\Types\Context(
|
|||
);
|
||||
```
|
||||
|
||||
Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector
|
||||
object or by providing the namespace that you'd like to extract and the source code of the file in which the given
|
||||
type expression occurs.
|
||||
Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector object or by providing the namespace that you'd like to extract and the source code of the file in which the given type expression occurs.
|
||||
|
||||
```php
|
||||
$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory();
|
||||
|
|
@ -149,8 +154,7 @@ $context = $contextFactory->createForNamespace('\My\Example', file_get_contents(
|
|||
|
||||
### Using the Context
|
||||
|
||||
After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver
|
||||
class as second argument and the Resolvers will take this into account when resolving partial names.
|
||||
After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver class as second argument and the Resolvers will take this into account when resolving partial names.
|
||||
|
||||
To obtain the resolved class name for the `@var` tag in the example above you can do:
|
||||
|
||||
|
|
@ -159,24 +163,17 @@ $typeResolver = new \phpDocumentor\Reflection\TypeResolver();
|
|||
$type = $typeResolver->resolve('Types\Context', $context);
|
||||
```
|
||||
|
||||
When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call
|
||||
the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be
|
||||
`phpDocumentor\Reflection\Types\Context`.
|
||||
When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be `phpDocumentor\Reflection\Types\Context`.
|
||||
|
||||
> Why is the FQSEN wrapped in another object `Object_`?
|
||||
>
|
||||
> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common
|
||||
> type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it
|
||||
> is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN.
|
||||
> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN.
|
||||
|
||||
Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To
|
||||
resolve that you can do the following:
|
||||
Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To resolve that you can do the following:
|
||||
|
||||
```php
|
||||
$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver();
|
||||
$type = $fqsenResolver->resolve('Classy::otherFunction()', $context);
|
||||
```
|
||||
|
||||
Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the
|
||||
`resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to
|
||||
`\My\Example\Classy::otherFunction()`.
|
||||
Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the `resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to `\My\Example\Classy::otherFunction()`.
|
||||
|
|
|
|||
|
|
@ -1,27 +1,36 @@
|
|||
{
|
||||
"name": "phpdocumentor/type-resolver",
|
||||
"type": "library",
|
||||
"name": "phpdocumentor/type-resolver",
|
||||
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Mike van Riel", "email": "me@mikevanriel.com"}
|
||||
{
|
||||
"name": "Mike van Riel",
|
||||
"email": "me@mikevanriel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.5 || ^7.0",
|
||||
"phpdocumentor/reflection-common": "^1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {"phpDocumentor\\Reflection\\": ["src/"]}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {"phpDocumentor\\Reflection\\": ["tests/unit"]}
|
||||
"php": "^7.1",
|
||||
"phpdocumentor/reflection-common": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.2||^4.8.24",
|
||||
"mockery/mockery": "^0.9.4"
|
||||
"mockery/mockery": "~1",
|
||||
"ext-tokenizer": "^7.1",
|
||||
"phpunit/phpunit": "^7.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"phpDocumentor\\Reflection\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"phpDocumentor\\Reflection\\": "tests/unit"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,30 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
|
||||
class FqsenResolver
|
||||
{
|
||||
/** @var string Definition of the NAMESPACE operator in PHP */
|
||||
const OPERATOR_NAMESPACE = '\\';
|
||||
private const OPERATOR_NAMESPACE = '\\';
|
||||
|
||||
public function resolve($fqsen, Context $context = null)
|
||||
public function resolve(string $fqsen, ?Context $context = null) : Fqsen
|
||||
{
|
||||
if ($context === null) {
|
||||
$context = new Context('');
|
||||
|
|
@ -34,12 +39,8 @@ class FqsenResolver
|
|||
|
||||
/**
|
||||
* Tests whether the given type is a Fully Qualified Structural Element Name.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isFqsen($type)
|
||||
private function isFqsen(string $type) : bool
|
||||
{
|
||||
return strpos($type, self::OPERATOR_NAMESPACE) === 0;
|
||||
}
|
||||
|
|
@ -48,13 +49,9 @@ class FqsenResolver
|
|||
* Resolves a partial Structural Element Name (i.e. `Reflection\DocBlock`) to its FQSEN representation
|
||||
* (i.e. `\phpDocumentor\Reflection\DocBlock`) based on the Namespace and aliases mentioned in the Context.
|
||||
*
|
||||
* @param string $type
|
||||
* @param Context $context
|
||||
*
|
||||
* @return Fqsen
|
||||
* @throws \InvalidArgumentException when type is not a valid FQSEN.
|
||||
* @throws InvalidArgumentException When type is not a valid FQSEN.
|
||||
*/
|
||||
private function resolvePartialStructuralElementName($type, Context $context)
|
||||
private function resolvePartialStructuralElementName(string $type, Context $context) : Fqsen
|
||||
{
|
||||
$typeParts = explode(self::OPERATOR_NAMESPACE, $type, 2);
|
||||
|
||||
|
|
@ -63,7 +60,7 @@ class FqsenResolver
|
|||
// if the first segment is not an alias; prepend namespace name and return
|
||||
if (!isset($namespaceAliases[$typeParts[0]])) {
|
||||
$namespace = $context->getNamespace();
|
||||
if ('' !== $namespace) {
|
||||
if ($namespace !== '') {
|
||||
$namespace .= self::OPERATOR_NAMESPACE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -14,5 +15,8 @@ namespace phpDocumentor\Reflection;
|
|||
|
||||
interface Type
|
||||
{
|
||||
public function __toString();
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*/
|
||||
public function __toString() : string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,76 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection;
|
||||
|
||||
use ArrayIterator;
|
||||
use InvalidArgumentException;
|
||||
use phpDocumentor\Reflection\Types\Array_;
|
||||
use phpDocumentor\Reflection\Types\Collection;
|
||||
use phpDocumentor\Reflection\Types\Compound;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
use phpDocumentor\Reflection\Types\Iterable_;
|
||||
use phpDocumentor\Reflection\Types\Nullable;
|
||||
use phpDocumentor\Reflection\Types\Object_;
|
||||
use phpDocumentor\Reflection\Types\String_;
|
||||
use RuntimeException;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use const PREG_SPLIT_NO_EMPTY;
|
||||
use function array_keys;
|
||||
use function array_pop;
|
||||
use function class_exists;
|
||||
use function class_implements;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function preg_split;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
use function trim;
|
||||
|
||||
final class TypeResolver
|
||||
{
|
||||
/** @var string Definition of the ARRAY operator for types */
|
||||
const OPERATOR_ARRAY = '[]';
|
||||
private const OPERATOR_ARRAY = '[]';
|
||||
|
||||
/** @var string Definition of the NAMESPACE operator in PHP */
|
||||
const OPERATOR_NAMESPACE = '\\';
|
||||
private const OPERATOR_NAMESPACE = '\\';
|
||||
|
||||
/** @var string[] List of recognized keywords and unto which Value Object they map */
|
||||
private $keywords = array(
|
||||
/** @var int the iterator parser is inside a compound context */
|
||||
private const PARSER_IN_COMPOUND = 0;
|
||||
|
||||
/** @var int the iterator parser is inside a nullable expression context */
|
||||
private const PARSER_IN_NULLABLE = 1;
|
||||
|
||||
/** @var int the iterator parser is inside an array expression context */
|
||||
private const PARSER_IN_ARRAY_EXPRESSION = 2;
|
||||
|
||||
/** @var int the iterator parser is inside a collection expression context */
|
||||
private const PARSER_IN_COLLECTION_EXPRESSION = 3;
|
||||
|
||||
/**
|
||||
* @var array<string, string> List of recognized keywords and unto which Value Object they map
|
||||
* @psalm-var array<string, class-string<Type>>
|
||||
*/
|
||||
private $keywords = [
|
||||
'string' => Types\String_::class,
|
||||
'int' => Types\Integer::class,
|
||||
'integer' => Types\Integer::class,
|
||||
'bool' => Types\Boolean::class,
|
||||
'boolean' => Types\Boolean::class,
|
||||
'real' => Types\Float_::class,
|
||||
'float' => Types\Float_::class,
|
||||
'double' => Types\Float_::class,
|
||||
'object' => Object_::class,
|
||||
|
|
@ -52,17 +89,15 @@ final class TypeResolver
|
|||
'static' => Types\Static_::class,
|
||||
'parent' => Types\Parent_::class,
|
||||
'iterable' => Iterable_::class,
|
||||
);
|
||||
];
|
||||
|
||||
/** @var FqsenResolver */
|
||||
private $fqsenResolver;
|
||||
|
||||
/**
|
||||
* Initializes this TypeResolver with the means to create and resolve Fqsen objects.
|
||||
*
|
||||
* @param FqsenResolver $fqsenResolver
|
||||
*/
|
||||
public function __construct(FqsenResolver $fqsenResolver = null)
|
||||
public function __construct(?FqsenResolver $fqsenResolver = null)
|
||||
{
|
||||
$this->fqsenResolver = $fqsenResolver ?: new FqsenResolver();
|
||||
}
|
||||
|
|
@ -77,39 +112,177 @@ final class TypeResolver
|
|||
* 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.
|
||||
* @param Context $context
|
||||
*
|
||||
* @uses Context::getNamespace() to determine with what to prefix the type name.
|
||||
* @uses Context::getNamespaceAliases() to check whether the first part of the relative type name should not be
|
||||
* replaced with another namespace.
|
||||
* replaced with another namespace.
|
||||
* @uses Context::getNamespace() to determine with what to prefix the type name.
|
||||
*
|
||||
* @return Type|null
|
||||
* @param string $type The relative or absolute type.
|
||||
*/
|
||||
public function resolve($type, Context $context = null)
|
||||
public function resolve(string $type, ?Context $context = null) : Type
|
||||
{
|
||||
if (!is_string($type)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Attempted to resolve type but it appeared not to be a string, received: ' . var_export($type, true)
|
||||
);
|
||||
}
|
||||
|
||||
$type = trim($type);
|
||||
if (!$type) {
|
||||
throw new \InvalidArgumentException('Attempted to resolve "' . $type . '" but it appears to be empty');
|
||||
throw new InvalidArgumentException('Attempted to resolve "' . $type . '" but it appears to be empty');
|
||||
}
|
||||
|
||||
if ($context === null) {
|
||||
$context = new Context('');
|
||||
}
|
||||
|
||||
// split the type string into tokens `|`, `?`, `<`, `>`, `,`, `(`, `)[]`, '<', '>' and type names
|
||||
$tokens = preg_split(
|
||||
'/(\\||\\?|<|>|, ?|\\(|\\)(?:\\[\\])+)/',
|
||||
$type,
|
||||
-1,
|
||||
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
|
||||
);
|
||||
|
||||
if ($tokens === false) {
|
||||
throw new InvalidArgumentException('Unable to split the type string "' . $type . '" into tokens');
|
||||
}
|
||||
|
||||
$tokenIterator = new ArrayIterator($tokens);
|
||||
|
||||
return $this->parseTypes($tokenIterator, $context, self::PARSER_IN_COMPOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyse each tokens and creates types
|
||||
*
|
||||
* @param ArrayIterator $tokens the iterator on tokens
|
||||
* @param int $parserContext on of self::PARSER_* constants, indicating
|
||||
* the context where we are in the parsing
|
||||
*/
|
||||
private function parseTypes(ArrayIterator $tokens, Context $context, int $parserContext) : Type
|
||||
{
|
||||
$types = [];
|
||||
$token = '';
|
||||
while ($tokens->valid()) {
|
||||
$token = $tokens->current();
|
||||
|
||||
if ($token === '|') {
|
||||
if (count($types) === 0) {
|
||||
throw new RuntimeException(
|
||||
'A type is missing before a type separator'
|
||||
);
|
||||
}
|
||||
|
||||
if ($parserContext !== self::PARSER_IN_COMPOUND
|
||||
&& $parserContext !== self::PARSER_IN_ARRAY_EXPRESSION
|
||||
&& $parserContext !== self::PARSER_IN_COLLECTION_EXPRESSION
|
||||
) {
|
||||
throw new RuntimeException(
|
||||
'Unexpected type separator'
|
||||
);
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
} elseif ($token === '?') {
|
||||
if ($parserContext !== self::PARSER_IN_COMPOUND
|
||||
&& $parserContext !== self::PARSER_IN_ARRAY_EXPRESSION
|
||||
&& $parserContext !== self::PARSER_IN_COLLECTION_EXPRESSION
|
||||
) {
|
||||
throw new RuntimeException(
|
||||
'Unexpected nullable character'
|
||||
);
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
$type = $this->parseTypes($tokens, $context, self::PARSER_IN_NULLABLE);
|
||||
$types[] = new Nullable($type);
|
||||
} elseif ($token === '(') {
|
||||
$tokens->next();
|
||||
$type = $this->parseTypes($tokens, $context, self::PARSER_IN_ARRAY_EXPRESSION);
|
||||
|
||||
$resolvedType = new Array_($type);
|
||||
|
||||
$token = $tokens->current();
|
||||
// Someone did not properly close their array expression ..
|
||||
if ($token === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// we generate arrays corresponding to the number of '[]' after the ')'
|
||||
$numberOfArrays = (strlen($token) - 1) / 2;
|
||||
for ($i = 0; $i < $numberOfArrays - 1; ++$i) {
|
||||
$resolvedType = new Array_($resolvedType);
|
||||
}
|
||||
|
||||
$types[] = $resolvedType;
|
||||
$tokens->next();
|
||||
} elseif ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION && $token[0] === ')') {
|
||||
break;
|
||||
} elseif ($token === '<') {
|
||||
if (count($types) === 0) {
|
||||
throw new RuntimeException(
|
||||
'Unexpected collection operator "<", class name is missing'
|
||||
);
|
||||
}
|
||||
|
||||
$classType = array_pop($types);
|
||||
if ($classType !== null) {
|
||||
$types[] = $this->resolveCollection($tokens, $classType, $context);
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
} elseif ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION
|
||||
&& ($token === '>' || trim($token) === ',')
|
||||
) {
|
||||
break;
|
||||
} else {
|
||||
$type = $this->resolveSingleType($token, $context);
|
||||
$tokens->next();
|
||||
if ($parserContext === self::PARSER_IN_NULLABLE) {
|
||||
return $type;
|
||||
}
|
||||
|
||||
$types[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
if ($token === '|') {
|
||||
throw new RuntimeException(
|
||||
'A type is missing after a type separator'
|
||||
);
|
||||
}
|
||||
|
||||
if (count($types) === 0) {
|
||||
if ($parserContext === self::PARSER_IN_NULLABLE) {
|
||||
throw new RuntimeException(
|
||||
'A type is missing after a nullable character'
|
||||
);
|
||||
}
|
||||
|
||||
if ($parserContext === self::PARSER_IN_ARRAY_EXPRESSION) {
|
||||
throw new RuntimeException(
|
||||
'A type is missing in an array expression'
|
||||
);
|
||||
}
|
||||
|
||||
if ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION) {
|
||||
throw new RuntimeException(
|
||||
'A type is missing in a collection expression'
|
||||
);
|
||||
}
|
||||
} elseif (count($types) === 1) {
|
||||
return $types[0];
|
||||
}
|
||||
|
||||
return new Compound($types);
|
||||
}
|
||||
|
||||
/**
|
||||
* resolve the given type into a type object
|
||||
*
|
||||
* @param string $type the type string, representing a single type
|
||||
*
|
||||
* @return Type|Array_|Object_
|
||||
*/
|
||||
private function resolveSingleType(string $type, Context $context)
|
||||
{
|
||||
switch (true) {
|
||||
case $this->isNullableType($type):
|
||||
return $this->resolveNullableType($type, $context);
|
||||
case $this->isKeyword($type):
|
||||
return $this->resolveKeyword($type);
|
||||
case ($this->isCompoundType($type)):
|
||||
return $this->resolveCompoundType($type, $context);
|
||||
case $this->isTypedArray($type):
|
||||
return $this->resolveTypedArray($type, $context);
|
||||
case $this->isFqsen($type):
|
||||
|
|
@ -119,32 +292,28 @@ final class TypeResolver
|
|||
// @codeCoverageIgnoreStart
|
||||
default:
|
||||
// I haven't got the foggiest how the logic would come here but added this as a defense.
|
||||
throw new \RuntimeException(
|
||||
throw new RuntimeException(
|
||||
'Unable to resolve type "' . $type . '", there is no known method to resolve it'
|
||||
);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a keyword to the list of Keywords and associates it with a specific Value Object.
|
||||
*
|
||||
* @param string $keyword
|
||||
* @param string $typeClassName
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addKeyword($keyword, $typeClassName)
|
||||
public function addKeyword(string $keyword, string $typeClassName) : void
|
||||
{
|
||||
if (!class_exists($typeClassName)) {
|
||||
throw new \InvalidArgumentException(
|
||||
throw new InvalidArgumentException(
|
||||
'The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class'
|
||||
. ' but we could not find the class ' . $typeClassName
|
||||
);
|
||||
}
|
||||
|
||||
if (!in_array(Type::class, class_implements($typeClassName))) {
|
||||
throw new \InvalidArgumentException(
|
||||
if (!in_array(Type::class, class_implements($typeClassName), true)) {
|
||||
throw new InvalidArgumentException(
|
||||
'The class "' . $typeClassName . '" must implement the interface "phpDocumentor\Reflection\Type"'
|
||||
);
|
||||
}
|
||||
|
|
@ -156,10 +325,8 @@ final class TypeResolver
|
|||
* Detects whether the given type represents an array.
|
||||
*
|
||||
* @param string $type A relative or absolute type as defined in the phpDocumentor documentation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isTypedArray($type)
|
||||
private function isTypedArray(string $type) : bool
|
||||
{
|
||||
return substr($type, -2) === self::OPERATOR_ARRAY;
|
||||
}
|
||||
|
|
@ -168,10 +335,8 @@ final class TypeResolver
|
|||
* 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
|
||||
*/
|
||||
private function isKeyword($type)
|
||||
private function isKeyword(string $type) : bool
|
||||
{
|
||||
return in_array(strtolower($type), array_keys($this->keywords), true);
|
||||
}
|
||||
|
|
@ -180,119 +345,126 @@ final class TypeResolver
|
|||
* Detects whether the given type represents a relative structural element name.
|
||||
*
|
||||
* @param string $type A relative or absolute type as defined in the phpDocumentor documentation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isPartialStructuralElementName($type)
|
||||
private function isPartialStructuralElementName(string $type) : bool
|
||||
{
|
||||
return ($type[0] !== self::OPERATOR_NAMESPACE) && !$this->isKeyword($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the given type is a Fully Qualified Structural Element Name.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isFqsen($type)
|
||||
private function isFqsen(string $type) : bool
|
||||
{
|
||||
return strpos($type, self::OPERATOR_NAMESPACE) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the given type is a compound type (i.e. `string|int`).
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isCompoundType($type)
|
||||
{
|
||||
return strpos($type, '|') !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given type is a nullable type (i.e. `?string`)
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isNullableType($type)
|
||||
{
|
||||
return $type[0] === '?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the given typed array string (i.e. `string[]`) into an Array object with the right types set.
|
||||
*
|
||||
* @param string $type
|
||||
* @param Context $context
|
||||
*
|
||||
* @return Array_
|
||||
*/
|
||||
private function resolveTypedArray($type, Context $context)
|
||||
private function resolveTypedArray(string $type, Context $context) : Array_
|
||||
{
|
||||
return new Array_($this->resolve(substr($type, 0, -2), $context));
|
||||
return new Array_($this->resolveSingleType(substr($type, 0, -2), $context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the given keyword (such as `string`) into a Type object representing that keyword.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
private function resolveKeyword($type)
|
||||
private function resolveKeyword(string $type) : Type
|
||||
{
|
||||
$className = $this->keywords[strtolower($type)];
|
||||
|
||||
return new $className();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the given FQSEN string into an FQSEN object.
|
||||
*
|
||||
* @param string $type
|
||||
* @param Context|null $context
|
||||
*
|
||||
* @return Object_
|
||||
*/
|
||||
private function resolveTypedObject($type, Context $context = null)
|
||||
private function resolveTypedObject(string $type, ?Context $context = null) : Object_
|
||||
{
|
||||
return new Object_($this->fqsenResolver->resolve($type, $context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a compound type (i.e. `string|int`) into the appropriate Type objects or FQSEN.
|
||||
* Resolves the collection values and keys
|
||||
*
|
||||
* @param string $type
|
||||
* @param Context $context
|
||||
*
|
||||
* @return Compound
|
||||
* @return Array_|Collection
|
||||
*/
|
||||
private function resolveCompoundType($type, Context $context)
|
||||
private function resolveCollection(ArrayIterator $tokens, Type $classType, Context $context) : Type
|
||||
{
|
||||
$types = [];
|
||||
$isArray = ((string) $classType === 'array');
|
||||
|
||||
foreach (explode('|', $type) as $part) {
|
||||
$types[] = $this->resolve($part, $context);
|
||||
// allow only "array" or class name before "<"
|
||||
if (!$isArray
|
||||
&& (!$classType instanceof Object_ || $classType->getFqsen() === null)) {
|
||||
throw new RuntimeException(
|
||||
$classType . ' is not a collection'
|
||||
);
|
||||
}
|
||||
|
||||
return new Compound($types);
|
||||
$tokens->next();
|
||||
|
||||
$valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
|
||||
$keyType = null;
|
||||
|
||||
if ($tokens->current() !== null && trim($tokens->current()) === ',') {
|
||||
// if we have a comma, then we just parsed the key type, not the value type
|
||||
$keyType = $valueType;
|
||||
if ($isArray) {
|
||||
// check the key type for an "array" collection. We allow only
|
||||
// strings or integers.
|
||||
if (!$keyType instanceof String_ &&
|
||||
!$keyType instanceof Integer &&
|
||||
!$keyType instanceof Compound
|
||||
) {
|
||||
throw new RuntimeException(
|
||||
'An array can have only integers or strings as keys'
|
||||
);
|
||||
}
|
||||
|
||||
if ($keyType instanceof Compound) {
|
||||
foreach ($keyType->getIterator() as $item) {
|
||||
if (!$item instanceof String_ &&
|
||||
!$item instanceof Integer
|
||||
) {
|
||||
throw new RuntimeException(
|
||||
'An array can have only integers or strings as keys'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
// now let's parse the value type
|
||||
$valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
|
||||
}
|
||||
|
||||
if ($tokens->current() !== '>') {
|
||||
if (empty($tokens->current())) {
|
||||
throw new RuntimeException(
|
||||
'Collection: ">" is missing'
|
||||
);
|
||||
}
|
||||
|
||||
throw new RuntimeException(
|
||||
'Unexpected character "' . $tokens->current() . '", ">" is missing'
|
||||
);
|
||||
}
|
||||
|
||||
if ($isArray) {
|
||||
return new Array_($valueType, $keyType);
|
||||
}
|
||||
|
||||
/** @psalm-suppress RedundantCondition */
|
||||
if ($classType instanceof Object_) {
|
||||
return $this->makeCollectionFromObject($classType, $valueType, $keyType);
|
||||
}
|
||||
|
||||
throw new RuntimeException('Invalid $classType provided');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve nullable types (i.e. `?string`) into a Nullable type wrapper
|
||||
*
|
||||
* @param string $type
|
||||
* @param Context $context
|
||||
*
|
||||
* @return Nullable
|
||||
*/
|
||||
private function resolveNullableType($type, Context $context)
|
||||
private function makeCollectionFromObject(Object_ $object, Type $valueType, ?Type $keyType = null) : Collection
|
||||
{
|
||||
return new Nullable($this->resolve(ltrim($type, '?'), $context));
|
||||
return new Collection($object->getFqsen(), $valueType, $keyType);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\Types;
|
||||
|
||||
use phpDocumentor\Reflection\Type;
|
||||
|
||||
/**
|
||||
* Represents an array type as described in the PSR-5, the PHPDoc Standard.
|
||||
*
|
||||
|
|
@ -23,64 +22,6 @@ use phpDocumentor\Reflection\Type;
|
|||
* 2. Types (`string[]`), where the value type is provided by preceding an opening and closing square bracket with a
|
||||
* type name.
|
||||
*/
|
||||
final class Array_ implements Type
|
||||
final class Array_ extends AbstractList
|
||||
{
|
||||
/** @var Type */
|
||||
private $valueType;
|
||||
|
||||
/** @var Type */
|
||||
private $keyType;
|
||||
|
||||
/**
|
||||
* Initializes this representation of an array with the given Type or Fqsen.
|
||||
*
|
||||
* @param Type $valueType
|
||||
* @param Type $keyType
|
||||
*/
|
||||
public function __construct(Type $valueType = null, Type $keyType = null)
|
||||
{
|
||||
if ($keyType === null) {
|
||||
$keyType = new Compound([ new String_(), new Integer() ]);
|
||||
}
|
||||
if ($valueType === null) {
|
||||
$valueType = new Mixed_();
|
||||
}
|
||||
|
||||
$this->valueType = $valueType;
|
||||
$this->keyType = $keyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type for the keys of this array.
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public function getKeyType()
|
||||
{
|
||||
return $this->keyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the keys of this array.
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public function getValueType()
|
||||
{
|
||||
return $this->valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->valueType instanceof Mixed_) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
return $this->valueType . '[]';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -21,10 +22,8 @@ final class Boolean implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'bool';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -21,10 +22,8 @@ final class Callable_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'callable';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\Types;
|
||||
|
||||
use ArrayIterator;
|
||||
use InvalidArgumentException;
|
||||
use IteratorAggregate;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
use function implode;
|
||||
|
||||
/**
|
||||
* Value Object representing a Compound Type.
|
||||
|
|
@ -32,13 +35,15 @@ final class Compound implements Type, IteratorAggregate
|
|||
* Initializes a compound type (i.e. `string|int`) and tests if the provided types all implement the Type interface.
|
||||
*
|
||||
* @param Type[] $types
|
||||
* @throws \InvalidArgumentException when types are not all instance of Type
|
||||
*
|
||||
* @throws InvalidArgumentException When types are not all instance of Type.
|
||||
*/
|
||||
public function __construct(array $types)
|
||||
{
|
||||
foreach ($types as $type) {
|
||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
||||
if (!$type instanceof Type) {
|
||||
throw new \InvalidArgumentException('A compound type can only have other types as elements');
|
||||
throw new InvalidArgumentException('A compound type can only have other types as elements');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,12 +52,8 @@ final class Compound implements Type, IteratorAggregate
|
|||
|
||||
/**
|
||||
* Returns the type at the given index.
|
||||
*
|
||||
* @param integer $index
|
||||
*
|
||||
* @return Type|null
|
||||
*/
|
||||
public function get($index)
|
||||
public function get(int $index) : ?Type
|
||||
{
|
||||
if (!$this->has($index)) {
|
||||
return null;
|
||||
|
|
@ -63,22 +64,16 @@ final class Compound implements Type, IteratorAggregate
|
|||
|
||||
/**
|
||||
* Tests if this compound type has a type with the given index.
|
||||
*
|
||||
* @param integer $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has($index)
|
||||
public function has(int $index) : bool
|
||||
{
|
||||
return isset($this->types[$index]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return implode('|', $this->types);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\Types;
|
||||
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Provides information about the Context in which the DocBlock occurs that receives this context.
|
||||
*
|
||||
|
|
@ -31,26 +36,27 @@ final class Context
|
|||
/** @var string The current namespace. */
|
||||
private $namespace;
|
||||
|
||||
/** @var array List of namespace aliases => Fully Qualified Namespace. */
|
||||
/** @var string[] List of namespace aliases => Fully Qualified Namespace. */
|
||||
private $namespaceAliases;
|
||||
|
||||
/**
|
||||
* Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN)
|
||||
* format (without a preceding `\`).
|
||||
*
|
||||
* @param string $namespace The namespace where this DocBlock resides in.
|
||||
* @param array $namespaceAliases List of namespace aliases => Fully Qualified Namespace.
|
||||
* @param string $namespace The namespace where this DocBlock resides in.
|
||||
* @param string[] $namespaceAliases List of namespace aliases => Fully Qualified Namespace.
|
||||
*/
|
||||
public function __construct($namespace, array $namespaceAliases = [])
|
||||
public function __construct(string $namespace, array $namespaceAliases = [])
|
||||
{
|
||||
$this->namespace = ('global' !== $namespace && 'default' !== $namespace)
|
||||
? trim((string)$namespace, '\\')
|
||||
$this->namespace = $namespace !== 'global' && $namespace !== 'default'
|
||||
? trim($namespace, '\\')
|
||||
: '';
|
||||
|
||||
foreach ($namespaceAliases as $alias => $fqnn) {
|
||||
if ($fqnn[0] === '\\') {
|
||||
$fqnn = substr($fqnn, 1);
|
||||
}
|
||||
|
||||
if ($fqnn[strlen($fqnn) - 1] === '\\') {
|
||||
$fqnn = substr($fqnn, 0, -1);
|
||||
}
|
||||
|
|
@ -63,10 +69,8 @@ final class Context
|
|||
|
||||
/**
|
||||
* Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
public function getNamespace() : string
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
|
@ -77,7 +81,7 @@ final class Context
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNamespaceAliases()
|
||||
public function getNamespaceAliases() : array
|
||||
{
|
||||
return $this->namespaceAliases;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,44 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\Types;
|
||||
|
||||
use ArrayIterator;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
use ReflectionClassConstant;
|
||||
use ReflectionMethod;
|
||||
use ReflectionParameter;
|
||||
use ReflectionProperty;
|
||||
use Reflector;
|
||||
use RuntimeException;
|
||||
use UnexpectedValueException;
|
||||
use const T_AS;
|
||||
use const T_CLASS;
|
||||
use const T_CURLY_OPEN;
|
||||
use const T_DOLLAR_OPEN_CURLY_BRACES;
|
||||
use const T_NAMESPACE;
|
||||
use const T_NS_SEPARATOR;
|
||||
use const T_STRING;
|
||||
use const T_USE;
|
||||
use function array_merge;
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
use function get_class;
|
||||
use function is_string;
|
||||
use function token_get_all;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor.
|
||||
*
|
||||
|
|
@ -24,31 +51,78 @@ namespace phpDocumentor\Reflection\Types;
|
|||
final class ContextFactory
|
||||
{
|
||||
/** The literal used at the end of a use statement. */
|
||||
const T_LITERAL_END_OF_USE = ';';
|
||||
private const T_LITERAL_END_OF_USE = ';';
|
||||
|
||||
/** The literal used between sets of use statements */
|
||||
const T_LITERAL_USE_SEPARATOR = ',';
|
||||
private const T_LITERAL_USE_SEPARATOR = ',';
|
||||
|
||||
/**
|
||||
* Build a Context given a Class Reflection.
|
||||
*
|
||||
* @param \Reflector $reflector
|
||||
*
|
||||
* @see Context for more information on Contexts.
|
||||
*
|
||||
* @return Context
|
||||
*/
|
||||
public function createFromReflector(\Reflector $reflector)
|
||||
public function createFromReflector(Reflector $reflector) : Context
|
||||
{
|
||||
if (method_exists($reflector, 'getDeclaringClass')) {
|
||||
$reflector = $reflector->getDeclaringClass();
|
||||
if ($reflector instanceof ReflectionClass) {
|
||||
return $this->createFromReflectionClass($reflector);
|
||||
}
|
||||
|
||||
$fileName = $reflector->getFileName();
|
||||
$namespace = $reflector->getNamespaceName();
|
||||
if ($reflector instanceof ReflectionParameter) {
|
||||
return $this->createFromReflectionParameter($reflector);
|
||||
}
|
||||
|
||||
if (file_exists($fileName)) {
|
||||
return $this->createForNamespace($namespace, file_get_contents($fileName));
|
||||
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) {
|
||||
return $this->createFromReflectionClass($class);
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Unable to get class of ' . $parameter->getName());
|
||||
}
|
||||
|
||||
private function createFromReflectionMethod(ReflectionMethod $method) : Context
|
||||
{
|
||||
return $this->createFromReflectionClass($method->getDeclaringClass());
|
||||
}
|
||||
|
||||
private function createFromReflectionProperty(ReflectionProperty $property) : Context
|
||||
{
|
||||
return $this->createFromReflectionClass($property->getDeclaringClass());
|
||||
}
|
||||
|
||||
private function createFromReflectionClassConstant(ReflectionClassConstant $constant) : Context
|
||||
{
|
||||
return $this->createFromReflectionClass($constant->getDeclaringClass());
|
||||
}
|
||||
|
||||
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, []);
|
||||
|
|
@ -57,19 +131,18 @@ final class ContextFactory
|
|||
/**
|
||||
* Build a Context for a namespace in the provided file contents.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @see Context for more information on Contexts.
|
||||
*
|
||||
* @return Context
|
||||
* @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($namespace, $fileContents)
|
||||
public function createForNamespace(string $namespace, string $fileContents) : Context
|
||||
{
|
||||
$namespace = trim($namespace, '\\');
|
||||
$useStatements = [];
|
||||
$namespace = trim($namespace, '\\');
|
||||
$useStatements = [];
|
||||
$currentNamespace = '';
|
||||
$tokens = new \ArrayIterator(token_get_all($fileContents));
|
||||
$tokens = new ArrayIterator(token_get_all($fileContents));
|
||||
|
||||
while ($tokens->valid()) {
|
||||
switch ($tokens->current()[0]) {
|
||||
|
|
@ -80,7 +153,7 @@ final class ContextFactory
|
|||
// 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;
|
||||
$braceLevel = 0;
|
||||
$firstBraceFound = false;
|
||||
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
|
||||
if ($tokens->current() === '{'
|
||||
|
|
@ -89,12 +162,14 @@ final class ContextFactory
|
|||
if (!$firstBraceFound) {
|
||||
$firstBraceFound = true;
|
||||
}
|
||||
$braceLevel++;
|
||||
|
||||
++$braceLevel;
|
||||
}
|
||||
|
||||
if ($tokens->current() === '}') {
|
||||
$braceLevel--;
|
||||
--$braceLevel;
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
}
|
||||
break;
|
||||
|
|
@ -104,6 +179,7 @@ final class ContextFactory
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
}
|
||||
|
||||
|
|
@ -112,12 +188,8 @@ final class ContextFactory
|
|||
|
||||
/**
|
||||
* Deduce the name from tokens when we are at the T_NAMESPACE token.
|
||||
*
|
||||
* @param \ArrayIterator $tokens
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function parseNamespace(\ArrayIterator $tokens)
|
||||
private function parseNamespace(ArrayIterator $tokens) : string
|
||||
{
|
||||
// skip to the first string or namespace separator
|
||||
$this->skipToNextStringOrNamespaceSeparator($tokens);
|
||||
|
|
@ -135,22 +207,18 @@ final class ContextFactory
|
|||
/**
|
||||
* Deduce the names of all imports when we are at the T_USE token.
|
||||
*
|
||||
* @param \ArrayIterator $tokens
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function parseUseStatement(\ArrayIterator $tokens)
|
||||
private function parseUseStatement(ArrayIterator $tokens) : array
|
||||
{
|
||||
$uses = [];
|
||||
$continue = true;
|
||||
|
||||
while ($continue) {
|
||||
while (true) {
|
||||
$this->skipToNextStringOrNamespaceSeparator($tokens);
|
||||
|
||||
list($alias, $fqnn) = $this->extractUseStatement($tokens);
|
||||
$uses[$alias] = $fqnn;
|
||||
$uses = array_merge($uses, $this->extractUseStatements($tokens));
|
||||
if ($tokens->current()[0] === self::T_LITERAL_END_OF_USE) {
|
||||
$continue = false;
|
||||
return $uses;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,12 +227,8 @@ final class ContextFactory
|
|||
|
||||
/**
|
||||
* Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.
|
||||
*
|
||||
* @param \ArrayIterator $tokens
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function skipToNextStringOrNamespaceSeparator(\ArrayIterator $tokens)
|
||||
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void
|
||||
{
|
||||
while ($tokens->valid() && ($tokens->current()[0] !== T_STRING) && ($tokens->current()[0] !== T_NS_SEPARATOR)) {
|
||||
$tokens->next();
|
||||
|
|
@ -173,38 +237,114 @@ final class ContextFactory
|
|||
|
||||
/**
|
||||
* 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.
|
||||
* a USE statement yet. This will return a key/value array of the alias => namespace.
|
||||
*
|
||||
* @param \ArrayIterator $tokens
|
||||
* @return string[]
|
||||
*
|
||||
* @return string
|
||||
* @psalm-suppress TypeDoesNotContainType
|
||||
*/
|
||||
private function extractUseStatement(\ArrayIterator $tokens)
|
||||
private function extractUseStatements(ArrayIterator $tokens) : array
|
||||
{
|
||||
$result = [''];
|
||||
while ($tokens->valid()
|
||||
&& ($tokens->current()[0] !== self::T_LITERAL_USE_SEPARATOR)
|
||||
&& ($tokens->current()[0] !== self::T_LITERAL_END_OF_USE)
|
||||
) {
|
||||
if ($tokens->current()[0] === T_AS) {
|
||||
$result[] = '';
|
||||
$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 .= $tokenValue;
|
||||
$currentAlias = $tokenValue;
|
||||
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 .= $tokenValue;
|
||||
$currentAlias = $tokenValue;
|
||||
break;
|
||||
case T_AS:
|
||||
$state = 'grouped-alias';
|
||||
break;
|
||||
case self::T_LITERAL_USE_SEPARATOR:
|
||||
$state = 'grouped';
|
||||
$extractedUseStatements[$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[$currentAlias] = $currentNs;
|
||||
$currentNs = $groupedNs;
|
||||
$currentAlias = '';
|
||||
break;
|
||||
case self::T_LITERAL_END_OF_USE:
|
||||
$state = 'end';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($tokens->current()[0] === T_STRING || $tokens->current()[0] === T_NS_SEPARATOR) {
|
||||
$result[count($result) - 1] .= $tokens->current()[1];
|
||||
|
||||
if ($state === 'end') {
|
||||
break;
|
||||
}
|
||||
|
||||
$tokens->next();
|
||||
}
|
||||
|
||||
if (count($result) == 1) {
|
||||
$backslashPos = strrpos($result[0], '\\');
|
||||
|
||||
if (false !== $backslashPos) {
|
||||
$result[] = substr($result[0], $backslashPos + 1);
|
||||
} else {
|
||||
$result[] = $result[0];
|
||||
}
|
||||
if ($groupedNs !== $currentNs) {
|
||||
$extractedUseStatements[$currentAlias] = $currentNs;
|
||||
}
|
||||
|
||||
return array_reverse($result);
|
||||
return $extractedUseStatements;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -21,10 +22,8 @@ final class Float_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -18,10 +19,8 @@ final class Integer implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -21,10 +22,8 @@ final class Null_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\Types;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\Type;
|
||||
use function strpos;
|
||||
|
||||
/**
|
||||
* Value Object representing an object.
|
||||
|
|
@ -30,15 +33,14 @@ final class Object_ implements Type
|
|||
/**
|
||||
* Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'.
|
||||
*
|
||||
* @param Fqsen $fqsen
|
||||
* @throws \InvalidArgumentException when provided $fqsen is not a valid type.
|
||||
* @throws InvalidArgumentException When provided $fqsen is not a valid type.
|
||||
*/
|
||||
public function __construct(Fqsen $fqsen = null)
|
||||
public function __construct(?Fqsen $fqsen = null)
|
||||
{
|
||||
if (strpos((string)$fqsen, '::') !== false || strpos((string)$fqsen, '()') !== false) {
|
||||
throw new \InvalidArgumentException(
|
||||
if (strpos((string) $fqsen, '::') !== false || strpos((string) $fqsen, '()') !== false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Object types can only refer to a class, interface or trait but a method, function, constant or '
|
||||
. 'property was received: ' . (string)$fqsen
|
||||
. 'property was received: ' . (string) $fqsen
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -47,23 +49,16 @@ final class Object_ implements Type
|
|||
|
||||
/**
|
||||
* Returns the FQSEN associated with this object.
|
||||
*
|
||||
* @return Fqsen|null
|
||||
*/
|
||||
public function getFqsen()
|
||||
public function getFqsen() : ?Fqsen
|
||||
{
|
||||
return $this->fqsen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
if ($this->fqsen) {
|
||||
return (string)$this->fqsen;
|
||||
return (string) $this->fqsen;
|
||||
}
|
||||
|
||||
return 'object';
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -21,10 +22,8 @@ final class Scalar implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'scalar';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -23,10 +24,8 @@ final class Self_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'self';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -28,10 +29,8 @@ final class Static_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'static';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -21,10 +22,8 @@ final class String_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -24,10 +25,8 @@ final class This implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return '$this';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<?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.
|
||||
*
|
||||
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
|
|
@ -24,10 +25,8 @@ final class Void_ implements Type
|
|||
{
|
||||
/**
|
||||
* Returns a rendered output of the Type as it would be used in a DocBlock.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return 'void';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue