assertCanBeStandaloneNullable(); } } /** * @internal * * @psalm-pure */ public static function fromReflectionType( ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null $type, ?ReflectionClass $currentClass ): ?self { if (null === $type) { return null; } if ($type instanceof ReflectionUnionType) { return new self( new UnionType(array_map( static fn( ReflectionIntersectionType|ReflectionNamedType $type ): IntersectionType|AtomicType => $type instanceof ReflectionNamedType ? AtomicType::fromReflectionNamedTypeAndClass($type, $currentClass) : self::fromIntersectionType($type, $currentClass), $type->getTypes() )), false ); } if ($type instanceof ReflectionIntersectionType) { return new self(self::fromIntersectionType($type, $currentClass), false); } $atomicType = AtomicType::fromReflectionNamedTypeAndClass($type, $currentClass); return new self( $atomicType, $atomicType->type !== 'mixed' && $atomicType !== 'null' && $type->allowsNull() ); } /** @psalm-pure */ private static function fromIntersectionType( ReflectionIntersectionType $intersectionType, ?ReflectionClass $currentClass ): IntersectionType { return new IntersectionType(array_map( static fn( ReflectionNamedType $type ): AtomicType => AtomicType::fromReflectionNamedTypeAndClass($type, $currentClass), $intersectionType->getTypes() )); } /** * @throws InvalidArgumentException * @psalm-pure */ public static function fromTypeString(string $type): self { [$nullable, $trimmedNullable] = self::trimNullable($type); if ( ! str_contains($trimmedNullable, CompositeType::INTERSECTION_SEPARATOR) && ! str_contains($trimmedNullable, CompositeType::UNION_SEPARATOR) ) { return new self(CompositeType::fromString($trimmedNullable), $nullable); } if ($nullable) { throw new InvalidArgumentException(sprintf( 'Type "%s" is a union type, and therefore cannot be also marked nullable with the "?" prefix', $type )); } return new self(CompositeType::fromString($trimmedNullable)); } /** * {@inheritDoc} * * Generates the type string, including FQCN "\\" prefix, so that * it can directly be used within any code snippet, regardless of * imports. * * @psalm-return non-empty-string */ public function generate(): string { return ($this->nullable ? self::NULL_MARKER : '') . $this->type->fullyQualifiedName(); } public function equals(TypeGenerator $otherType): bool { return $this->generate() === $otherType->generate(); } /** * @return non-empty-string the cleaned type string. Note that this value is not suitable for code generation, * since the returned value does not include any root namespace prefixes, when applicable, * and therefore the values cannot be used as FQCN in generated code. */ public function __toString(): string { return $this->type->toString(); } /** * @return bool[]|string[] ordered tuple, first key represents whether the type is nullable, second is the * trimmed string * @psalm-return array{bool, string} * @psalm-pure */ private static function trimNullable(string $type): array { if (str_starts_with($type, self::NULL_MARKER)) { return [true, substr($type, 1)]; } return [false, $type]; } } __halt_compiler();----SIGNATURE:----J0Gz7O8quAQztM2UXszUpTukPFHAOtGNInmN1lt731GmVpSMIdOyHiY6AS8wRrfGPHMYq/D55Bg3OXwrPsH7ZbCZztI4v8IOTbgYWfckrtVTJY8obfPuQvjRnK7aY+5bewnPbQL/4EOMMOxJGE7OWZowWP69jYlsPp/+534jZNyVhXiMFhUAud7OR1f4fCZ5IPf1LyWaT1cqbYqnkQ0DuWc1CAIV9jqCIl10nNK6rh8qFvVW3nI71/CTt2/sfFdMqKmwRhdDq99vz8XM632fx309ET3PhuX70r11EDv/EfiM5A3IhT9OYZnvc7bUkYrn+2/f8F+khcMCtJY4WLor2tUYDo2WTUTn9QBtnrQOSBaFvEzsoRQvxkDDllmNyVdjzMyix/mb3xqb9XlDD8nrKsZI0IoPfvy9fM2M/KhZLDmw0wSzsTRjvhYGQvZsMVC4MJR0xDw8zWB1XearBMh5vVFb4DkJ2yqmjVfCua3XYptPSZy50qeM5EOlBatg9oAx5gTYZO1fG4nHjIGykcnOpizoJdzBUd/A5+UchfhorJ6nAJvYpsTWU2jztesqeIaOjVeNF6QmNJe2M6v5v2ce+28m5ah1VC8qj/2MKW+yZOVZS6eLNN2wjwq81ayQhwJziNf2Ivx3KDVRJ/1+BMKNnIJy730IOnS5Zh7SBh1SLbc=----ATTACHMENT:----NDI3Mjg2NTAzODMxODI1NSAyMTk3ODQ5Mzc4NDg5MzkgMTI1NDE0ODg0MzQ2Njk0Mw==