PHP Class Phan\Language\Type

Inheritance: use trait Phan\Memoize
Show file Open project: etsy/phan Class Usage Examples

Protected Properties

Property Type Description
$name string The name of this type such as 'int' or 'MyClass'
$namespace string The namespace of this type such as '\' or '\Phan\Language'
$template_parameter_type_list UnionType[] A possibly empty list of concrete types that act as parameters to this type if it is a templated type.
$template_parameter_type_list UnionType[] A possibly empty list of concrete types that act as parameters to this type if it is a templated type.

Public Methods

Method Description
__toString ( ) : string
asExpandedTypes ( CodeBase $code_base, integer $recursion_depth ) : UnionType
asExpandedTypes ( CodeBase $code_base, integer $recursion_depth ) : UnionType
asFQSEN ( ) : Phan\Language\FQSEN
asFQSENString ( ) : string
asGenericArrayType ( ) : Type
asUnionType ( ) : UnionType
asUnionType ( ) : UnionType
canCastToType ( Type $type ) : boolean
fromFullyQualifiedString ( string $fully_qualified_string ) : Type
fromInternalTypeName ( string $type_name ) : Type
fromNamespaceAndName ( string $namespace, string $type_name ) : Type
fromObject ( $object ) : Type
fromStringInContext ( string $string, Context $context ) : Type
fromType ( Type $type, UnionType[] $template_parameter_type_list ) : Type
fromType ( Type $type, UnionType[] $template_parameter_type_list ) : Type
genericArrayElementType ( ) : Type
getName ( ) : string
getNamespace ( ) : string
getTemplateParameterTypeList ( ) : UnionType[]
getTemplateParameterTypeList ( ) : UnionType[]
getTemplateParameterTypeMap ( CodeBase $code_base ) : Type[]
hasNamespace ( ) : boolean
hasTemplateParameterTypes ( ) : boolean
isArrayLike ( ) : boolean
isGenericArray ( ) : boolean
isNativeType ( ) : boolean
isScalar ( ) : boolean
isSelfType ( ) : boolean
isSelfTypeString ( string $type_string ) : boolean
isStaticType ( ) : boolean
isSubclassOf ( CodeBase $code_base, Type $parent )

Protected Methods

Method Description
__construct ( string $namespace, string $name, UnionType[] $template_parameter_type_list )
__construct ( string $namespace, string $name, UnionType[] $template_parameter_type_list )
make ( string $namespace, string $type_name, UnionType[] $template_parameter_type_list ) : Type
make ( string $namespace, string $type_name, UnionType[] $template_parameter_type_list ) : Type

Private Methods

Method Description
canonicalNameFromName ( string $name ) : string
isGenericArrayString ( string $type_name ) : boolean
isNativeTypeString ( string $type_name ) : boolean
typeStringComponents ( string $type_string ) : Tuple3

Method Details

__construct() protected method

protected __construct ( string $namespace, string $name, UnionType[] $template_parameter_type_list )
$namespace string The (optional) namespace of the type such as '\' or '\Phan\Language'.
$name string The name of the type such as 'int' or 'MyClass'
$template_parameter_type_list UnionType[] A (possibly empty) list of template parameter types

__construct() protected method

protected __construct ( string $namespace, string $name, UnionType[] $template_parameter_type_list )
$namespace string The (optional) namespace of the type such as '\' or '\Phan\Language'.
$name string The name of the type such as 'int' or 'MyClass'
$template_parameter_type_list UnionType[] A (possibly empty) list of template parameter types

__toString() public method

public __toString ( ) : string
return string A human readable representation of this type

asExpandedTypes() public method

public asExpandedTypes ( CodeBase $code_base, integer $recursion_depth ) : UnionType
$code_base Phan\CodeBase
$recursion_depth integer This thing has a tendency to run-away on me. This tracks how bad I messed up by seeing how far the expanded types go
return UnionType Expands class types to all inherited classes returning a superset of this type.

asExpandedTypes() public method

public asExpandedTypes ( CodeBase $code_base, integer $recursion_depth ) : UnionType
$code_base Phan\CodeBase
$recursion_depth integer This thing has a tendency to run-away on me. This tracks how bad I messed up by seeing how far the expanded types go
return UnionType Expands class types to all inherited classes returning a superset of this type.

asFQSEN() public method

public asFQSEN ( ) : Phan\Language\FQSEN
return Phan\Language\FQSEN A fully-qualified structural element name derived from this type

asFQSENString() public method

public asFQSENString ( ) : string
return string A string representation of this type in FQSEN form.

asGenericArrayType() public method

public asGenericArrayType ( ) : Type
return Type Get a new type which is the generic array version of this type. For instance, 'int' will produce 'int[]'.

asUnionType() public method

public asUnionType ( ) : UnionType
return UnionType A UnionType representing this and only this type

asUnionType() public method

public asUnionType ( ) : UnionType
return UnionType A UnionType representing this and only this type

canCastToType() public method

public canCastToType ( Type $type ) : boolean
$type Type
return boolean True if this Type can be cast to the given Type cleanly

