phpstan-wordpress
phpstan-wordpress copied to clipboard
Move dynamic return type extensions into wordpress-stubs
@szepeviktor PHPStan 1.6 added support for conditional return types in docblocks, eg @return ($as_float is true ? float : string).
Some of the dynamic return type extensions (eg. CurrentTimeDynamicFunctionReturnTypeExtension) could be replaced by a conditional return type doc in the wordpress-stubs repo instead. Then we'd only need dynamic return type extensions for functions with more complicated logic.
What do you think? Worth doing?
Example (untested):
/**
* @phpstan-return ($type is 'timestamp'|'U' ? int : string)
*/
function current_time( $type, $gmt = false) {}
I go crazy! You have to know I'm old-fashioned guy: keep a Single type in a variable.
As for the answer: I have no clue how to manipulate stubs in a sustainable fashion.
Keep a big array<Class::method, $returnTypeString>?
I would need to check but I think the existing functionMap file could be used.
Example:
'current_time' => '($type is \'timestamp\'|\'U\' ? int : string)',
All right.