File tree 3 files changed +94
-0
lines changed
tests/UnitTest/PhpDocReader
3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ public function getPropertyClass(ReflectionProperty $property)
74
74
return null ;
75
75
}
76
76
77
+ // Ignore types containing special characters ([], <> ...)
78
+ if (! preg_match ('/^[a-zA-Z0-9 \\\\]+$/ ' , $ type )) {
79
+ return null ;
80
+ }
81
+
77
82
$ class = $ property ->getDeclaringClass ();
78
83
79
84
// If the class name is not fully qualified (i.e. doesn't start with a \)
@@ -175,6 +180,11 @@ public function getParameterClass(ReflectionParameter $parameter)
175
180
return null ;
176
181
}
177
182
183
+ // Ignore types containing special characters ([], <> ...)
184
+ if (! preg_match ('/^[a-zA-Z0-9 \\\\]+$/ ' , $ type )) {
185
+ return null ;
186
+ }
187
+
178
188
$ class = $ parameter ->getDeclaringClass ();
179
189
180
190
// If the class name is not fully qualified (i.e. doesn't start with a \)
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace UnitTest \PhpDocReader \FixturesUnknownTypes ;
4
+
5
+ class Class1
6
+ {
7
+ /**
8
+ * @var
9
+ */
10
+ public $ empty ;
11
+
12
+ /**
13
+ * @var Foo[]
14
+ */
15
+ public $ array ;
16
+
17
+ /**
18
+ * @var array<Foo>
19
+ */
20
+ public $ generics ;
21
+
22
+ /**
23
+ * @var Foo|Bar
24
+ */
25
+ public $ multiple ;
26
+
27
+ /**
28
+ * @param $empty
29
+ * @param Foo[] $array
30
+ * @param array<Foo> $generics
31
+ * @param Foo|Bar $multiple
32
+ */
33
+ public function foo (
34
+ $ empty ,
35
+ $ array ,
36
+ $ generics ,
37
+ $ multiple
38
+ ) {
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace UnitTest \PhpDocReader ;
4
+
5
+ use PhpDocReader \PhpDocReader ;
6
+ use ReflectionParameter ;
7
+
8
+ /**
9
+ * @see https://github.com/mnapoli/PhpDocReader/issues/3
10
+ */
11
+ class UnknownTypesTest extends \PHPUnit_Framework_TestCase
12
+ {
13
+ /**
14
+ * @dataProvider typeProvider
15
+ */
16
+ public function testProperties ($ type )
17
+ {
18
+ $ parser = new PhpDocReader ();
19
+ $ class = new \ReflectionClass ('UnitTest\PhpDocReader\FixturesUnknownTypes\Class1 ' );
20
+
21
+ $ this ->assertNull ($ parser ->getPropertyClass ($ class ->getProperty ($ type )));
22
+ }
23
+
24
+ /**
25
+ * @dataProvider typeProvider
26
+ */
27
+ public function testMethodParameters ($ type )
28
+ {
29
+ $ parser = new PhpDocReader ();
30
+ $ parameter = new ReflectionParameter (array ('UnitTest\PhpDocReader\FixturesUnknownTypes\Class1 ' , 'foo ' ), $ type );
31
+
32
+ $ this ->assertNull ($ parser ->getParameterClass ($ parameter ));
33
+ }
34
+
35
+ public function typeProvider ()
36
+ {
37
+ return array (
38
+ 'empty ' => array ('empty ' ),
39
+ 'array ' => array ('array ' ),
40
+ 'generics ' => array ('generics ' ),
41
+ 'multiple ' => array ('multiple ' ),
42
+ );
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments