-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAbstractTypoScriptFractor.php
More file actions
62 lines (48 loc) · 1.56 KB
/
AbstractTypoScriptFractor.php
File metadata and controls
62 lines (48 loc) · 1.56 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace a9f\FractorTypoScript;
use a9f\Fractor\Application\ValueObject\AppliedRule;
use a9f\Fractor\Application\ValueObject\File;
use a9f\FractorTypoScript\Contract\TypoScriptFractor;
use a9f\FractorTypoScript\NodeTraverser\SimpleCallableStatementTraverser;
use Helmich\TypoScriptParser\Parser\AST\Statement;
abstract class AbstractTypoScriptFractor implements TypoScriptFractor
{
protected File $file;
protected bool $hasChanged = false;
public function __construct(
private readonly SimpleCallableStatementTraverser $simpleCallableStatementTraverser
) {
}
/**
* @param list<Statement> $statements
*/
final public function beforeTraversal(File $file, array $statements): void
{
$this->file = $file;
}
final public function enterNode(Statement $node): Statement|int|null
{
$result = $this->refactor($node);
// no change => return unchanged node
if ($result === null) {
return $node;
}
$this->file->addAppliedRule(AppliedRule::fromRule($this));
return $result;
}
final public function leaveNode(Statement $node): int|Statement|null
{
return null;
}
/**
* @param list<Statement> $statements
*/
final public function afterTraversal(array $statements): void
{
}
protected function traverseStatementsWithCallable(?Statement $statement, callable $callable): void
{
$this->simpleCallableStatementTraverser->traverseNodesWithCallable($statement, $callable);
}
}