-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathAbstractPostRector.php
More file actions
47 lines (37 loc) · 1.12 KB
/
AbstractPostRector.php
File metadata and controls
47 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace Rector\PostRector\Rector;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\NodeVisitorAbstract;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Rector\ValueObject\Application\File;
use Webmozart\Assert\Assert;
abstract class AbstractPostRector extends NodeVisitorAbstract implements PostRectorInterface
{
private File|null $file = null;
/**
* @param Stmt[] $stmts
*/
public function shouldTraverse(array $stmts): bool
{
return true;
}
public function setFile(File $file): void
{
$this->file = $file;
}
public function getFile(): File
{
Assert::isInstanceOf($this->file, File::class);
return $this->file;
}
protected function addRectorClassWithLine(Node $node): void
{
Assert::isInstanceOf($this->file, File::class);
$rectorWithLineChange = new RectorWithLineChange(static::class, $node->getStartLine());
$this->getFile()
->addRectorClassWithLine($rectorWithLineChange);
}
}