Skip to content

Commit

Permalink
#45 refactored logic - split ignored annotation checking into private…
Browse files Browse the repository at this point in the history
… method, corrected property/parameter documentation
  • Loading branch information
Ocramius committed Oct 24, 2016
1 parent 5c18969 commit eb3de72
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions lib/Doctrine/Common/Annotations/DocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ final class DocParser
* The names must be the raw names as used in the class, not the fully qualified
* class names.
*
* @var array
* @var bool[] indexed by annotation name
*/
private $ignoredAnnotationNames = array();

/**
* A list with annotations in namespaced format
* that are not causing exceptions when not resolved to an annotation class.
*
* @var array
* @var bool[] indexed by namespace name
*/
private $ignoredAnnotationNamespaces = array();

Expand Down Expand Up @@ -250,7 +250,7 @@ public function __construct()
* The names are supposed to be the raw names as used in the class, not the
* fully qualified class names.
*
* @param array $names
* @param bool[] $names indexed by annotation name
*
* @return void
*/
Expand All @@ -262,7 +262,7 @@ public function setIgnoredAnnotationNames(array $names)
/**
* Sets the annotation namespaces that are ignored during the parsing process.
*
* @param array $ignoredAnnotationNamespaces
* @param bool[] $ignoredAnnotationNamespaces indexed by annotation namespace name
*
* @return void
*/
Expand Down Expand Up @@ -716,18 +716,10 @@ private function Annotation()
}

if ( ! $found) {
if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
if ($this->isIgnoredAnnotation($name)) {
return false;
}

foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
$ignoredAnnotationNamespace = rtrim($ignoredAnnotationNamespace, '\\') . '\\';

if (0 === stripos($name, $ignoredAnnotationNamespace) || 0 === stripos($name . '\\', $ignoredAnnotationNamespace)) {
return false;
}
}

throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?', $name, $this->context));
}
}
Expand Down Expand Up @@ -1163,4 +1155,28 @@ private function ArrayEntry()

return array(null, $this->Value());
}

/**
* Checks whether the given $name matches any ignored annotation name or namespace
*
* @param string $name
*
* @return bool
*/
private function isIgnoredAnnotation($name)
{
if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
return true;
}

foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
$ignoredAnnotationNamespace = rtrim($ignoredAnnotationNamespace, '\\') . '\\';

if (0 === stripos(rtrim($name, '\\') . '\\', $ignoredAnnotationNamespace)) {
return true;
}
}

return false;
}
}

0 comments on commit eb3de72

Please sign in to comment.