Skip to content

Commit 78bedd9

Browse files
authored
Merge pull request #242 from andreaswolf/never-return-array
[TASK] NodeVisitor::enterNode and traverseNode will never return an array
2 parents cdfa0a3 + 8769488 commit 78bedd9

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

packages/fractor-typoscript/src/AbstractTypoScriptFractor.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ final public function beforeTraversal(File $file, array $statements): void
2323
$this->file = $file;
2424
}
2525

26-
/**
27-
* @return Statement|list<Statement>|int
28-
*/
29-
final public function enterNode(Statement $node): Statement|array|int
26+
final public function enterNode(Statement $node): Statement|int
3027
{
3128
$result = $this->refactor($node);
3229

packages/fractor-typoscript/src/Contract/TypoScriptNodeVisitor.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace a9f\FractorTypoScript\Contract;
66

77
use a9f\Fractor\Application\ValueObject\File;
8-
use a9f\FractorTypoScript\TypoScriptStatementsIterator;
98
use Helmich\TypoScriptParser\Parser\AST\Statement;
109

1110
/**
@@ -18,10 +17,7 @@ interface TypoScriptNodeVisitor
1817
*/
1918
public function beforeTraversal(File $file, array $statements): void;
2019

21-
/**
22-
* @return Statement|list<Statement>|TypoScriptStatementsIterator::*
23-
*/
24-
public function enterNode(Statement $node): Statement|array|int;
20+
public function enterNode(Statement $node): Statement|int;
2521

2622
public function leaveNode(Statement $node): void;
2723

packages/fractor-typoscript/src/TypoScriptStatementsIterator.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
/**
2727
* @param list<TypoScriptNodeVisitor> $visitors
2828
*/
29-
public function __construct(
30-
iterable $visitors
31-
) {
29+
public function __construct(iterable $visitors)
30+
{
3231
$visitors = iterator_to_array($visitors);
3332
Assert::allIsInstanceOf($visitors, TypoScriptNodeVisitor::class);
3433
$this->visitors = $visitors;
@@ -63,19 +62,14 @@ private function processStatementList(array $statements): array
6362
foreach ($statements as $statement) {
6463
$result = $this->traverseNode($statement);
6564

66-
if (is_array($result)) {
67-
$resultingStatements[] = $result;
68-
} elseif ($result instanceof Statement) {
65+
if ($result instanceof Statement) {
6966
$resultingStatements[] = [$result];
7067
}
7168
}
7269
return array_merge(...$resultingStatements);
7370
}
7471

75-
/**
76-
* @return self::*|Statement|list<Statement>
77-
*/
78-
private function traverseNode(Statement $node): int|Statement|array
72+
private function traverseNode(Statement $node): int|Statement
7973
{
8074
$lastCalledVisitor = null;
8175
$result = $node;

packages/fractor-typoscript/tests/TypoScriptStatementsIterator/Fixture/StatementCollectingVisitor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function beforeTraversal(File $file, array $statements): void
2727
$this->calls[] = sprintf('%s:beforeTraversal:%s', $this->visitorName, count($statements));
2828
}
2929

30-
public function enterNode(Statement $node): Statement|array|int
30+
public function enterNode(Statement $node): Statement|int
3131
{
3232
$this->calls[] = sprintf('%s:enterNode:%s:l-%d', $this->visitorName, $node::class, $node->sourceLine);
3333
return $node;

0 commit comments

Comments
 (0)