Phan\Language\Type::fromInternalTypeName PHP Method

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
    public static function fromInternalTypeName(string $type_name) : Type
    {
        // If this is a generic type (like int[]), return
        // a generic of internal types.
        if (false !== ($pos = strrpos($type_name, '[]'))) {
            return GenericArrayType::fromElementType(self::fromInternalTypeName(substr($type_name, 0, $pos)));
        }
        $type_name = self::canonicalNameFromName($type_name);
        switch (strtolower($type_name)) {
            case 'array':
                return ArrayType::instance();
            case 'bool':
                return BoolType::instance();
            case 'callable':
                return CallableType::instance();
            case 'float':
                return FloatType::instance();
            case 'int':
                return IntType::instance();
            case 'mixed':
                return MixedType::instance();
            case 'null':
                return NullType::instance();
            case 'object':
                return ObjectType::instance();
            case 'resource':
                return ResourceType::instance();
            case 'string':
                return StringType::instance();
            case 'void':
                return VoidType::instance();
            case 'static':
                return StaticType::instance();
        }
        assert(false, "No internal type with name {$type_name}");
    }

Usage Example

Beispiel #1
0
 /**
  * @return Type
  * Get a type for the given object
  */
 public static function fromObject($object) : Type
 {
     return Type::fromInternalTypeName(gettype($object));
 }