Exemple #1
0
 /**
  * Check to see if the given Clazz is a duplicate
  *
  * @return null
  */
 public static function analyzeElementReferenceCounts(CodeBase $code_base, TypedStructuralElement $element, string $issue_type)
 {
     // Don't worry about internal elements
     if ($element->getContext()->isInternal()) {
         return;
     }
     if ($element->getReferenceCount($code_base) < 1) {
         if ($element->hasSuppressIssue($issue_type)) {
             return;
         }
         if ($element instanceof Addressable) {
             Issue::emit($issue_type, $element->getContext()->getFile(), $element->getContext()->getLineNumberStart(), (string) $element->getFQSEN());
         } else {
             Issue::emit($issue_type, $element->getContext()->getFile(), $element->getContext()->getLineNumberStart(), (string) $element);
         }
     }
 }
Exemple #2
0
 /**
  * @return int
  * The number of references to this typed structural element
  */
 public function getReferenceCount(CodeBase $code_base) : int
 {
     $count = parent::getReferenceCount($code_base);
     // A function that maps a list of elements to the
     // total reference count for all elements
     $list_count = function (array $list) use($code_base) {
         return array_reduce($list, function (int $count, TypedStructuralElement $element) use($code_base) {
             return $count + $element->getReferenceCount($code_base);
         }, 0);
     };
     // Sum up counts for all dependent elements
     $count += $list_count($this->getPropertyList($code_base));
     $count += $list_count($this->getMethodMap($code_base));
     $count += $list_count($this->getConstantMap($code_base));
     return $count;
 }
Exemple #3
0
 /**
  * Check to see if the given Clazz is a duplicate
  *
  * @return null
  */
 public static function analyzeElementReferenceCounts(CodeBase $code_base, TypedStructuralElement $element)
 {
     // Don't worry about internal elements
     if ($element->getContext()->isInternal()) {
         return;
     }
     if ($element->getReferenceCount($code_base) < 1) {
         if ($element instanceof Addressable) {
             Log::err(Log::ENOOP, "{$element->getFQSEN()} may have zero references", $element->getContext()->getFile(), $element->getContext()->getLineNumberStart());
         } else {
             Log::err(Log::ENOOP, "{$element} may have zero references", $element->getContext()->getFile(), $element->getContext()->getLineNumberStart());
         }
     }
 }