Phan\AST\ContextNode::getClassList PHP Method

getClassList() public method

public getClassList ( boolean $ignore_missing_classes = false ) : Clazz[]
$ignore_missing_classes boolean If set to true, missing classes will be ignored and exceptions will be inhibited
return Phan\Language\Element\Clazz[] A list of classes representing the non-native types associated with the given node
    public function getClassList($ignore_missing_classes = false)
    {
        $union_type = UnionTypeVisitor::unionTypeFromClassNode($this->code_base, $this->context, $this->node);
        $class_list = [];
        if ($ignore_missing_classes) {
            try {
                foreach ($union_type->asClassList($this->code_base, $this->context) as $i => $clazz) {
                    $class_list[] = $clazz;
                }
            } catch (CodeBaseException $exception) {
                // swallow it
            }
        } else {
            foreach ($union_type->asClassList($this->code_base, $this->context) as $i => $clazz) {
                $class_list[] = $clazz;
            }
        }
        return $class_list;
    }

Usage Example

Beispiel #1
0
 /**
  * @param Node $node
  * A node to parse
  *
  * @return Context
  * A new or an unchanged context resulting from
  * parsing the node
  */
 public function visitNew(Node $node) : Context
 {
     try {
         $context_node = new ContextNode($this->code_base, $this->context, $node);
         $method = $context_node->getMethod('__construct', false);
         // Add a reference to each class this method
         // could be called on
         foreach ($context_node->getClassList() as $class) {
             $class->addReference($this->context);
             if ($class->isDeprecated()) {
                 $this->emitIssue(Issue::DeprecatedClass, $node->lineno ?? 0, (string) $class->getFQSEN(), $class->getContext()->getFile(), (string) $class->getContext()->getLineNumberStart());
             }
         }
         $this->analyzeCallToMethod($this->code_base, $method, $node);
         $class_list = $context_node->getClassList();
         foreach ($class_list as $class) {
             // Make sure we're not instantiating an abstract
             // class
             if ($class->isAbstract() && (!$this->context->isInClassScope() || $class->getFQSEN() != $this->context->getClassFQSEN())) {
                 $this->emitIssue(Issue::TypeInstantiateAbstract, $node->lineno ?? 0, (string) $class->getFQSEN());
             }
             // Make sure we're not instantiating an interface
             if ($class->isInterface()) {
                 $this->emitIssue(Issue::TypeInstantiateInterface, $node->lineno ?? 0, (string) $class->getFQSEN());
             }
         }
     } catch (IssueException $exception) {
         Issue::maybeEmitInstance($this->code_base, $this->context, $exception->getIssueInstance());
     } catch (\Exception $exception) {
         // If we can't figure out what kind of a call
         // this is, don't worry about it
         return $this->context;
     }
     return $this->context;
 }