PHP Class Phan\Language\UnionType

Inheritance: implements Serializable, use trait Phan\Memoize
Datei anzeigen Open project: etsy/phan Class Usage Examples

Public Methods

Method Description
__clone ( ) : null After a clone is called on this object, clone our deep objects.
__construct ( Type[] | Iterator $type_list = null )
__construct ( Type[] | Iterator $type_list = null )
__toString ( ) : string
addType ( Type $type ) : void Add a type name to the list of types
addType ( Type $type ) : void Add a type name to the list of types
addUnionType ( UnionType $union_type ) : null Add the given types to this type
asClassList ( CodeBase $code_base, Context $context ) : Generator | Clazz[]
asExpandedTypes ( CodeBase $code_base, integer $recursion_depth ) : UnionType
asGenericArrayTypes ( ) : UnionType
canCastToExpandedUnionType ( UnionType $target, CodeBase $code_base ) : boolean
canCastToUnionType ( UnionType $target ) : boolean
fromFullyQualifiedString ( string $fully_qualified_string ) : UnionType
fromNode ( Context $context, CodeBase $code_base, ast\Node | string | null $node, boolean $should_catch_issue_exception = true ) : UnionType
fromStringInContext ( string $type_string, Context $context ) : UnionType
genericArrayElementTypes ( ) : UnionType Takes "a|b[]|c|d[]|e" and returns "b|d"
getTemplateParameterTypeList ( ) : array
getTemplateParameterTypeMap ( CodeBase $code_base ) : array
getTypeSet ( ) : Phan\Library\Set
hasAnyType ( array $type_list ) : boolean
hasArrayLike ( ) : boolean
hasGenericArray ( ) : boolean
hasSelfType ( ) : boolean
hasStaticType ( ) : boolean
hasTemplateType ( ) : boolean
hasType ( Type $type ) : boolean
hasType ( Type $type ) : boolean
internalFunctionSignatureMap ( ) : array
internalFunctionSignatureMapForFQSEN ( FullyQualifiedMethodName | FullyQualifiedFunctionName $function_fqsen ) : array A list of types for parameters associated with the given builtin function with the given name
internalPropertyMapForClassName ( string $class_name ) : array
isEmpty ( ) : boolean
isEqualTo ( UnionType $union_type ) : boolean
isGenericArray ( ) : boolean
isNativeType ( ) : boolean
isScalar ( ) : boolean
isType ( Type $type ) : boolean
isType ( Type $type ) : boolean
nonArrayTypes ( ) : UnionType Takes "a|b[]|c|d[]|e|array|ArrayAccess" and returns "a|c|e|ArrayAccess"
nonGenericArrayTypes ( ) : UnionType Takes "a|b[]|c|d[]|e" and returns "a|c|e"
nonNativeTypes ( ) : UnionType
removeType ( Type $type ) : void Remove a type name to the list of types
removeType ( Type $type ) : void Remove a type name to the list of types
serialize ( ) : string As per the Serializable interface
typeCount ( ) : integer
unserialize ( string $serialized ) : void As per the Serializable interface
withStaticResolvedInContext ( Context $context ) : UnionType
withTemplateParameterTypeMap ( array $template_parameter_type_map ) : UnionType

Private Methods

Method Description
hasGenericType ( ) : boolean
internalPropertyMap ( ) : array

Method Details

__clone() public method

After a clone is called on this object, clone our deep objects.
public __clone ( ) : null
return null

__construct() public method

public __construct ( Type[] | Iterator $type_list = null )
$type_list Type[] | Iterator An optional list of types represented by this union

__construct() public method

public __construct ( Type[] | Iterator $type_list = null )
$type_list Type[] | Iterator An optional list of types represented by this union

__toString() public method

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

addType() public method

Add a type name to the list of types
public addType ( Type $type ) : void
$type Type
return void

addType() public method

Add a type name to the list of types
public addType ( Type $type ) : void
$type Type
return void

addUnionType() public method

Add the given types to this type
public addUnionType ( UnionType $union_type ) : null
$union_type UnionType
return null

asClassList() public method

public asClassList ( CodeBase $code_base, Context $context ) : Generator | Clazz[]
$code_base Phan\CodeBase The code base in which to find classes
$context Context The context in which we're resolving this union type.
return Generator | Phan\Language\Element\Clazz[] A list of classes representing the non-native types associated with this UnionType

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 all class types to all inherited classes returning a superset of this type.

asGenericArrayTypes() public method

public asGenericArrayTypes ( ) : UnionType
return UnionType Get a new type for each type in this union which is the generic array version of this type. For instance, 'int|float' will produce 'int[]|float[]'.

canCastToExpandedUnionType() public method

public canCastToExpandedUnionType ( UnionType $target, CodeBase $code_base ) : boolean
$target UnionType The type we'd like to see if this type can cast to
$code_base Phan\CodeBase The code base used to expand types
return boolean Test to see if this type can be cast to the given type after expanding both union types to include all ancestor types

canCastToUnionType() public method

See also: Phan\Deprecated\Pass2::type_check Formerly 'function type_check'
public canCastToUnionType ( UnionType $target ) : boolean
$target UnionType A type to check to see if this can cast to it
return boolean True if this type is allowed to cast to the given type i.e. int->float is allowed while float->int is not.

fromFullyQualifiedString() public static method

public static fromFullyQualifiedString ( string $fully_qualified_string ) : UnionType
$fully_qualified_string string A '|' delimited string representing a type in the form 'int|string|null|ClassName'.
return UnionType

fromNode() public static method

