mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-04 02:10:51 +00:00
[docs] add Rectors orde example
This commit is contained in:
parent
8fe0107070
commit
99b2cd75c3
|
@ -11,17 +11,17 @@
|
|||
## 2. Parse and Reconstruct 1 File
|
||||
|
||||
The iteration of files, nodes and Rectors respects this life cycle:
|
||||
|
||||
|
||||
```php
|
||||
foreach ($fileInfos as $fileInfo) {
|
||||
// 1 file => nodes
|
||||
$nodes = $phpParser->parseFileInfo($fileInfo);
|
||||
|
||||
// nodes => 1 node
|
||||
|
||||
// nodes => 1 node
|
||||
foreach ($nodes as $node) { // rather traverse all of them
|
||||
foreach ($rectors as $rector) {
|
||||
if ($rector->isCandidate($node)) {
|
||||
$rector->reconstructr($node);
|
||||
$rector->reconstruct($node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,21 +33,39 @@ foreach ($fileInfos as $fileInfo) {
|
|||
- File is parsed by [`nikic/php-parser`](https://github.com/nikic/PHP-Parser), 4.0-dex (this is important, because this version support writing modified tree back to file)
|
||||
- Then nodes (array of objects by parser) are traversed by `StandaloneTraverseNodeTraverser` to prepare it's metadata, e.g. class name, method node the node is in, namespace name etc. added by `$node->setAttribute(Attribute::CLASS_NODE, 'value')`.
|
||||
|
||||
### 2.2 Rectify Phase
|
||||
|
||||
### 2.2 Rectify Phase
|
||||
|
||||
- When all nodes are ready, applicies iterates all active Rector
|
||||
- Each nodes is passed to `$rector->isCandidate($node)` method to see, if this Rector should do some work on it, e.g. is this class name called `OldClassName`?
|
||||
- If it doesn't match, it goes to next node.
|
||||
- If it matches, the `$rector->reconstruct($node)` method is called
|
||||
- Active Rector changes all what he should and returns changed node
|
||||
|
||||
### 2.2.1 Order of Rectors
|
||||
|
||||
- Rectors are run by they natural order in config, first will be run first.
|
||||
|
||||
E.g. in this case, first will be changed `@expectedException` annotation to method,
|
||||
then a method `setExpectedException` to `expectedException`.
|
||||
|
||||
```yml
|
||||
# rector.yml
|
||||
rectors:
|
||||
Rector\Rector\Contrib\PHPUnit\ExceptionAnnotationRector: ~
|
||||
|
||||
Rector\Rector\Dynamic\MethodNameReplacerRector:
|
||||
'PHPUnit\Framework\TestClass':
|
||||
'setExpectedException': 'expectedException'
|
||||
'setExpectedExceptionRegExp': 'expectedException'
|
||||
```
|
||||
|
||||
### 2.3 Save File/Diff Phase
|
||||
|
||||
- When work on all nodes of 1 file is done, the file will be saved if it has some changes
|
||||
- When work on all nodes of 1 file is done, the file will be saved if it has some changes
|
||||
- Or if the `--dry-run` option is on, it will store the *git-like* diff thanks to [GeckoPackages/GeckoDiffOutputBuilder](https://github.com/GeckoPackages/GeckoDiffOutputBuilder)
|
||||
- Then go to next file
|
||||
|
||||
## 3 Reporting
|
||||
|
||||
- After this Rector displays list of changed files
|
||||
- After this Rector displays list of changed files
|
||||
- Or with `--dry-run` option the diff of these files
|
Loading…
Reference in New Issue
Block a user