/** * @param \phan\Context $context * The context in which the structural element lives * * @param string $name, * The name of the typed structural element * * @param UnionType $type, * A '|' delimited set of types satisfyped by this * typed structural element. * * @param int $flags, * The flags property contains node specific flags. It is * always defined, but for most nodes it is always zero. * ast\kind_uses_flags() can be used to determine whether * a certain kind has a meaningful flags value. * * @param int $number_of_required_parameters * * @param int $number_of_optional_parameters * * @param bool $is_dynamic */ public function __construct(Context $context, string $name, UnionType $type, int $flags, int $number_of_required_parameters = 0, int $number_of_optional_parameters = 0, bool $is_dynamic = false) { parent::__construct($context, $name, $type, $flags); $this->number_of_required_parameters = $number_of_required_parameters; $this->number_of_optional_parameters = $number_of_optional_parameters; $this->is_dynamic = $is_dynamic; }
/** * 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()); } } }
/** * @param UnionType $union_type * Set the type represented by this class * * @return null */ public function setUnionType(UnionType $union_type) { // Set the class's type parent::setUnionType($union_type); // Propagate the type to the constructor if (!empty($this->method_map['__construct'])) { // TODO: $code_base isn't defined. f**k. $method = $this->getMethodByNameInContext($code_base, '__construct', $this->getContext()); $method->setUnionType($union_type); } // Propagate the type to the 'this' variable $variable = $this->getContext()->getScope()->getVariableWithName('this'); $variable->setUnionType($union_type); }
/** * @param \phan\Context $context * The context in which the structural element lives * * @param string $name, * The name of the typed structural element * * @param UnionType $type, * A '|' delimited set of types satisfyped by this * typed structural element. * * @param int $flags, * The flags property contains node specific flags. It is * always defined, but for most nodes it is always zero. * ast\kind_uses_flags() can be used to determine whether * a certain kind has a meaningful flags value. */ public function __construct(Context $context, string $name, UnionType $type, int $flags) { parent::__construct($context, $name, $type, $flags); }
/** * @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; }
/** * 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); } } }