Compare commits

..
15 Commits
Author SHA1 Message Date
Aamir Sohail KmAs db125e8df4 style: fix typo in Description.php (#24) 2024-12-28 11:00:03 +01:00
Barry vd. Heuvel 62d62638b2 Update composer.json 2024-12-28 10:02:09 +01:00
Nereo Berardozzi 476f62b577 Added generics to Context (#22) 2024-12-24 19:06:41 +01:00
Nereo Berardozzi e5c8b970d6 Handle more PHPDoc type keyworks (#23)
* Added advanced PHPDoc type keyworks

* Fixed typed keywords
2024-12-24 19:06:02 +01:00
Nereo Berardozzi d5d2d76892 Parse template tag for generics (#21)
* Parse template tag for generics

* Fixed templatetag docblock

* Fixed PHP 7 issue

* Fixed PHP 7.2 issue

* Fixed another 7.2 issue
2024-12-24 12:30:50 +01:00
Barry vd. Heuvel fba297a2a7 Merge pull request #20 from JeppeKnockaert/fix-php84-deprecations
Fix PHP 8.4 deprecations
2024-11-27 22:10:25 +01:00
Jeppe Knockaert 0fd348d3fe Replace implicitly nullable parameters for PHP 8.4 2024-11-27 11:22:09 +01:00
Barry vd. Heuvel 67e478e26a Merge pull request #19 from KentarouTakeda/chore-improve-tests
chore: improve tests
2024-11-08 21:47:50 +01:00
武田 憲太郎 e292151642 Update actions/checkout to the latest version 2024-11-08 21:37:33 +09:00
武田 憲太郎 8bb2a5f9b7 Test coverage extended to PHP 8.4 2024-11-08 21:30:01 +09:00
武田 憲太郎 ac3b854893 Exclude PHPUnit auto-generated files from git 2024-11-08 21:29:38 +09:00
Barry vd. Heuvel c6fad15f7c Merge pull request #18 from KentarouTakeda/fix-generics-and-closures-return-type
Fixed incorrect parsing of return types for generics and closures
2024-10-23 13:41:03 +02:00
武田 憲太郎 836d531676 Fixed incorrect parsing of return types for generics and closures 2024-10-20 09:02:42 +09:00
Barry vd. Heuvel bba116ba9d Merge pull request #17 from KentarouTakeda/nested-generics-and-closures-type-hint
Support nested generics and closures type hint
2024-10-16 13:06:28 +02:00
武田 憲太郎 23fa082874 Support nested generics and closures type hint 2024-10-16 18:33:31 +09:00
17 changed files with 516 additions and 40 deletions
+2 -2
View File
@@ -19,14 +19,14 @@ jobs:
strategy: strategy:
matrix: matrix:
php: [8.1, 8.0, 7.4, 7.3, 7.2] php: [8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2]
dependency-version: [prefer-lowest, prefer-stable] dependency-version: [prefer-lowest, prefer-stable]
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} name: P${{ matrix.php }} - ${{ matrix.dependency-version }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v4
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
+1
View File
@@ -1,3 +1,4 @@
.idea .idea
.phpunit.result.cache
composer.lock composer.lock
vendor vendor
+1 -1
View File
@@ -20,7 +20,7 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.0.x-dev" "dev-master": "2.2.x-dev"
} }
} }
} }
+21 -3
View File
@@ -15,6 +15,7 @@ namespace Barryvdh\Reflection;
use Barryvdh\Reflection\DocBlock\Tag; use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Context; use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Location; use Barryvdh\Reflection\DocBlock\Location;
use Barryvdh\Reflection\DocBlock\Tag\TemplateTag;
/** /**
* Parses the DocBlock for any structure. * Parses the DocBlock for any structure.
@@ -40,6 +41,9 @@ class DocBlock implements \Reflector
*/ */
protected $tags = array(); protected $tags = array();
/** @var string[] An array containing all the generics in this docblock. */
protected $generics = array();
/** @var Context Information about the context of this DocBlock. */ /** @var Context Information about the context of this DocBlock. */
protected $context = null; protected $context = null;
@@ -71,8 +75,8 @@ class DocBlock implements \Reflector
*/ */
public function __construct( public function __construct(
$docblock, $docblock,
Context $context = null, ?Context $context = null,
Location $location = null ?Location $location = null
) { ) {
if (is_object($docblock)) { if (is_object($docblock)) {
if (!method_exists($docblock, 'getDocComment')) { if (!method_exists($docblock, 'getDocComment')) {
@@ -238,7 +242,11 @@ class DocBlock implements \Reflector
// create proper Tag objects // create proper Tag objects
foreach ($result as $key => $tag_line) { foreach ($result as $key => $tag_line) {
$result[$key] = Tag::createInstance(trim($tag_line), $this); $tag = Tag::createInstance(trim($tag_line), $this);
if ($tag instanceof TemplateTag) {
$this->generics[] = $tag->getTemplateName();
}
$result[$key] = $tag;
} }
} }
@@ -457,6 +465,16 @@ class DocBlock implements \Reflector
return false; return false;
} }
/**
* Returns the generics for this DocBlock.
*
* @return string[]
*/
public function getGenerics()
{
return $this->generics;
}
/** /**
* Builds a string representation of this object. * Builds a string representation of this object.
* *
+30 -2
View File
@@ -29,7 +29,10 @@ class Context
/** @var string Name of the structural element, within the namespace. */ /** @var string Name of the structural element, within the namespace. */
protected $lsen = ''; protected $lsen = '';
/** @var string[] List of generics */
protected $generics = array();
/** /**
* Cteates a new context. * Cteates a new context.
* @param string $namespace The namespace where this DocBlock * @param string $namespace The namespace where this DocBlock
@@ -42,13 +45,15 @@ class Context
public function __construct( public function __construct(
$namespace = '', $namespace = '',
array $namespace_aliases = array(), array $namespace_aliases = array(),
$lsen = '' $lsen = '',
array $generics = array()
) { ) {
if (!empty($namespace)) { if (!empty($namespace)) {
$this->setNamespace($namespace); $this->setNamespace($namespace);
} }
$this->setNamespaceAliases($namespace_aliases); $this->setNamespaceAliases($namespace_aliases);
$this->setLSEN($lsen); $this->setLSEN($lsen);
$this->setGenerics($generics);
} }
/** /**
@@ -76,6 +81,16 @@ class Context
{ {
return $this->lsen; return $this->lsen;
} }
/**
* Returns the list of generics.
*
* @return string[] List of generics
*/
public function getGenerics()
{
return $this->generics;
}
/** /**
* Sets a new namespace. * Sets a new namespace.
@@ -151,4 +166,17 @@ class Context
$this->lsen = (string)$lsen; $this->lsen = (string)$lsen;
return $this; return $this;
} }
/**
* Sets a new list of generics.
*
* @param string[] $generics The new list of generics.
*
* @return $this
*/
public function setGenerics(array $generics)
{
$this->generics = $generics;
return $this;
}
} }
@@ -35,10 +35,10 @@ class Description implements \Reflector
/** /**
* Populates the fields of a description. * Populates the fields of a description.
* *
* @param string $content The description's conetnts. * @param string $content The description's contents.
* @param DocBlock $docblock The DocBlock which this description belongs to. * @param DocBlock $docblock The DocBlock which this description belongs to.
*/ */
public function __construct($content, DocBlock $docblock = null) public function __construct($content, ?DocBlock $docblock = null)
{ {
$this->setContent($content)->setDocBlock($docblock); $this->setContent($content)->setDocBlock($docblock);
} }
@@ -190,7 +190,7 @@ class Description implements \Reflector
* *
* @return $this * @return $this
*/ */
public function setDocBlock(DocBlock $docblock = null) public function setDocBlock(?DocBlock $docblock = null)
{ {
$this->docblock = $docblock; $this->docblock = $docblock;
+9 -7
View File
@@ -97,7 +97,9 @@ class Tag implements \Reflector
'version' 'version'
=> '\Barryvdh\Reflection\DocBlock\Tag\VersionTag', => '\Barryvdh\Reflection\DocBlock\Tag\VersionTag',
'SuppressWarnings' 'SuppressWarnings'
=> '\Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag' => '\Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag',
'template'
=> '\Barryvdh\Reflection\DocBlock\Tag\TemplateTag'
); );
/** /**
@@ -113,8 +115,8 @@ class Tag implements \Reflector
*/ */
final public static function createInstance( final public static function createInstance(
$tag_line, $tag_line,
DocBlock $docblock = null, ?DocBlock $docblock = null,
Location $location = null ?Location $location = null
) { ) {
if (!preg_match( if (!preg_match(
'/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us', '/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)?/us',
@@ -194,8 +196,8 @@ class Tag implements \Reflector
public function __construct( public function __construct(
$name, $name,
$content, $content,
DocBlock $docblock = null, ?DocBlock $docblock = null,
Location $location = null ?Location $location = null
) { ) {
$this $this
->setName($name) ->setName($name)
@@ -323,7 +325,7 @@ class Tag implements \Reflector
* *
* @return $this * @return $this
*/ */
public function setDocBlock(DocBlock $docblock = null) public function setDocBlock(?DocBlock $docblock = null)
{ {
$this->docblock = $docblock; $this->docblock = $docblock;
@@ -347,7 +349,7 @@ class Tag implements \Reflector
* *
* @return $this * @return $this
*/ */
public function setLocation(Location $location = null) public function setLocation(?Location $location = null)
{ {
$this->location = $location; $this->location = $location;
@@ -80,10 +80,12 @@ class MethodTag extends ReturnTag
(?:[\w\|_\\\\]*\$this[\w\|_\\\\]*) (?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
| |
(?: (?:
(?:[\w\|_\\\\]+) (?:[\w\|_\\\\]+(?:<[\s\S]*>)?)
# array notation # array notation
(?:\[\])* (?:\[\])*
)* )*
|
(?:\([\s\S]*\))?
) )
\s+ \s+
)? )?
@@ -46,21 +46,38 @@ class ParamTag extends ReturnTag
public function setContent($content) public function setContent($content)
{ {
Tag::setContent($content); Tag::setContent($content);
$parts = preg_split(
'/(\s+)/Su',
$this->description,
3,
PREG_SPLIT_DELIM_CAPTURE
);
// detect generic type $parts = [];
if (isset($parts[0]) && isset($parts[2]) && strpos($parts[0], '<') !== false && strpos($parts[2], '>') !== false) { $rest = $this->description;
$parts[0] .= ' ' . $parts[2];
unset($parts[1]); // parsing generics and closures to detect types
unset($parts[2]); for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) {
$parts = array_values($parts); $char = $rest[$pos];
if($char === '<') {
array_unshift($stacks, $char);
}
if($char === '(') {
array_unshift($stacks, $char);
}
if($char === '>' && isset($stacks[0]) && $stacks[0] === '<') {
array_shift($stacks);
}
if($char === ')' && isset($stacks[0]) && $stacks[0] === '(') {
array_shift($stacks);
}
if(!$stacks && preg_match('/\A(\s+)(.*)/su', substr($rest, $pos), $matches)) {
$parts[0] = substr($rest, 0, $pos);
$parts[1] = $matches[1];
$rest = $matches[2];
break;
}
} }
array_push($parts, ...preg_split('/(\s+)/u', $rest, 2, PREG_SPLIT_DELIM_CAPTURE));
// if the first item that is encountered is not a variable; it is a type // if the first item that is encountered is not a variable; it is a type
if (isset($parts[0]) if (isset($parts[0])
&& (strlen($parts[0]) > 0) && (strlen($parts[0]) > 0)
@@ -120,7 +120,8 @@ class ReturnTag extends Tag
if (null === $this->types) { if (null === $this->types) {
$this->types = new Collection( $this->types = new Collection(
array($this->type), array($this->type),
$this->docblock ? $this->docblock->getContext() : null $this->docblock ? $this->docblock->getContext() : null,
$this->docblock ? $this->docblock->getGenerics() : array()
); );
} }
return $this->types; return $this->types;
@@ -0,0 +1,104 @@
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
/**
* Reflection class for a @template tag in a Docblock.
*
* @author chack1172 <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class TemplateTag extends ParamTag
{
/** @var string */
protected $templateName = null;
/** @var string|null */
protected $bound = null;
public function getContent()
{
if (null === $this->content) {
$this->content = $this->templateName;
if (null !== $this->bound) {
$this->content .= ' of ' . $this->bound;
}
}
return $this->content;
}
/**
* {@inheritDoc}
*/
public function setContent($content)
{
$parts = explode(' of ', $content);
$this->templateName = $parts[0];
if (isset($parts[1])) {
$this->bound = $parts[1];
}
$this->setDescription('');
$this->content = $content;
return $this;
}
/**
* Gets the template name
*
* @return string
*/
public function getTemplateName()
{
return $this->templateName;
}
/**
* Sets the template name
*
* @param string $templateName
*
* @return $this
*/
public function setTemplateName($templateName)
{
$this->templateName = $templateName;
$this->content = null;
return $this;
}
/**
* Gets the bound type
*
* @return string|null
*/
public function getBound()
{
return $this->bound;
}
/**
* Sets the bound type
* @param string|null $bound
* @return $this
*/
public function setBound($bound)
{
$this->bound = $bound;
$this->content = null;
return $this;
}
}
@@ -37,7 +37,14 @@ class Collection extends \ArrayObject
protected static $keywords = array( protected static $keywords = array(
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double', 'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
'object', 'mixed', 'array', 'resource', 'void', 'null', 'scalar', 'object', 'mixed', 'array', 'resource', 'void', 'null', 'scalar',
'callback', 'callable', 'false', 'true', 'self', '$this', 'static' 'callback', 'callable', 'false', 'true', 'self', '$this', 'static',
'array-key', 'number', 'iterable', 'pure-callable', 'closed-resource',
'open-resource', 'positive-int', 'negative-int', 'non-positive-int',
'non-negative-int', 'non-zero-int', 'non-empty-array', 'list',
'non-empty-list', 'key-of', 'value-of', 'template-type', 'class-string',
'callable-string', 'numeric-string', 'non-empty-string',
'non-falsy-string', 'literal-string', 'lowercase-string', 'never',
'never-return', 'never-returns', 'no-return', 'int-mask', 'int-mask-of'
); );
/** /**
@@ -50,6 +57,13 @@ class Collection extends \ArrayObject
*/ */
protected $context = null; protected $context = null;
/**
* List of generics types
*
* @var string[]
*/
protected $generics = array();
/** /**
* Registers the namespace and aliases; uses that to add and expand the * Registers the namespace and aliases; uses that to add and expand the
* given types. * given types.
@@ -60,9 +74,11 @@ class Collection extends \ArrayObject
*/ */
public function __construct( public function __construct(
array $types = array(), array $types = array(),
Context $context = null ?Context $context = null,
array $generics = array()
) { ) {
$this->context = null === $context ? new Context() : $context; $this->context = null === $context ? new Context() : $context;
$this->generics = array_merge($this->context->getGenerics(), $generics);
foreach ($types as $type) { foreach ($types as $type) {
$this->add($type); $this->add($type);
@@ -145,9 +161,9 @@ class Collection extends \ArrayObject
$type_parts[] = $curr_type; $type_parts[] = $curr_type;
$curr_type = ''; $curr_type = '';
} else { } else {
if ($char === '<') { if ($char === '<' || $char === '(') {
$nest_level++; $nest_level++;
} else if ($char === '>') { } else if ($char === '>' || $char === ')') {
$nest_level--; $nest_level--;
} }
@@ -185,7 +201,11 @@ class Collection extends \ArrayObject
return ''; return '';
} }
if (substr($type, 0, 6) === 'array<' && substr($type, -1) === '>') { if (preg_match('/^[\w-]+<.*>$/', $type)) {
return $type;
}
if($type[0] === '(') {
return $type; return $type;
} }
@@ -193,7 +213,7 @@ class Collection extends \ArrayObject
return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY; return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
} }
if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type)) { if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type) && !$this->isTypeAGeneric($type)) {
if($this->shouldBeAbsolute($type)){ if($this->shouldBeAbsolute($type)){
return self::OPERATOR_NAMESPACE . $type; return self::OPERATOR_NAMESPACE . $type;
@@ -269,6 +289,19 @@ class Collection extends \ArrayObject
|| $this->isTypeAKeyword($type); || $this->isTypeAKeyword($type);
} }
/**
* Detects whether the given type represents a generic.
*
* @param string $type A relative or absolute type as defined in the
* phpDocumentor documentation.
*
* @return bool
*/
protected function isTypeAGeneric($type)
{
return in_array($type, $this->generics, true);
}
/** /**
* Detects if the type should actually be absolute, by checking if it exists. * Detects if the type should actually be absolute, by checking if it exists.
* *
@@ -142,7 +142,25 @@ class MethodTagTest extends TestCase
array( array(
'static static foo()', 'static static foo()',
true, 'foo', 'static', true, 0, '' true, 'foo', 'static', true, 0, ''
) ),
// generic array
array(
'array<int, string> foo()',
true, 'foo', 'array<int, string>', false, 0, ''
),
// nested generics
array(
'array<int, array<string, mixed>> foo()',
true, 'foo', 'array<int, array<string, mixed>>', false, 0, ''
),
// closure
array(
'(\Closure(int, string): bool) foo()',
true, 'foo', '(\Closure(int, string): bool)', false, 0, ''
),
); );
} }
} }
@@ -114,7 +114,75 @@ class ParamTagTest extends TestCase
array('int'), array('int'),
'$bob', '$bob',
"Type on a new line" "Type on a new line"
) ),
// generic array
array(
'param',
'array<int, string> $names',
'array<int, string>',
array('array<int, string>'),
'$names',
''
),
// nested generics
array(
'param',
'array<int, array<string, mixed>> $arrays',
'array<int, array<string, mixed>>',
array('array<int, array<string, mixed>>'),
'$arrays',
''
),
// closure
array(
'param',
'(\Closure(int, string): bool) $callback',
'(\Closure(int, string): bool)',
array('(\Closure(int, string): bool)'),
'$callback',
''
),
// generic array in closure
array(
'param',
'(\Closure(array<int, string>): bool) $callback',
'(\Closure(array<int, string>): bool)',
array('(\Closure(array<int, string>): bool)'),
'$callback',
''
),
// union types in closure
array(
'param',
'(\Closure(int|string): bool)|bool $callback',
'(\Closure(int|string): bool)|bool',
array('(\Closure(int|string): bool)', 'bool'),
'$callback',
''
),
// example from Laravel Framework - Eloquent Builder)
array(
'param',
'array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>|string $relations',
'array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>|string',
array('array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>', 'string'),
'$relations',
''
),
array(
'param',
'(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null $callback',
'(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null',
array('(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)', 'string', 'null'),
'$callback',
''
),
); );
} }
} }
@@ -0,0 +1,86 @@
<?php
/**
* phpDocumentor Template Tag Test
*
* PHP version 5.3
*
* @author Daniel O'Connor <daniel.oconnor@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace Barryvdh\Reflection\DocBlock\Tag;
use PHPUnit\Framework\TestCase;
/**
* Test class for \Barryvdh\Reflection\DocBlock\Tag\TemplateTag
*
* @author Daniel O'Connor <daniel.oconnor@gmail.com>
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
class TemplateTagTest extends TestCase
{
/**
* Test that the phpDocumentor_Reflection_DocBlock_Tag_See can create a link
* for the @see doc block.
*
* @param string $type
* @param string $content
* @param string $exContent
* @param string $exReference
*
* @covers \Barryvdh\Reflection\DocBlock\Tag\SeeTag
* @dataProvider provideDataForConstuctor
*
* @return void
*/
public function testConstructorParesInputsIntoCorrectFields(
$type,
$content,
$exContent,
$exDescription,
$exTemplateName,
$exBound
) {
$tag = new TemplateTag($type, $content);
$this->assertEquals($type, $tag->getName());
$this->assertEquals($exContent, $tag->getContent());
$this->assertEquals($exDescription, $tag->getDescription());
$this->assertEquals($exTemplateName, $tag->getTemplateName());
$this->assertEquals($exBound, $tag->getBound());
}
/**
* Data provider for testConstructorParesInputsIntoCorrectFields
*
* @return array
*/
public function provideDataForConstuctor()
{
// $type, $content, $exContent, $exDescription, $exTemplateName, $exBound
return array(
array(
'template',
'TValue',
'TValue',
'',
'TValue',
null,
),
array(
'template',
'TValue of string',
'TValue of string',
'',
'TValue',
'string',
),
);
}
}
@@ -144,6 +144,27 @@ class CollectionTest extends TestCase
$this->assertSame($expected, $collection->getArrayCopy()); $this->assertSame($expected, $collection->getArrayCopy());
} }
/**
* @param string $fixture
* @param array $expected
*
* @dataProvider provideTypesToExpandWithGenerics
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
*
* @return void
*/
public function testAddWithGenerics($fixture, $expected)
{
$collection = new Collection(
array(),
new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'), '', array('TParent')),
array('TValue')
);
$collection->add($fixture);
$this->assertSame($expected, $collection->getArrayCopy());
}
/** /**
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add * @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
* *
@@ -198,6 +219,10 @@ class CollectionTest extends TestCase
'DocBlock[]|int[]', 'DocBlock[]|int[]',
array($namespace.'DocBlock[]', 'int[]') array($namespace.'DocBlock[]', 'int[]')
), ),
array(
'array<string>',
array('array<string>')
),
array( array(
'array<int, string>', 'array<int, string>',
array('array<int, string>') array('array<int, string>')
@@ -222,6 +247,42 @@ class CollectionTest extends TestCase
'Alias\LinkDescriptor::setLink()', 'Alias\LinkDescriptor::setLink()',
array('\My\Space\Aliasing\LinkDescriptor::setLink()') array('\My\Space\Aliasing\LinkDescriptor::setLink()')
), ),
array(
'int<0, 100>',
array('int<0, 100>')
),
array(
'non-empty-array<string>',
array('non-empty-array<string>')
),
array(
'non-empty-array<int, string>',
array('non-empty-array<int, string>')
),
array(
'list<string>',
array('list<string>')
),
array(
'non-empty-list<string>',
array('non-empty-list<string>')
),
array(
'key-of<MyClass::ARRAY_CONST>',
array('key-of<MyClass::ARRAY_CONST>')
),
array(
'value-of<MyClass::ARRAY_CONST>',
array('value-of<MyClass::ARRAY_CONST>')
),
array(
'value-of<MyBackedEnum>',
array('value-of<MyBackedEnum>')
),
array(
'iterable<string>',
array('iterable<string>')
),
); );
} }
@@ -267,4 +328,23 @@ class CollectionTest extends TestCase
), ),
); );
} }
/**
* Returns the types and their expected values to test the retrieval of
* types including generics.
*
* @param string $method Name of the method consuming this data provider.
* @param string $namespace Name of the namespace to user as basis.
*
* @return string[]
*/
public function provideTypesToExpandWithGenerics($method, $namespace = '\My\Space\\')
{
return array(
array('TValue', array('TValue')),
array('TValue[]', array('TValue[]')),
array('TValue|DocBlock', array('TValue', $namespace . 'DocBlock')),
array('TParent', array('TParent')),
);
}
} }
@@ -336,4 +336,22 @@ DOCBLOCK;
$this->assertCount(1, $object->getTagsByName('return')); $this->assertCount(1, $object->getTagsByName('return'));
$this->assertCount(2, $object->getTagsByName('param')); $this->assertCount(2, $object->getTagsByName('param'));
} }
/**
* @covers \Barryvdh\Reflection\DocBlock::parseTags
*
* @return void
*/
public function testGenericsAreParsed()
{
$fixture = <<<DOCBLOCK
/**
* @template TValue
* @param TValue
* @return TValue
*/
DOCBLOCK;
$object = new DocBlock($fixture);
$this->assertSame(array('TValue'), $object->getGenerics());
}
} }