Skip to content

Commit e5c8b97

Browse files
authored
Handle more PHPDoc type keyworks (#23)
* Added advanced PHPDoc type keyworks * Fixed typed keywords
1 parent d5d2d76 commit e5c8b97

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/Barryvdh/Reflection/DocBlock/Type/Collection.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ class Collection extends \ArrayObject
3737
protected static $keywords = array(
3838
'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
3939
'object', 'mixed', 'array', 'resource', 'void', 'null', 'scalar',
40-
'callback', 'callable', 'false', 'true', 'self', '$this', 'static'
40+
'callback', 'callable', 'false', 'true', 'self', '$this', 'static',
41+
'array-key', 'number', 'iterable', 'pure-callable', 'closed-resource',
42+
'open-resource', 'positive-int', 'negative-int', 'non-positive-int',
43+
'non-negative-int', 'non-zero-int', 'non-empty-array', 'list',
44+
'non-empty-list', 'key-of', 'value-of', 'template-type', 'class-string',
45+
'callable-string', 'numeric-string', 'non-empty-string',
46+
'non-falsy-string', 'literal-string', 'lowercase-string', 'never',
47+
'never-return', 'never-returns', 'no-return', 'int-mask', 'int-mask-of'
4148
);
4249

4350
/**
@@ -194,7 +201,7 @@ protected function expand($type)
194201
return '';
195202
}
196203

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

tests/Barryvdh/Reflection/DocBlock/Type/CollectionTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ public function provideTypesToExpand($method, $namespace = '\My\Space\\')
219219
'DocBlock[]|int[]',
220220
array($namespace.'DocBlock[]', 'int[]')
221221
),
222+
array(
223+
'array<string>',
224+
array('array<string>')
225+
),
222226
array(
223227
'array<int, string>',
224228
array('array<int, string>')
@@ -243,6 +247,42 @@ public function provideTypesToExpand($method, $namespace = '\My\Space\\')
243247
'Alias\LinkDescriptor::setLink()',
244248
array('\My\Space\Aliasing\LinkDescriptor::setLink()')
245249
),
250+
array(
251+
'int<0, 100>',
252+
array('int<0, 100>')
253+
),
254+
array(
255+
'non-empty-array<string>',
256+
array('non-empty-array<string>')
257+
),
258+
array(
259+
'non-empty-array<int, string>',
260+
array('non-empty-array<int, string>')
261+
),
262+
array(
263+
'list<string>',
264+
array('list<string>')
265+
),
266+
array(
267+
'non-empty-list<string>',
268+
array('non-empty-list<string>')
269+
),
270+
array(
271+
'key-of<MyClass::ARRAY_CONST>',
272+
array('key-of<MyClass::ARRAY_CONST>')
273+
),
274+
array(
275+
'value-of<MyClass::ARRAY_CONST>',
276+
array('value-of<MyClass::ARRAY_CONST>')
277+
),
278+
array(
279+
'value-of<MyBackedEnum>',
280+
array('value-of<MyBackedEnum>')
281+
),
282+
array(
283+
'iterable<string>',
284+
array('iterable<string>')
285+
),
246286
);
247287
}
248288

0 commit comments

Comments
 (0)