PHPStan\Broker\Broker::hasClass PHP Method

hasClass() public method

public hasClass ( string $className ) : boolean
$className string
return boolean
    public function hasClass(string $className) : bool
    {
        try {
            return class_exists($className) || interface_exists($className) || trait_exists($className);
        } catch (\Throwable $t) {
            throw new \PHPStan\Broker\ClassAutoloadingException($className, $t);
        }
    }

Usage Example

 private function checkParametersAcceptor(ParametersAcceptor $parametersAcceptor, string $parameterMessage, string $returnMessage) : array
 {
     $errors = [];
     foreach ($parametersAcceptor->getParameters() as $parameter) {
         $type = $parameter->getType();
         if ($type->getClass() !== null && !$this->broker->hasClass($type->getClass())) {
             $errors[] = sprintf($parameterMessage, $parameter->getName(), $type->getClass());
         } elseif ($type instanceof ArrayType) {
             $nestedItemType = $type->getNestedItemType();
             if ($nestedItemType->getItemType()->getClass() !== null && !$this->broker->hasClass($nestedItemType->getItemType()->getClass())) {
                 $errors[] = sprintf($parameterMessage, $parameter->getName(), $type->describe());
             }
         }
     }
     $returnType = $parametersAcceptor->getReturnType();
     if ($returnType->getClass() !== null && !$this->broker->hasClass($returnType->getClass())) {
         $errors[] = sprintf($returnMessage, $returnType->getClass());
     } elseif ($returnType instanceof ArrayType) {
         $nestedItemType = $returnType->getNestedItemType();
         if ($nestedItemType->getItemType()->getClass() !== null && !$this->broker->hasClass($nestedItemType->getItemType()->getClass())) {
             $errors[] = sprintf($returnMessage, $returnType->describe());
         }
     }
     return $errors;
 }
All Usage Examples Of PHPStan\Broker\Broker::hasClass