Download the PHP package uuf6429/phpstan-phpdoc-type-resolver without Composer
On this page you can find all versions of the php package uuf6429/phpstan-phpdoc-type-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uuf6429/phpstan-phpdoc-type-resolver
More information about uuf6429/phpstan-phpdoc-type-resolver
Files in uuf6429/phpstan-phpdoc-type-resolver
Package phpstan-phpdoc-type-resolver
Short Description Resolve (fully qualify) types from PHPStan's PHPDoc parser
License MIT
Homepage https://github.com/uuf6429/phpstan-phpdoc-type-resolver
Informations about the package phpstan-phpdoc-type-resolver
ðĄ PHPStan PHPDoc Type Resolver
Resolve (fully qualify) types from PHPStan's PHPDoc parser.
ðū Installation
Install via Composer:
Consider using --dev if you intend to use this library during development only.
ðĪ Why?
Because phpstan/phpdoc-parser doesn't resolve types (it's not its responsibility) and phpdocument/type-resolver
currently has some major limitations.
ð Usage
In principle, the resolver needs two things:
- The PHPStan-PHPDoc type (an instance of
TypeNode). - 'Scope' information of where that type occurred.
There are two ways to retrieve that information, as shown below.
Important: The resolver will always convert some specific PHPStan types into something else as follows:
- *
ThisTypeNodeis converted intoIdentifierTypeNodefor the current class. - *
GenericTypeNodeto eitherConcreteGenericTypeNodeorTemplateGenericTypeNodebased on if the received instance contains unresolved generic/template types. - PHPStan locally defined or imported types, a
TypeDefTypeNodewill be provided (instead of anIdentifierTypeNodewith just the type name).
(*) conversion is mandatory, failures will trigger some sort of exception (meaning: the original type should never be returned).
ð Via Reflection
Here's how we can resolve the Greeter::greet() method's return type:
ð Without Factory/DocBlock Wrapper
Here's the longer way to resolve the return type of the Greeter::greet() method:
ðĪŠ Via Source Strings
It's also possible to resolve the type without actually loading the PHP source code (which is a requirement for reflection). However, this will take more work â the main difference is that you will need to set up the scope yourself.
Let's assume we want to resolve a type in a PHP source code string: