From 3652fd2dca567d03350e7f4296912744406f9d4a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 07:16:14 +0000 Subject: [PATCH] Fix errors reported by PHPStan 2.x The CI job runs `phpstan analyse Michelf/ --level=5` with an unpinned `phpstan/phpstan` (>=1.0), so it now picks up 2.x, which reports seven errors in code that was already on `lib`: - `@copyright (Original Markdown) ...` in the three file headers: a tag value starting with "(" is parsed as annotation arguments and fails. Drop the parentheses. - Markdown::_doLists_callback(): `$list_type == 'ol'` is always true where it is tested, because `$ol_start > 1` is only reachable for ordered lists. Remove the redundant comparison. - Markdown::handleSpanToken(): pass the regex delimiter to preg_quote(). The token is only backticks, so the pattern is unchanged. - MarkdownExtra::doExtraAttributes(): document `$attr` as `string|null`; callers pass possibly unset matches and the body already handles null. - MarkdownExtra::parseFootnotePlaceholders(): cast the numbers to string for str_replace(). No change in output: the 60 bundled fixtures and a ~4,000 case corpus render identically with both parsers before and after. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013TVvenPEq6D9BgMuwN7Cam --- Michelf/Markdown.php | 6 +++--- Michelf/MarkdownExtra.php | 6 +++--- Michelf/MarkdownInterface.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 746a2d0..f75e476 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -5,7 +5,7 @@ * @package php-markdown * @author Michel Fortin * @copyright 2004-2022 Michel Fortin - * @copyright (Original Markdown) 2004-2006 John Gruber + * @copyright Original Markdown 2004-2006 John Gruber */ namespace Michelf; @@ -1079,7 +1079,7 @@ protected function _doLists_callback($matches) { } } - if ($ol_start > 1 && $list_type == 'ol'){ + if ($ol_start > 1){ $result = $this->hashBlock("<$list_type start=\"$ol_start\">\n" . $result . ""); } else { $result = $this->hashBlock("<$list_type>\n" . $result . ""); @@ -1782,7 +1782,7 @@ protected function handleSpanToken($token, &$str) { return $this->hashPart("&#". ord($token[1]). ";"); case "`": // Search for end marker in remaining text. - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', + if (preg_match('/^(.*?[^`])'.preg_quote($token, '/').'(?!`)(.*)$/sm', $str, $matches)) { $str = $matches[2]; diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 78e265d..340fdf1 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -5,7 +5,7 @@ * @package php-markdown * @author Michel Fortin * @copyright 2004-2022 Michel Fortin - * @copyright (Original Markdown) 2004-2006 John Gruber + * @copyright Original Markdown 2004-2006 John Gruber */ namespace Michelf; @@ -218,7 +218,7 @@ protected function teardown() { * which will be used to populate the id attribute in case it was not * overridden. * @param string $tag_name - * @param string $attr + * @param string|null $attr * @param mixed $defaultIdValue * @param array $classes * @return string @@ -1796,7 +1796,7 @@ protected function _appendFootnotes_callback($matches) { protected function parseFootnotePlaceholders($label, $footnote_number, $reference_number) { return str_replace( array('^^', '%%'), - array($footnote_number, $reference_number), + array((string) $footnote_number, (string) $reference_number), $label ); } diff --git a/Michelf/MarkdownInterface.php b/Michelf/MarkdownInterface.php index 84e6545..ede9155 100644 --- a/Michelf/MarkdownInterface.php +++ b/Michelf/MarkdownInterface.php @@ -5,7 +5,7 @@ * @package php-markdown * @author Michel Fortin * @copyright 2004-2022 Michel Fortin - * @copyright (Original Markdown) 2004-2006 John Gruber + * @copyright Original Markdown 2004-2006 John Gruber */ namespace Michelf;