Skip to content

Commit 98932c2

Browse files
linawolfjaapio
andcommitted
Apply suggestions from review
Co-authored-by: Jaap van Otterdijk <[email protected]>
1 parent 4fb8f9e commit 98932c2

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function supports(Node $node): bool
4949

5050
public function getPriority(): int
5151
{
52-
// Before MenuNodeTransformer
52+
// Before TocNodeWithDocumentEntryTransformer and SectionEntryRegistrationTransformer
5353
return 5000;
5454
}
5555
}

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use function array_pop;
1717
use function assert;
18-
use function count;
1918
use function explode;
2019
use function implode;
2120
use function preg_match;
@@ -52,13 +51,9 @@ public function leaveNode(Node $node, CompilerContext $compilerContext): Node|nu
5251

5352
$documentEntriesInTree[] = $documentEntry;
5453
$menuEntry = new MenuEntryNode($documentEntry->getFile(), $documentEntry->getTitle(), [], false, 1);
55-
if (!$node->hasOption('titlesonly') && count($documentEntry->getSections()) > 0) {
54+
if (!$node->hasOption('titlesonly')) {
5655
foreach ($documentEntry->getSections() as $section) {
5756
// We do not add the main section as it repeats the document title
58-
if (count($section->getChildren()) <= 0) {
59-
continue;
60-
}
61-
6257
foreach ($section->getChildren() as $subSectionEntryNode) {
6358
assert($subSectionEntryNode instanceof SectionEntryNode);
6459
$currentLevel = $menuEntry->getLevel() + 1;
@@ -107,14 +102,7 @@ private function isEqualAbsolutePath(DocumentEntryNode $documentEntry, string $f
107102
return true;
108103
}
109104

110-
if ($glob && $documentEntry->getFile() !== $currentPath) {
111-
$file = str_replace('*', '[a-zA-Z0-9]*', $file);
112-
$pattern = '`^' . $file . '$`';
113-
114-
return preg_match($pattern, '/' . $documentEntry->getFile()) > 0;
115-
}
116-
117-
return false;
105+
return $this->isGlob($glob, $documentEntry->getFile(), $currentPath, $file, '/');
118106
}
119107

120108
private function isEqualRelativePath(DocumentEntryNode $documentEntry, string $file, string $currentPath, bool $glob): bool
@@ -132,11 +120,16 @@ private function isEqualRelativePath(DocumentEntryNode $documentEntry, string $f
132120
return true;
133121
}
134122

135-
if ($glob && $documentEntry->getFile() !== $currentPath) {
123+
return $this->isGlob($glob, $documentEntry->getFile(), $currentPath, $file, '');
124+
}
125+
126+
private function isGlob(bool $glob, string $documentEntryFile, string $currentPath, string $file, string $prefix): bool
127+
{
128+
if ($glob && $documentEntryFile !== $currentPath) {
136129
$file = str_replace('*', '[a-zA-Z0-9]*', $file);
137130
$pattern = '`^' . $file . '$`';
138131

139-
return preg_match($pattern, $documentEntry->getFile()) > 0;
132+
return preg_match($pattern, $prefix . $documentEntryFile) > 0;
140133
}
141134

142135
return false;

packages/guides/src/Nodes/DocumentTree/DocumentEntryNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use phpDocumentor\Guides\Nodes\TitleNode;
1010

1111
/** @extends AbstractNode<DocumentNode> */
12-
class DocumentEntryNode extends AbstractNode
12+
final class DocumentEntryNode extends AbstractNode
1313
{
1414
/** @var DocumentEntryNode[] */
1515
private array $entries = [];

packages/guides/src/Nodes/DocumentTree/SectionEntryNode.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
namespace phpDocumentor\Guides\Nodes\DocumentTree;
66

7+
use phpDocumentor\Guides\Nodes\AbstractNode;
8+
use phpDocumentor\Guides\Nodes\DocumentNode;
79
use phpDocumentor\Guides\Nodes\TitleNode;
810

9-
class SectionEntryNode
11+
/** @extends AbstractNode<DocumentNode> */
12+
final class SectionEntryNode extends AbstractNode
1013
{
1114
/** @var SectionEntryNode[] */
1215
private array $children = [];

0 commit comments

Comments
 (0)