Skip to content

Commit

Permalink
Handle more PHPDoc type keyworks (#23)
Browse files Browse the repository at this point in the history
* Added advanced PHPDoc type keyworks

* Fixed typed keywords
  • Loading branch information
chack1172 authored Dec 24, 2024
1 parent d5d2d76 commit e5c8b97
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Barryvdh/Reflection/DocBlock/Type/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ class Collection extends \ArrayObject
protected static $keywords = array(
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
'object', 'mixed', 'array', 'resource', 'void', 'null', 'scalar',
'callback', 'callable', 'false', 'true', 'self', '$this', 'static'
'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'
);

/**
Expand Down Expand Up @@ -194,7 +201,7 @@ protected function expand($type)
return '';
}

if (substr($type, 0, 6) === 'array<' && substr($type, -1) === '>') {
if (preg_match('/^[\w-]+<.*>$/', $type)) {
return $type;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/Barryvdh/Reflection/DocBlock/Type/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ public function provideTypesToExpand($method, $namespace = '\My\Space\\')
'DocBlock[]|int[]',
array($namespace.'DocBlock[]', 'int[]')
),
array(
'array<string>',
array('array<string>')
),
array(
'array<int, string>',
array('array<int, string>')
Expand All @@ -243,6 +247,42 @@ public function provideTypesToExpand($method, $namespace = '\My\Space\\')
'Alias\LinkDescriptor::setLink()',
array('\My\Space\Aliasing\LinkDescriptor::setLink()')
),
array(
'int<0, 100>',
array('int<0, 100>')
),
array(
'non-empty-array<string>',
array('non-empty-array<string>')
),
array(
'non-empty-array<int, string>',
array('non-empty-array<int, string>')
),
array(
'list<string>',
array('list<string>')
),
array(
'non-empty-list<string>',
array('non-empty-list<string>')
),
array(
'key-of<MyClass::ARRAY_CONST>',
array('key-of<MyClass::ARRAY_CONST>')
),
array(
'value-of<MyClass::ARRAY_CONST>',
array('value-of<MyClass::ARRAY_CONST>')
),
array(
'value-of<MyBackedEnum>',
array('value-of<MyBackedEnum>')
),
array(
'iterable<string>',
array('iterable<string>')
),
);
}

Expand Down

0 comments on commit e5c8b97

Please sign in to comment.