src/PhpDocReader/PhpDocReader.php
public function getPropertyClass(ReflectionProperty $property)
    {
        // Get the content of the @var annotation
        if (preg_match('/@var\s+([^\s]+)/', $property->getDocComment(), $matches)) {
            list(, $type) = $matches;
        } else {
            return null;
        }

        // Ignore primitive types
        if (in_array($type, $this->ignoredTypes)) {
            return null;
        }

        // Ignore types containing special characters ([], <> ...)
        if (! preg_match('/^[a-zA-Z0-9\\\\_]+$/', $type)) {
            return null;
        }

        $class = $property->getDeclaringClass();

        // If the class name is not fully qualified (i.e. doesn't start with a \)
        if ($type[0] !== '\\') {
            // Try to resolve the FQN using the class context
            $resolvedType = $this->tryResolveFqn($type, $class, $property);

            if (!$resolvedType && !$this->ignorePhpDocErrors) {
                throw new AnnotationException(sprintf(
                    'The @var annotation on %s::%s contains a non existent class "%s". '
                        . 'Did you maybe forget to add a "use" statement for this annotation?',
                    $class->name,
                    $property->getName(),
                    $type
                ));
            }
            
            $type = $resolvedType;
        }

        if (!$this->classExists($type) && !$this->ignorePhpDocErrors) {
            throw new AnnotationException(sprintf(
                'The @var annotation on %s::%s contains a non existent class "%s"',
                $class->name,
                $property->getName(),
                $type
            ));
        }

        // Remove the leading \ (FQN shouldn't contain it)
        $type = ltrim($type, '\\');

        return $type;
    }
public function getPropertyClass(ReflectionProperty $property)
    {
        // Get the content of the @var annotation
        if (preg_match('/@var\s+([^\s]+)/', $property->getDocComment(), $matches)) {
            list(, $type) = $matches;
        } else {
            return null;
        }

        // Ignore primitive types
        if (in_array($type, $this->ignoredTypes)) {
            return null;
        }

        // Ignore types containing special characters ([], <> ...)
        if (! preg_match('/^[a-zA-Z0-9\\\\_]+$/', $type)) {
            return null;
        }

        $class = $property->getDeclaringClass();

        // If the class name is not fully qualified (i.e. doesn't start with a \)
        if ($type[0] !== '\\') {
            // Try to resolve the FQN using the class context
            $resolvedType = $this->tryResolveFqn($type, $class, $property);

            if (!$resolvedType && !$this->ignorePhpDocErrors) {
                throw new AnnotationException(sprintf(
                    'The @var annotation on %s::%s contains a non existent class "%s". '
                        . 'Did you maybe forget to add a "use" statement for this annotation?',
                    $class->name,
                    $property->getName(),
                    $type
                ));
            }
            
            $type = $resolvedType;
        }

        if (!$this->classExists($type) && !$this->ignorePhpDocErrors) {
            throw new AnnotationException(sprintf(
                'The @var annotation on %s::%s contains a non existent class "%s"',
                $class->name,
                $property->getName(),
                $type
            ));
        }

        // Remove the leading \ (FQN shouldn't contain it)
        $type = ltrim($type, '\\');

        return $type;
    }
public function getPropertyClass ( ReflectionProperty $ property ) { // Get the content of the @var annotation if ( preg_match ( '/@var\s+([^\s]+)/' , $ property -> getDocComment ( ) , $ matches ) ) { list ( , $ type ) = $ matches ; } else { return null ; } // Ignore primitive types if ( in_array ( $ type , $ this -> ignoredTypes ) ) { return null ; } // Ignore types containing special characters ([], <> ...) if ( ! preg_match ( '/^[a-zA-Z0-9\\\\_]+$/' , $ type ) ) { return null ; } $ class = $ property -> getDeclaringClass ( ) ; // If the class name is not fully qualified (i.e. doesn't start with a \) if ( $ type [ 0 ] !== '\\' ) { // Try to resolve the FQN using the class context $ resolvedType = $ this -> tryResolveFqn ( $ type , $ class , $ property ) ; if ( ! $ resolvedType && ! $ this -> ignorePhpDocErrors ) { throw new AnnotationException ( sprintf ( 'The @var annotation on %s::%s contains a non existent class "%s". ' . 'Did you maybe forget to add a "use" statement for this annotation?' , $ class -> name , $ property -> getName ( ) , $ type ) ) ; } $ type = $ resolvedType ; } if ( ! $ this -> classExists ( $ type ) && ! $ this -> ignorePhpDocErrors ) { throw new AnnotationException ( sprintf ( 'The @var annotation on %s::%s contains a non existent class "%s"' , $ class -> name , $ property -> getName ( ) , $ type ) ) ; } // Remove the leading \ (FQN shouldn't contain it) $ type = ltrim ( $ type , '\\' ) ; return $ type ; }
Parse the docblock of the property to get the class of the var annotation.

@param ReflectionProperty $property

@throws AnnotationException
@return string|null Type of the property (content of var annotation)
Parse the docblock of the property to get the class of the var annotation .