Skip to content

Commit f889cb8

Browse files
fix: some psalm fixes
1 parent 38c7166 commit f889cb8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Twig/TwigUtil.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ public static function getMarkdownToc(?string $markdown = null, int $minLevel =
114114

115115
// Remove code blocks cause they can have heading symbols (#)
116116
$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+
}
117122

118123
// 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);
122127
$data = [];
123128

124129
foreach ($headings as $heading) {
@@ -320,6 +325,8 @@ public static function getElementsList(array $unsetFields = []): array
320325
continue;
321326
}
322327

328+
/** @var int $key */
329+
$key = $key;
323330
$data[$key]['open'] = true;
324331

325332
/**
@@ -510,11 +517,13 @@ public static function linkFqsen(?string $value = null): ?string
510517
case $element instanceof Trait_:
511518
/** @var Class_|Interface_|Trait_ $element */
512519
$element = $element;
520+
/** @var string $name */
521+
$name = $element->getName();
513522
$link = sprintf(
514523
'<a href="%s" title="%s">%s</a>',
515524
self::getElementFilename($element),
516525
trim($element->getFqsen()->__toString(), '\\()'),
517-
$element->getName(),
526+
$name,
518527
);
519528

520529
break;

0 commit comments

Comments
 (0)