public static fromNode ( Context $context, CodeBase $code_base, ast\Node | string | null $node, boolean $should_catch_issue_exception = true ) : UnionType
$context Context The context of the parser at the node for which we'd like to determine a type
$code_base Phan\CodeBase The code base within which we're operating
$node ast\Node | string | null The node for which we'd like to determine its type
$should_catch_issue_exception boolean Set to true to cause loggable issues to be thrown instead of emitted as issues to the log.
return UnionType

fromStringInContext() public static method

public static fromStringInContext ( string $type_string, Context $context ) : UnionType
$type_string string A '|' delimited string representing a type in the form 'int|string|null|ClassName'.
$context Context The context in which the type string was found
return UnionType

genericArrayElementTypes() public method

Takes "a|b[]|c|d[]|e" and returns "b|d"
public genericArrayElementTypes ( ) : UnionType
return UnionType The subset of types in this

getTemplateParameterTypeList() public method

public getTemplateParameterTypeList ( ) : array
return array A map from template type identifiers to the UnionType to replace it with

getTemplateParameterTypeMap() public method

public getTemplateParameterTypeMap ( CodeBase $code_base ) : array
$code_base Phan\CodeBase The code base to look up classes against
return array A map from template type identifiers to the UnionType to replace it with

getTypeSet() public method

public getTypeSet ( ) : Phan\Library\Set
return Phan\Library\Set The set of simple types associated with this union type.

hasAnyType() public method

public hasAnyType ( array $type_list ) : boolean
$type_list array A list of types
return boolean True if this union type contains any of the given named types

hasArrayLike() public method

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

hasGenericArray() public method

public hasGenericArray ( ) : boolean
return boolean True if this type has any generic types

hasSelfType() public method

public hasSelfType ( ) : boolean
return boolean True if this type has a type referencing the class context in which it exists such as 'self' or '$this'

hasStaticType() public method

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

hasTemplateType() public method

public hasTemplateType ( ) : boolean
return boolean True if this union type has any types that are generic types

hasType() public method

public hasType ( Type $type ) : boolean
$type Type
return boolean True if this union type contains the given named type.

hasType() public method

public hasType ( Type $type ) : boolean
$type Type
return boolean True if this union type contains the given named type.

internalFunctionSignatureMap() public static method

See also: Phan\Language\Internal\FunctionSignatureMap
public static internalFunctionSignatureMap ( ) : array
return array A map from builtin function name to type information

internalFunctionSignatureMapForFQSEN() public static method

A list of types for parameters associated with the given builtin function with the given name
See also: internal_varargs_check Formerly `function internal_varargs_check`
public static internalFunctionSignatureMapForFQSEN ( FullyQualifiedMethodName | FullyQualifiedFunctionName $function_fqsen ) : array
$function_fqsen Phan\Language\FQSEN\FullyQualifiedMethodName | Phan\Language\FQSEN\FullyQualifiedFunctionName
return array

internalPropertyMapForClassName() public static method

public static internalPropertyMapForClassName ( string $class_name ) : array
$class_name string
return array Get a map from property name to its type for the given class name.

isEmpty() public method

public isEmpty ( ) : boolean
return boolean True if this Union has no types

isEqualTo() public method

public isEqualTo ( UnionType $union_type ) : boolean
$union_type UnionType
return boolean True iff this union contains the exact set of types represented in the given union type.

isGenericArray() public method

public isGenericArray ( ) : boolean
return boolean True if this is exclusively generic types

isNativeType() public method

public isNativeType ( ) : boolean
return boolean True if this UnionType is exclusively native types

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

isType() public method

public isType ( Type $type ) : boolean
$type Type
return boolean True if and only if this UnionType contains the given type and no others.

isType() public method

public isType ( Type $type ) : boolean
$type Type
return boolean True if and only if this UnionType contains the given type and no others.

nonArrayTypes() public method

Takes "a|b[]|c|d[]|e|array|ArrayAccess" and returns "a|c|e|ArrayAccess"
See also: nonGenericArrayTypes
public nonArrayTypes ( ) : UnionType
return UnionType A UnionType with generic types(as well as the non-generic type "array") filtered out.

nonGenericArrayTypes() public method

Takes "a|b[]|c|d[]|e" and returns "a|c|e"
See also: Phan\Deprecated\Pass2::nongenerics Formerly `function nongenerics`
public nonGenericArrayTypes ( ) : UnionType
return UnionType A UnionType with generic types filtered out

nonNativeTypes() public method

public nonNativeTypes ( ) : UnionType
return UnionType Get the subset of types which are not native

removeType() public method

Remove a type name to the list of types
public removeType ( Type $type ) : void
$type Type
return void

removeType() public method

Remove a type name to the list of types
public removeType ( Type $type ) : void
$type Type
return void

serialize() public method

As per the Serializable interface
See also: Serializable
public serialize ( ) : string
return string A serialized representation of this type

typeCount() public method

public typeCount ( ) : integer
return integer The number of types in this union type

unserialize() public method

As per the Serializable interface
See also: Serializable
public unserialize ( string $serialized ) : void
$serialized string A serialized UnionType
return void

withStaticResolvedInContext() public method

public withStaticResolvedInContext ( Context $context ) : UnionType
$context Context
return UnionType A new UnionType with any references to 'static' resolved in the given context.

withTemplateParameterTypeMap() public method

public withTemplateParameterTypeMap ( array $template_parameter_type_map ) : UnionType
$template_parameter_type_map array A map from template type identifiers to concrete types
return UnionType This UnionType with any template types contained herein mapped to concrete types defined in the given map.