当前位置: 首页>>代码示例>>PHP>>正文


PHP CodeBase::getClassByFQSEN方法代码示例

本文整理汇总了PHP中Phan\CodeBase::getClassByFQSEN方法的典型用法代码示例。如果您正苦于以下问题:PHP CodeBase::getClassByFQSEN方法的具体用法?PHP CodeBase::getClassByFQSEN怎么用?PHP CodeBase::getClassByFQSEN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phan\CodeBase的用法示例。


在下文中一共展示了CodeBase::getClassByFQSEN方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMethodInCodeBase

 public function testMethodInCodeBase()
 {
     $context = $this->contextForCode("\n                namespace A;\n                Class B {\n                    public function c() {\n                        return 42;\n                    }\n                }\n            ");
     $class_fqsen = FullyQualifiedClassName::fromFullyQualifiedString('\\A\\b');
     self::assertTrue($this->code_base->hasClassWithFQSEN($class_fqsen), "Class with FQSEN {$class_fqsen} not found");
     $clazz = $this->code_base->getClassByFQSEN($class_fqsen);
     self::assertTrue($clazz->hasMethodWithName($this->code_base, 'c'), "Method with FQSEN not found");
 }
开发者ID:Jvbzephir,项目名称:phan,代码行数:8,代码来源:AnalyzerTest.php

示例2: visitProp

 /**
  * @param Node $node
  * A node of the type indicated by the method name that we'd
  * like to figure out the type that it produces.
  *
  * @return string
  * The class name represented by the given call
  */
 public function visitProp(Node $node) : string
 {
     if (!($node->children['expr']->kind == \ast\AST_VAR && !$node->children['expr']->children['name'] instanceof Node)) {
         return '';
     }
     // $var->prop->method()
     $var = $node->children['expr'];
     $class = null;
     if ($var->children['name'] == 'this') {
         // If we're not in a class scope, 'this' won't work
         if (!$this->context->isInClassScope()) {
             Log::err(Log::ESTATIC, 'Using $this when not in object context', $this->context->getFile(), $node->lineno);
             return '';
         }
         // $this->$node->method()
         if ($node->children['prop'] instanceof Node) {
             // Too hard. Giving up.
             return '';
         }
         $class = $this->context->getClassInScope($this->code_base);
     } else {
         // Get the list of viable class types for the
         // variable
         $union_type = AST::varUnionType($this->context, $var)->nonNativeTypes()->nonGenericArrayTypes();
         if ($union_type->isEmpty()) {
             return '';
         }
         $class_fqsen = $union_type->head()->asFQSEN();
         if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
             return '';
         }
         $class = $this->code_base->getClassByFQSEN($class_fqsen);
     }
     $property_name = $node->children['prop'];
     if (!$class->hasPropertyWithName($this->code_base, $property_name)) {
         // If we can't find the property, there's
         // no type. Thie issue should be caught
         // elsewhere.
         return '';
     }
     try {
         $property = $class->getPropertyByNameInContext($this->code_base, $property_name, $this->context);
     } catch (AccessException $exception) {
         Log::err(Log::EACCESS, $exception->getMessage(), $this->context->getFile(), $node->lineno);
         return '';
     }
     $union_type = $property->getUnionType()->nonNativeTypes();
     if ($union_type->isEmpty()) {
         // If we don't have a type on the property we
         // can't figure out the class type.
         return '';
     } else {
         // Return the first type on the property
         // that could be a reference to a class
         return (string) $union_type->head()->asFQSEN();
     }
     // No such property was found, or none were classes
     // that could be found
     return '';
 }
开发者ID:zhangf911,项目名称:phan,代码行数:68,代码来源:MethodCallVisitor.php

示例3: analyzeParentConstructorCalled

 /**
  * Check to see if the given Clazz is a duplicate
  *
  * @return null
  */
 public static function analyzeParentConstructorCalled(CodeBase $code_base, Clazz $clazz)
 {
     // Only look at classes configured to require a call
     // to its parent constructor
     if (!in_array($clazz->getName(), Config::get()->parent_constructor_required)) {
         return;
     }
     // Don't worry about internal classes
     if ($clazz->isInternal()) {
         return;
     }
     // Don't worry if there's no parent class
     if (!$clazz->hasParentClassFQSEN()) {
         return;
     }
     if (!$code_base->hasClassWithFQSEN($clazz->getParentClassFQSEN())) {
         // This is an error, but its caught elsewhere. We'll
         // just roll through looking for other errors
         return;
     }
     $parent_clazz = $code_base->getClassByFQSEN($clazz->getParentClassFQSEN());
     if (!$parent_clazz->isAbstract() && !$clazz->getIsParentConstructorCalled()) {
         Issue::emit(Issue::TypeParentConstructorCalled, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $clazz->getFQSEN(), (string) $parent_clazz->getFQSEN());
     }
 }
开发者ID:actank,项目名称:phan,代码行数:30,代码来源:ParentConstructorCalled.php

示例4: analyzeDuplicateClass

 /**
  * Check to see if the given Clazz is a duplicate
  *
  * @return null
  */
 public static function analyzeDuplicateClass(CodeBase $code_base, Clazz $clazz)
 {
     // Determine if its a duplicate by looking to see if
     // the FQSEN is suffixed with an alternate ID.
     if (!$clazz->getFQSEN()->isAlternate()) {
         return;
     }
     $original_fqsen = $clazz->getFQSEN()->getCanonicalFQSEN();
     if (!$code_base->hasClassWithFQSEN($original_fqsen)) {
         // If there's a missing class we'll catch that
         // elsewhere
         return;
     }
     // Get the original class
     $original_class = $code_base->getClassByFQSEN($original_fqsen);
     // Check to see if the original definition was from
     // an internal class
     if ($original_class->isInternal()) {
         Log::err(Log::EREDEF, "{$clazz} defined at " . "{$clazz->getContext()->getFile()}:{$clazz->getContext()->getLineNumberStart()} " . "was previously defined as {$original_class} internally", $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
         // Otherwise, print the coordinates of the original
         // definition
     } else {
         Log::err(Log::EREDEF, "{$clazz} defined at " . "{$clazz->getContext()->getFile()}:{$clazz->getContext()->getLineNumberStart()} " . "was previously defined as {$original_class} at " . "{$original_class->getContext()->getFile()}:{$original_class->getContext()->getLineNumberStart()}", $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart());
     }
     return;
 }
开发者ID:mgonyan,项目名称:phan,代码行数:31,代码来源:DuplicateClass.php

示例5: analyzeDuplicateClass

 /**
  * Check to see if the given Clazz is a duplicate
  *
  * @return null
  */
 public static function analyzeDuplicateClass(CodeBase $code_base, Clazz $clazz)
 {
     // Determine if its a duplicate by looking to see if
     // the FQSEN is suffixed with an alternate ID.
     if (!$clazz->getFQSEN()->isAlternate()) {
         return;
     }
     $original_fqsen = $clazz->getFQSEN()->getCanonicalFQSEN();
     if (!$code_base->hasClassWithFQSEN($original_fqsen)) {
         // If there's a missing class we'll catch that
         // elsewhere
         return;
     }
     // Get the original class
     $original_class = $code_base->getClassByFQSEN($original_fqsen);
     // Check to see if the original definition was from
     // an internal class
     if ($original_class->isInternal()) {
         Issue::emit(Issue::RedefineClassInternal, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $clazz, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $original_class);
         // Otherwise, print the coordinates of the original
         // definition
     } else {
         Issue::emit(Issue::RedefineClass, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $clazz, $clazz->getContext()->getFile(), $clazz->getContext()->getLineNumberStart(), (string) $original_class, $original_class->getContext()->getFile(), $original_class->getContext()->getLineNumberStart());
     }
     return;
 }
开发者ID:actank,项目名称:phan,代码行数:31,代码来源:DuplicateClass.php

示例6: visitMethodCall

 /**
  * Visit a node with kind `\ast\AST_METHOD_CALL`
  *
  * @param Node $node
  * A node of the type indicated by the method name that we'd
  * like to figure out the type that it produces.
  *
  * @return UnionType
  * The set of types that are possibly produced by the
  * given node
  */
 public function visitMethodCall(Node $node) : UnionType
 {
     $class_name = AST::classNameFromNode($this->context, $this->code_base, $node);
     if (empty($class_name)) {
         return new UnionType();
     }
     $class_fqsen = FullyQualifiedClassName::fromstringInContext($class_name, $this->context);
     assert($this->code_base->hasClassWithFQSEN($class_fqsen), "Class {$class_fqsen} must exist");
     $clazz = $this->code_base->getClassByFQSEN($class_fqsen);
     $method_name = $node->children['method'];
     // Give up on any complicated nonsense where the
     // method name is a variable such as in
     // `$variable->$function_name()`.
     if ($method_name instanceof Node) {
         return new UnionType();
     }
     // Method names can some times turn up being
     // other method calls.
     assert(is_string($method_name), "Method name must be a string. Something else given.");
     if (!$clazz->hasMethodWithName($this->code_base, $method_name)) {
         Log::err(Log::EUNDEF, "call to undeclared method {$class_fqsen}->{$method_name}()", $this->context->getFile(), $node->lineno);
         return new UnionType();
     }
     $method = $clazz->getMethodByNameInContext($this->code_base, $method_name, $this->context);
     return $method->getUnionType();
 }
开发者ID:themarios,项目名称:phan,代码行数:37,代码来源:UnionTypeVisitor.php

示例7: getDefiningClass

 /**
  * @return Clazz
  * The class that defined this element
  *
  * @throws CodeBaseException
  * An exception may be thrown if we can't find the
  * class
  */
 public function getDefiningClass(CodeBase $code_base) : Clazz
 {
     $class_fqsen = $this->getDefiningClassFQSEN();
     if (!$code_base->hasClassWithFQSEN($class_fqsen)) {
         throw new CodeBaseException($class_fqsen, "Defining class {$class_fqsen} for {$this->getFQSEN()} not found");
     }
     return $code_base->getClassByFQSEN($class_fqsen);
 }
开发者ID:black-silence,项目名称:phan,代码行数:16,代码来源:ClassElement.php

示例8: visitNew

 public function visitNew(Node $node) : bool
 {
     if (!$this->classExists()) {
         return $this->classExistsOrIsNative($node);
     }
     $clazz = $this->code_base->getClassByFQSEN($this->class_fqsen);
     if ($clazz->isAbstract()) {
         if (!$this->context->hasClassFQSEN() || $clazz->getFQSEN() != $this->context->getClassFQSEN()) {
             Log::err(Log::ETYPE, "Cannot instantiate abstract class {$this->class_name}", $this->context->getFile(), $node->lineno);
             return false;
         }
         return true;
     }
     if ($clazz->isInterface()) {
         if (!UnionType::fromStringInContext($this->class_name, $this->context)->isNativeType()) {
             Log::err(Log::ETYPE, "Cannot instantiate interface {$this->class_name}", $this->context->getFile(), $node->lineno);
             return false;
         }
     }
     return true;
 }
开发者ID:blackreaven,项目名称:phan,代码行数:21,代码来源:ClassNameValidationVisitor.php

示例9: visitStaticProp

 public function visitStaticProp(Node $node) : bool
 {
     if (!$this->classExists()) {
         return $this->classExistsOrIsNative($node);
     }
     $clazz = $this->code_base->getClassByFQSEN($this->class_fqsen);
     if (is_string($node->children['prop']) && !$clazz->hasPropertyWithName($this->code_base, $node->children['prop'])) {
         Log::err(Log::ETYPE, "Access to undeclared static property {$node->children['prop']} on {$this->class_name}", $this->context->getFile(), $node->lineno);
         return false;
     }
     return true;
 }
开发者ID:VladaPetrovic,项目名称:phan,代码行数:12,代码来源:ValidationVisitor.php

示例10: classListFromNode

 /**
  * @return Clazz[]
  * A list of classes associated with the given node
  *
  * @throws CodeBaseException
  * An exception is thrown if we can't find a class for
  * the given type
  */
 private function classListFromNode(Node $node)
 {
     // Get the types associated with the node
     $union_type = self::unionTypeFromNode($this->code_base, $this->context, $node);
     // Iterate over each viable class type to see if any
     // have the constant we're looking for
     foreach ($union_type->nonNativeTypes()->getTypeList() as $class_type) {
         // Get the class FQSEN
         $class_fqsen = $class_type->asFQSEN();
         // See if the class exists
         if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
             throw new CodeBaseException($class_fqsen, "reference to undeclared class {$class_fqsen}");
         }
         (yield $this->code_base->getClassByFQSEN($class_fqsen));
     }
 }
开发者ID:gitter-badger,项目名称:phan,代码行数:24,代码来源:UnionTypeVisitor.php

示例11: classListFromNode

 /**
  * @return Clazz[]
  * A list of classes associated with the given node
  *
  * @throws IssueException
  * An exception is thrown if we can't find a class for
  * the given type
  */
 private function classListFromNode(Node $node)
 {
     // Get the types associated with the node
     $union_type = self::unionTypeFromNode($this->code_base, $this->context, $node);
     // Iterate over each viable class type to see if any
     // have the constant we're looking for
     foreach ($union_type->nonNativeTypes()->getTypeSet() as $class_type) {
         // Get the class FQSEN
         $class_fqsen = $class_type->asFQSEN();
         // See if the class exists
         if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
             throw new IssueException(Issue::fromType(Issue::UndeclaredClassReference)($this->context->getFile(), $node->lineno ?? 0, [(string) $class_fqsen]));
         }
         (yield $this->code_base->getClassByFQSEN($class_fqsen));
     }
 }
开发者ID:black-silence,项目名称:phan,代码行数:24,代码来源:UnionTypeVisitor.php

示例12: getClass

 /**
  * @param bool $validate_class_name
  * If true, we'll validate that the name of the class
  * is valid.
  *
  * @return Clazz
  * The class being referenced in the given node in
  * the given context
  *
  * @throws NodeException
  * An exception is thrown if we can't understand the node
  *
  * @throws CodeBaseExtension
  * An exception is thrown if we can't find the referenced
  * class
  *
  * @throws TypeException
  * An exception may be thrown if the only viable candidate
  * is a non-class type.
  */
 public function getClass(bool $validate_class_name = true) : Clazz
 {
     // Figure out the name of the class
     $class_name = $this->getClassName($validate_class_name);
     // If we can't figure out the class name (which happens
     // from time to time), then give up
     if (empty($class_name)) {
         throw new NodeException($this->node, 'Could not find class name');
     }
     $class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $this->context);
     // Check to see if the class actually exists
     if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
         throw new CodeBaseException($class_fqsen, "Can't find class {$class_fqsen}");
     }
     $class = $this->code_base->getClassByFQSEN($class_fqsen);
     return $class;
 }
