Skip to content

Commit a7cee5b

Browse files
committed
Merge pull request #4 from kdubois/master
Add option to ignore annotation misconfigurations
2 parents 0da1a14 + b3dc84a commit a7cee5b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/PhpDocReader/PhpDocReader.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,21 @@ class PhpDocReader
3232
'resource',
3333
);
3434

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)
3647
{
3748
$this->phpParser = new PhpParser();
49+
$this->ignorePhpDocErrors = $ignorePhpDocErrors;
3850
}
3951

4052
/**
@@ -111,7 +123,7 @@ public function getPropertyClass(ReflectionProperty $property)
111123
$found = true;
112124
}
113125

114-
if (!$found) {
126+
if (!$found && !$this->ignorePhpDocErrors) {
115127
throw new AnnotationException(sprintf(
116128
'The @var annotation on %s::%s contains a non existent class "%s". '
117129
. 'Did you maybe forget to add a "use" statement for this annotation?',
@@ -122,7 +134,7 @@ public function getPropertyClass(ReflectionProperty $property)
122134
}
123135
}
124136

125-
if (!$this->classExists($type)) {
137+
if (!$this->classExists($type) && !$this->ignorePhpDocErrors) {
126138
throw new AnnotationException(sprintf(
127139
'The @var annotation on %s::%s contains a non existent class "%s"',
128140
$class->name,
@@ -219,7 +231,7 @@ public function getParameterClass(ReflectionParameter $parameter)
219231
$found = true;
220232
}
221233

222-
if (!$found) {
234+
if (!$found && !$this->ignorePhpDocErrors) {
223235
throw new AnnotationException(sprintf(
224236
'The @param annotation for parameter "%s" of %s::%s contains a non existent class "%s". '
225237
. 'Did you maybe forget to add a "use" statement for this annotation?',
@@ -231,7 +243,7 @@ public function getParameterClass(ReflectionParameter $parameter)
231243
}
232244
}
233245

234-
if (!$this->classExists($type)) {
246+
if (!$this->classExists($type) && !$this->ignorePhpDocErrors) {
235247
throw new AnnotationException(sprintf(
236248
'The @param annotation for parameter "%s" of %s::%s contains a non existent class "%s"',
237249
$parameterName,

0 commit comments

Comments
 (0)