Skip to content

Fix errors reported by PHPStan 2.x - #410

Open
codeling wants to merge 1 commit into
michelf:libfrom
codeling:fix/phpstan-2x-errors
Open

codeling wants to merge 1 commit into
michelf:libfrom
codeling:fix/phpstan-2x-errors

Conversation

@codeling

@codeling codeling commented Nov 8, 2026 •

Copy link
Copy Markdown

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.

Disclaimer

Report and fix generated by Claude Code (Sonnet 5.5)

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013TVvenPEq6D9BgMuwN7Cam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants