@@ -32,9 +32,21 @@ class PhpDocReader
32
32
'resource ' ,
33
33
);
34
34
35
- public function __construct ()
35
+ /**
36
+ * Enable or disable throwing errors when PhpDoc Errors occur (when parsing annotations)
37
+ *
38
+ * @var bool
39
+ */
40
+ private $ ignorePhpDocErrors ;
41
+
42
+ /**
43
+ *
44
+ * @param bool $ignorePhpDocErrors
45
+ */
46
+ public function __construct ($ ignorePhpDocErrors = false )
36
47
{
37
48
$ this ->phpParser = new PhpParser ();
49
+ $ this ->ignorePhpDocErrors = $ ignorePhpDocErrors ;
38
50
}
39
51
40
52
/**
@@ -111,7 +123,7 @@ public function getPropertyClass(ReflectionProperty $property)
111
123
$ found = true ;
112
124
}
113
125
114
- if (!$ found ) {
126
+ if (!$ found && ! $ this -> ignorePhpDocErrors ) {
115
127
throw new AnnotationException (sprintf (
116
128
'The @var annotation on %s::%s contains a non existent class "%s". '
117
129
. 'Did you maybe forget to add a "use" statement for this annotation? ' ,
@@ -122,7 +134,7 @@ public function getPropertyClass(ReflectionProperty $property)
122
134
}
123
135
}
124
136
125
- if (!$ this ->classExists ($ type )) {
137
+ if (!$ this ->classExists ($ type ) && ! $ this -> ignorePhpDocErrors ) {
126
138
throw new AnnotationException (sprintf (
127
139
'The @var annotation on %s::%s contains a non existent class "%s" ' ,
128
140
$ class ->name ,
@@ -219,7 +231,7 @@ public function getParameterClass(ReflectionParameter $parameter)
219
231
$ found = true ;
220
232
}
221
233
222
- if (!$ found ) {
234
+ if (!$ found && ! $ this -> ignorePhpDocErrors ) {
223
235
throw new AnnotationException (sprintf (
224
236
'The @param annotation for parameter "%s" of %s::%s contains a non existent class "%s". '
225
237
. 'Did you maybe forget to add a "use" statement for this annotation? ' ,
@@ -231,7 +243,7 @@ public function getParameterClass(ReflectionParameter $parameter)
231
243
}
232
244
}
233
245
234
- if (!$ this ->classExists ($ type )) {
246
+ if (!$ this ->classExists ($ type ) && ! $ this -> ignorePhpDocErrors ) {
235
247
throw new AnnotationException (sprintf (
236
248
'The @param annotation for parameter "%s" of %s::%s contains a non existent class "%s" ' ,
237
249
$ parameterName ,
0 commit comments