@@ -114,11 +114,16 @@ public static function getMarkdownToc(?string $markdown = null, int $minLevel =
114
114
115
115
// Remove code blocks cause they can have heading symbols (#)
116
116
$ markdown = (string ) preg_replace ('/(```[a-z]*\n[\s\S]*?\n```)/ ' , '' , $ markdown );
117
+ $ headings = preg_grep ('/^\s*\#{ ' . $ minLevel . ', ' . $ maxLevel . '}\ / ' , explode ("\n" , $ markdown ));
118
+
119
+ if ((bool ) $ headings === false ) {
120
+ return [];
121
+ }
117
122
118
123
// Fetch all lines with headings
119
- $ headings = array_filter (
120
- preg_grep ( ' /^\s*\#{ ' . $ minLevel . ' , ' . $ maxLevel . ' }\ / ' , explode ( "\n" , $ markdown )),
121
- );
124
+ /** @var array<int,string> $headings */
125
+ $ headings = $ headings ;
126
+ $ headings = array_filter ( $ headings );
122
127
$ data = [];
123
128
124
129
foreach ($ headings as $ heading ) {
@@ -320,6 +325,8 @@ public static function getElementsList(array $unsetFields = []): array
320
325
continue ;
321
326
}
322
327
328
+ /** @var int $key */
329
+ $ key = $ key ;
323
330
$ data [$ key ]['open ' ] = true ;
324
331
325
332
/**
@@ -510,11 +517,13 @@ public static function linkFqsen(?string $value = null): ?string
510
517
case $ element instanceof Trait_:
511
518
/** @var Class_|Interface_|Trait_ $element */
512
519
$ element = $ element ;
520
+ /** @var string $name */
521
+ $ name = $ element ->getName ();
513
522
$ link = sprintf (
514
523
'<a href="%s" title="%s">%s</a> ' ,
515
524
self ::getElementFilename ($ element ),
516
525
trim ($ element ->getFqsen ()->__toString (), '\\() ' ),
517
- $ element -> getName () ,
526
+ $ name ,
518
527
);
519
528
520
529
break ;
0 commit comments