15
15
16
16
use function array_pop ;
17
17
use function assert ;
18
- use function count ;
19
18
use function explode ;
20
19
use function implode ;
21
20
use function preg_match ;
@@ -52,13 +51,9 @@ public function leaveNode(Node $node, CompilerContext $compilerContext): Node|nu
52
51
53
52
$ documentEntriesInTree [] = $ documentEntry ;
54
53
$ menuEntry = new MenuEntryNode ($ documentEntry ->getFile (), $ documentEntry ->getTitle (), [], false , 1 );
55
- if (!$ node ->hasOption ('titlesonly ' ) && count ( $ documentEntry -> getSections ()) > 0 ) {
54
+ if (!$ node ->hasOption ('titlesonly ' )) {
56
55
foreach ($ documentEntry ->getSections () as $ section ) {
57
56
// We do not add the main section as it repeats the document title
58
- if (count ($ section ->getChildren ()) <= 0 ) {
59
- continue ;
60
- }
61
-
62
57
foreach ($ section ->getChildren () as $ subSectionEntryNode ) {
63
58
assert ($ subSectionEntryNode instanceof SectionEntryNode);
64
59
$ currentLevel = $ menuEntry ->getLevel () + 1 ;
@@ -107,14 +102,7 @@ private function isEqualAbsolutePath(DocumentEntryNode $documentEntry, string $f
107
102
return true ;
108
103
}
109
104
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 , '/ ' );
118
106
}
119
107
120
108
private function isEqualRelativePath (DocumentEntryNode $ documentEntry , string $ file , string $ currentPath , bool $ glob ): bool
@@ -132,11 +120,16 @@ private function isEqualRelativePath(DocumentEntryNode $documentEntry, string $f
132
120
return true ;
133
121
}
134
122
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 ) {
136
129
$ file = str_replace ('* ' , '[a-zA-Z0-9]* ' , $ file );
137
130
$ pattern = '`^ ' . $ file . '$` ' ;
138
131
139
- return preg_match ($ pattern , $ documentEntry -> getFile () ) > 0 ;
132
+ return preg_match ($ pattern , $ prefix . $ documentEntryFile ) > 0 ;
140
133
}
141
134
142
135
return false ;
0 commit comments