Phan\Analysis\ParameterTypesAnalyzer::analyzeParameterTypes PHP Method

analyzeParameterTypes() public static method

Check method parameters to make sure they're valid
public static analyzeParameterTypes ( CodeBase $code_base, Phan\Language\Element\FunctionInterface $method ) : null
$code_base Phan\CodeBase
$method Phan\Language\Element\FunctionInterface
return null
    public static function analyzeParameterTypes(CodeBase $code_base, FunctionInterface $method)
    {
        // Look at each parameter to make sure their types
        // are valid
        foreach ($method->getParameterList() as $parameter) {
            $union_type = $parameter->getUnionType();
            // 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 ($method instanceof Method) {
                        if ($method->isStatic()) {
                            Issue::maybeEmit($code_base, $method->getContext(), Issue::TemplateTypeStaticMethod, $method->getFileRef()->getLineNumberStart(), (string) $method->getFQSEN());
                        }
                    }
                } else {
                    // Make sure the class exists
                    $type_fqsen = $type->asFQSEN();
                    if (!$code_base->hasClassWithFQSEN($type_fqsen)) {
                        Issue::maybeEmit($code_base, $method->getContext(), Issue::UndeclaredTypeParameter, $method->getFileRef()->getLineNumberStart(), (string) $type_fqsen);
                    }
                }
            }
        }
        if ($method instanceof Method) {
            self::analyzeOverrideSignature($code_base, $method);
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Take a pass over all functions verifying various
  * states.
  *
  * @return null
  */
 public static function analyzeFunctions(CodeBase $code_base)
 {
     $function_count = count($code_base->getFunctionAndMethodSet());
     $i = 0;
     foreach ($code_base->getFunctionAndMethodSet() as $function_or_method) {
         CLI::progress('method', ++$i / $function_count);
         if ($function_or_method->isInternal()) {
             continue;
         }
         DuplicateFunctionAnalyzer::analyzeDuplicateFunction($code_base, $function_or_method);
         ParameterTypesAnalyzer::analyzeParameterTypes($code_base, $function_or_method);
     }
 }
All Usage Examples Of Phan\Analysis\ParameterTypesAnalyzer::analyzeParameterTypes