Phan\Analysis\PropertyTypesAnalyzer::analyzePropertyTypes PHP Method

analyzePropertyTypes() public static method

Check to see if the given Clazz is a duplicate
public static analyzePropertyTypes ( CodeBase $code_base, Clazz $clazz ) : null
$code_base Phan\CodeBase
$clazz Phan\Language\Element\Clazz
return null
    public static function analyzePropertyTypes(CodeBase $code_base, Clazz $clazz)
    {
        foreach ($clazz->getPropertyList($code_base) as $property) {
            try {
                $union_type = $property->getUnionType();
            } catch (IssueException $exception) {
                Issue::maybeEmitInstance($code_base, $property->getContext(), $exception->getIssueInstance());
                continue;
            }
            // Look at each type in the parameter's Union Type
            foreach ($union_type->getTypeSet() as $type) {
                // If its a native type or a reference to
                // self, its OK
                if ($type->isNativeType() || $type->isSelfType()) {
                    continue;
                }
                if ($type instanceof TemplateType) {
                    if ($property->isStatic()) {
                        Issue::maybeEmit($code_base, $property->getContext(), Issue::TemplateTypeStaticProperty, $property->getFileRef()->getLineNumberStart(), (string) $property->getFQSEN());
                    }
                } else {
                    // Make sure the class exists
                    $type_fqsen = $type->asFQSEN();
                    if (!$code_base->hasClassWithFQSEN($type_fqsen) && !$type instanceof TemplateType && (!$property->hasDefiningFQSEN() || $property->getDefiningFQSEN() == $property->getFQSEN())) {
                        Issue::maybeEmit($code_base, $property->getContext(), Issue::UndeclaredTypeProperty, $property->getFileRef()->getLineNumberStart(), (string) $property->getFQSEN(), (string) $type_fqsen);
                    }
                }
            }
        }
    }

Usage Example

Example #1
0
 /**
  * Take a pass over all classes verifying various
  * states.
  *
  * @return null
  */
 public static function analyzeClasses(CodeBase $code_base)
 {
     $class_count = count($code_base->getClassMap());
     // Take a pass to import all details from ancestors
     $i = 0;
     foreach ($code_base->getClassMap() as $fqsen => $class) {
         CLI::progress('classes', ++$i / $class_count);
         if ($class->isInternal()) {
             continue;
         }
         // Make sure the parent classes exist
         ParentClassExistsAnalyzer::analyzeParentClassExists($code_base, $class);
         DuplicateClassAnalyzer::analyzeDuplicateClass($code_base, $class);
         ParentConstructorCalledAnalyzer::analyzeParentConstructorCalled($code_base, $class);
         PropertyTypesAnalyzer::analyzePropertyTypes($code_base, $class);
     }
 }
All Usage Examples Of Phan\Analysis\PropertyTypesAnalyzer::analyzePropertyTypes
PropertyTypesAnalyzer