staabm / rector-view-scope
Fund package maintenance!
staabm
Installs: 1 156
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 8
Requires
- php: ^7.4 || ^8.0
- rector/rector: ^0.12
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-11 05:23:39 UTC
README
ViewScopeRector
is your helper to make static analysis tools aware of variable-types within view-scripts infered from a external context.
Summary
This rector includes the mechanics of scanning procedural php files (e.g. views) and calling a given ContextInferer. It afterwards updates the view-files global @var
phpdocs to reflect the types, the ContextInferer determinded beforehand.
A example implementation is shipped with ViewContextInferer, which implements Ruby'on Rails like view <–> controller type inference.
example big picture
this rector is meant to introduce @var
phpdocs into analyzed view files, e.g. based on declared public properties of a corresponding controller.
example Controller:
class Controller { /** * @var string */ public $hello; }
example view:
echo $hello;
the rector should lookup the controller-class via static reflection, infer the type of its properties and with this knowledge adjust/create a @var
phpdoc in the view file.
so in the end the rector will change the example view to
/** * @var string */ echo $hello;