开发者ID:kangkot,项目名称:phan,代码行数:37,代码来源:ContextNode.php

示例13: getClassInScope

 /**
  * @param CodeBase $code_base
  * The global code base holding all state
  *
  * @return Clazz
  * Get the class in this scope, or fail real hard
  */
 public function getClassInScope(CodeBase $code_base) : Clazz
 {
     assert($this->isInClassScope(), "Must be in class scope to get class");
     if (!$code_base->hasClassWithFQSEN($this->getClassFQSEN())) {
         Log::err(Log::EFATAL, "Cannot find class with FQSEN {$this->getClassFQSEN()} in context {$this}", $this->getFile(), 0);
     }
     return $code_base->getClassByFQSEN($this->getClassFQSEN());
 }
开发者ID:gitter-badger,项目名称:phan,代码行数:15,代码来源:Context.php

示例14: alternateGenerator

 /**
  * @return Clazz[]
  * The set of all alternates to this class
  */
 public function alternateGenerator(CodeBase $code_base) : \Generator
 {
     $alternate_id = 0;
     $fqsen = $this->getFQSEN();
     while ($code_base->hasClassWithFQSEN($fqsen)) {
         (yield $code_base->getClassByFQSEN($fqsen));
         $fqsen = $fqsen->withAlternateId(++$alternate_id);
     }
 }
开发者ID:hslatman,项目名称:phan,代码行数:13,代码来源:Clazz.php

示例15: asClassList

 /**
  * @return Clazz[]
  * A list of classes representing the non-native types
  * associated with this UnionType
  *
  * @throws CodeBaseException
  * An exception is thrown if a non-native type does not have
  * an associated class
  */
 public function asClassList(CodeBase $code_base)
 {
     // Iterate over each viable class type to see if any
     // have the constant we're looking for
     foreach ($this->nonNativeTypes()->getTypeList() as $class_type) {
         // Get the class FQSEN
         $class_fqsen = $class_type->asFQSEN();
         // See if the class exists
         if (!$code_base->hasClassWithFQSEN($class_fqsen)) {
             throw new CodeBaseException($class_fqsen, "Cannot find class {$class_fqsen}");
         }
         (yield $code_base->getClassByFQSEN($class_fqsen));
     }
 }
开发者ID:kangkot,项目名称:phan,代码行数:23,代码来源:UnionType.php


注:本文中的Phan\CodeBase::getClassByFQSEN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。