fromFullyQualifiedString() public static method

public static fromFullyQualifiedString ( string $fully_qualified_string ) : Type
$fully_qualified_string string A fully qualified type name
return Type

fromInternalTypeName() public static method

public static fromInternalTypeName ( string $type_name ) : Type
$type_name string The name of the internal type such as 'int'
return Type Get a type for the given type name

fromNamespaceAndName() public static method

public static fromNamespaceAndName ( string $namespace, string $type_name ) : Type
$namespace string A fully qualified namespace
$type_name string The name of the type
return Type A type representing the given namespace and type name.

fromObject() public static method

public static fromObject ( $object ) : Type
return Type Get a type for the given object

fromStringInContext() public static method

public static fromStringInContext ( string $string, Context $context ) : Type
$string string A string representing a type
$context Context The context in which the type string was found
return Type Parse a type from the given string

fromType() public static method

public static fromType ( Type $type, UnionType[] $template_parameter_type_list ) : Type
$type Type The base type of this generic type referencing a generic class
$template_parameter_type_list UnionType[] A map from a template type identifier to a concrete union type
return Type

fromType() public static method

public static fromType ( Type $type, UnionType[] $template_parameter_type_list ) : Type
$type Type The base type of this generic type referencing a generic class
$template_parameter_type_list UnionType[] A map from a template type identifier to a concrete union type
return Type

genericArrayElementType() public method

public genericArrayElementType ( ) : Type
return Type A variation of this type that is not generic. i.e. 'int[]' becomes 'int'.

getName() public method

public getName ( ) : string
return string The name associated with this type

getNamespace() public method

public getNamespace ( ) : string
return string The namespace associated with this type

getTemplateParameterTypeList() public method

public getTemplateParameterTypeList ( ) : UnionType[]
return UnionType[] The set of types filling in template parameter types defined on the class specified by this type.

getTemplateParameterTypeList() public method

public getTemplateParameterTypeList ( ) : UnionType[]
return UnionType[] The set of types filling in template parameter types defined on the class specified by this type.

getTemplateParameterTypeMap() public method

public getTemplateParameterTypeMap ( CodeBase $code_base ) : Type[]
$code_base Phan\CodeBase The code base to look up classes against
return Type[] A map from template type identifier to a concrete type

hasNamespace() public method

public hasNamespace ( ) : boolean
return boolean True if this namespace is defined

hasTemplateParameterTypes() public method

public hasTemplateParameterTypes ( ) : boolean
return boolean True if this type has any template parameter types

isArrayLike() public method

public isArrayLike ( ) : boolean
return boolean True if this type is array-like (is of type array, is a generic array, or implements ArrayAccess).

isGenericArray() public method

public isGenericArray ( ) : boolean
return boolean True if this is a generic type such as 'int[]' or 'string[]'.

isNativeType() public method

public isNativeType ( ) : boolean
return boolean True if this is a native type (like int, string, etc.)

isScalar() public method

See also: Phan\Deprecated\Util::type_scalar Formerly `function type_scalar`
public isScalar ( ) : boolean
return boolean True if all types in this union are scalars

isSelfType() public method

public isSelfType ( ) : boolean
return boolean True if this type is a type referencing the class context in which it exists such as 'static' or 'self'.

isSelfTypeString() public static method

public static isSelfTypeString ( string $type_string ) : boolean
$type_string string A string defining a type such as 'self' or 'int'.
return boolean True if the given type references the class context in which it exists such as 'static' or 'self'.

isStaticType() public method

public isStaticType ( ) : boolean
return boolean True if this type is a type referencing the class context 'static'.

isSubclassOf() public method

public isSubclassOf ( CodeBase $code_base, Type $parent )
$code_base Phan\CodeBase
$parent Type

make() protected static method

protected static make ( string $namespace, string $type_name, UnionType[] $template_parameter_type_list ) : Type
$namespace string The (optional) namespace of the type such as '\' or '\Phan\Language'.
$type_name string
$template_parameter_type_list UnionType[] A (possibly empty) list of template parameter types
return Type A single canonical instance of the given type.

make() protected static method

protected static make ( string $namespace, string $type_name, UnionType[] $template_parameter_type_list ) : Type
$namespace string The (optional) namespace of the type such as '\' or '\Phan\Language'.
$type_name string
$template_parameter_type_list UnionType[] A (possibly empty) list of template parameter types
return Type A single canonical instance of the given type.

Property Details

$name protected property

The name of this type such as 'int' or 'MyClass'
protected string $name
return string

$namespace protected property

The namespace of this type such as '\' or '\Phan\Language'
protected string $namespace
return string

$template_parameter_type_list protected property

A possibly empty list of concrete types that act as parameters to this type if it is a templated type.
protected UnionType[] $template_parameter_type_list
return UnionType[]

$template_parameter_type_list protected property

A possibly empty list of concrete types that act as parameters to this type if it is a templated type.
protected UnionType[],Phan\Language $template_parameter_type_list
return UnionType[]