TypeNormalizer
in package
Type normalizer class
Maps gettype()'s legacy type names to the PHP type-hint keyword they should have been. gettype() returns 'integer'/'boolean'/'double', none of which are valid in a PHP type-hint position — using them there directly is what produced invalid generated code before this fix.
Tags
Table of Contents
Constants
- MAP = ['integer' => 'int', 'boolean' => 'bool', 'double' => 'float', 'NULL' => 'null']
- Map of gettype() names to PHP type-hint keywords
Methods
- normalize() : string
- Normalize a gettype()-style name to a PHP type-hint keyword
- resolveReflectionType() : string|null
- Resolve a native ReflectionType into a bare, pipe-joined type-hint string
- joinIntersectionType() : string
- Join an intersection type's member names with '&'
Constants
MAP
Map of gettype() names to PHP type-hint keywords
protected
array<string|int, mixed>
MAP
= ['integer' => 'int', 'boolean' => 'bool', 'double' => 'float', 'NULL' => 'null']
Methods
normalize()
Normalize a gettype()-style name to a PHP type-hint keyword
public
static normalize(string $gettypeName) : string
Parameters
- $gettypeName : string
Return values
stringresolveReflectionType()
Resolve a native ReflectionType into a bare, pipe-joined type-hint string
public
static resolveReflectionType(ReflectionType|null $type) : string|null
Handles named types, union types, and intersection types -- including a DNF union whose
members are themselves intersection types (e.g. (A&B)|C), which PHP 8.2+ allows. This
consolidates what used to be four separate, partially-duplicated, partially-incomplete
copies of this logic (MethodReflection and FunctionReflection each had their own -- neither
handled intersection types, and MethodReflection's parameter branch and FunctionReflection's
parameter branch didn't handle unions at all, either crashing or silently dropping the type).
Parameters
- $type : ReflectionType|null
Return values
string|nulljoinIntersectionType()
Join an intersection type's member names with '&'
protected
static joinIntersectionType(ReflectionIntersectionType $type) : string
Parameters
- $type : ReflectionIntersectionType