Skip to content

Commit ca869ec

Browse files
committed
Fix code style
1 parent 3c11f40 commit ca869ec

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

packages/guides/src/Compiler/CompilerContext.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
use Exception;
1717
use phpDocumentor\Guides\Compiler\ShadowTree\TreeNode;
1818
use phpDocumentor\Guides\Nodes\DocumentNode;
19+
use phpDocumentor\Guides\Nodes\Node;
1920
use phpDocumentor\Guides\Nodes\ProjectNode;
2021

2122
class CompilerContext
2223
{
23-
/** @var TreeNode<DocumentNode> */
24+
/** @var TreeNode<Node> */
2425
private TreeNode $shadowTree;
2526

2627
public function __construct(
@@ -50,6 +51,7 @@ public function withDocumentShadowTree(DocumentNode $documentNode): static
5051
return $that;
5152
}
5253

54+
/** @param TreeNode<Node> $shadowTree */
5355
public function withShadowTree(TreeNode $shadowTree): static
5456
{
5557
$that = clone $this;
@@ -58,7 +60,7 @@ public function withShadowTree(TreeNode $shadowTree): static
5860
return $that;
5961
}
6062

61-
/** @return TreeNode<DocumentNode> */
63+
/** @return TreeNode<Node> */
6264
public function getShadowTree(): TreeNode
6365
{
6466
if (!isset($this->shadowTree)) {

packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace phpDocumentor\Guides\Compiler\NodeTransformers;
46

7+
use ArrayIterator;
58
use LogicException;
69
use phpDocumentor\Guides\Compiler\CompilerContext;
710
use phpDocumentor\Guides\Compiler\NodeTransformer;
@@ -10,8 +13,12 @@
1013
use phpDocumentor\Guides\Nodes\Node;
1114
use phpDocumentor\Guides\Nodes\SectionNode;
1215

16+
use function spl_object_hash;
17+
18+
/** @implements NodeTransformer<AnchorNode> */
1319
final class MoveAnchorTransformer implements NodeTransformer
1420
{
21+
/** @var array<string, string> */
1522
private array $seen = [];
1623

1724
public function enterNode(Node $node, CompilerContext $compilerContext): Node
@@ -46,7 +53,8 @@ public function getPriority(): int
4653
return 30000;
4754
}
4855

49-
private function attemptMoveToNeighbour(TreeNode $parent, int $position, Node $node): ?Node
56+
/** @param TreeNode<Node> $parent */
57+
private function attemptMoveToNeighbour(TreeNode $parent, int $position, AnchorNode $node): AnchorNode|null
5058
{
5159
$current = $this->findNextSection($parent, $position);
5260
if ($current === null) {
@@ -55,20 +63,30 @@ private function attemptMoveToNeighbour(TreeNode $parent, int $position, Node $n
5563
}
5664

5765
$position = $parent->getParent()->findPosition($parent->getNode());
66+
if ($position === null) {
67+
throw new LogicException('Node not found in shadow tree');
68+
}
69+
5870
return $this->attemptMoveToNeighbour($parent->getParent(), $position, $node);
5971
}
6072

6173
if ($current->getNode() instanceof SectionNode) {
6274
$current->pushChild($node);
75+
6376
return null;
6477
}
6578

6679
return $node;
6780
}
6881

69-
private function findNextSection($parent, $position): TreeNode|null
82+
/**
83+
* @param TreeNode<Node> $parent
84+
*
85+
* @return TreeNode<Node>|null
86+
*/
87+
private function findNextSection(TreeNode $parent, int $position): TreeNode|null
7088
{
71-
$children = new \ArrayIterator($parent->getChildren());
89+
$children = new ArrayIterator($parent->getChildren());
7290
if ($children->count() <= $position + 1) {
7391
return null;
7492
}

packages/guides/src/Compiler/ShadowTree/TreeNode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
use phpDocumentor\Guides\Nodes\DocumentNode;
1010
use phpDocumentor\Guides\Nodes\Node;
1111

12+
use function array_unshift;
1213
use function array_values;
1314

14-
/** @template TNode of Node */
15+
/** @template-covariant TNode of Node */
1516
final class TreeNode
1617
{
1718
/** @var TreeNode<DocumentNode> */
@@ -178,7 +179,7 @@ public function replaceChild(Node $oldChildNode, Node $newChildNode): void
178179
}
179180
}
180181

181-
public function findPosition(Node $node): ?int
182+
public function findPosition(Node $node): int|null
182183
{
183184
foreach ($this->children as $key => $child) {
184185
if ($child->getNode() === $node) {

packages/guides/src/Nodes/CompoundNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpDocumentor\Guides\Nodes;
1515

16+
use function array_unshift;
1617
use function array_values;
1718

1819
/**
@@ -39,7 +40,6 @@ public function addChildNode(Node $node): void
3940
$this->value[] = $node;
4041
}
4142

42-
4343
public function pushChildNode(Node $node): void
4444
{
4545
array_unshift($this->value, $node);

packages/guides/tests/unit/Compiler/NodeTransformers/MoveAnchorTransformerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace phpDocumentor\Guides\Compiler\NodeTransformers;
46

57
use phpDocumentor\Guides\Compiler\CompilerContext;
@@ -19,13 +21,13 @@ final class MoveAnchorTransformerTest extends TestCase
1921
protected function setUp(): void
2022
{
2123
$this->documentNodeTraverser = new DocumentNodeTraverser(new class implements NodeTransformerFactory {
24+
/** @return iterable<MoveAnchorTransformer> */
2225
public function getTransformers(): iterable
2326
{
24-
return [
25-
new MoveAnchorTransformer()
26-
];
27+
yield new MoveAnchorTransformer();
2728
}
2829

30+
/** @return array<string, int> */
2931
public function getPriorities(): array
3032
{
3133
return [];
@@ -142,7 +144,6 @@ public function testMoveAnchorsAtTheEndOfSectionToNextSection(): void
142144
self::assertCount(2, $context->getDocumentNode()->getChildren()[1]->getChildren());
143145
}
144146

145-
146147
public function testMoveAnchorsAtTheEndOfSectionToNextParentNeighbourSection(): void
147148
{
148149
$node1 = new AnchorNode('foo');

tests/Integration/IntegrationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use phpDocumentor\Guides\ApplicationTestCase;
88
use phpDocumentor\Guides\Cli\Command\Run;
99
use PHPUnit\Framework\Attributes\DataProvider;
10-
use PHPUnit\Framework\Constraint\IsEqual;
1110
use PHPUnit\Framework\ExpectationFailedException;
1211
use Symfony\Component\Console\Input\ArrayInput;
1312
use Symfony\Component\Console\Output\BufferedOutput;

0 commit comments

Comments
 (0)