https://github.com/staabm/rector-view-scope
https://github.com/staabm/rector-view-scope
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/staabm/rector-view-scope
- Owner: staabm
- Created: 2021-04-10T17:41:54.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-09-11T02:45:29.000Z (almost 3 years ago)
- Last Synced: 2025-03-29T23:11:19.636Z (over 1 year ago)
- Language: PHP
- Size: 75.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Problemspace
`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](https://github.com/staabm/rector-view-scope/blob/main/lib/ContextInferer.php). It afterwards updates the view-files global `@var` phpdocs to reflect the types, the ContextInferer determinded beforehand.
A example implementation is shipped with [ViewContextInferer](https://github.com/staabm/rector-view-scope/blob/main/lib/inferer/rocket/ViewContextInferer.php), 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:
```php
class Controller {
/**
* @var string
*/
public $hello;
}
```
example view:
```php
echo $hello;
```
the rector should lookup the controller-class via static reflection, [infer the type of its properties](https://github.com/staabm/rector-view-scope/blob/main/lib/ContextInferer.php) 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
```php
/**
* @var string
*/
echo $hello;
```