Skip to content

Modernize codebase for PHP 8.4+ and add PHPStan level 10#4

Merged
lisachenko merged 4 commits into
masterfrom
feature/php84-migration
Mar 25, 2026
Merged

Modernize codebase for PHP 8.4+ and add PHPStan level 10#4
lisachenko merged 4 commits into
masterfrom
feature/php84-migration

Conversation

@lisachenko

Copy link
Copy Markdown
Member
  • Add phpstan/phpstan at level 10 and phpstan/phpstan-phpunit as dev dependencies; all 57 tests pass with zero static analysis errors
  • Refactor Recognizer::match() from by-reference output to ?string return
  • Narrow Token::getType() return from mixed to string
  • Use readonly constructor promotion throughout all value-object classes
  • Add precise generic type annotations (parse table shapes, ArrayIterator, SplQueue, @template T of string constraints on Util)
  • Decompose StatefulLexer nested array into three typed flat arrays
  • Replace static $regex local var in RegexLexer with typed class property
  • Fix undefined variable bug in Analyzer::buildParseTable()
  • Update Recognizer tests to new ?string API; fix ArithGrammar closures with typed parameters to satisfy PHPStan level 10

- Add phpstan/phpstan at level 10 and phpstan/phpstan-phpunit as dev
  dependencies; all 57 tests pass with zero static analysis errors
- Refactor Recognizer::match() from by-reference output to ?string return
- Narrow Token::getType() return from mixed to string
- Use readonly constructor promotion throughout all value-object classes
- Add precise generic type annotations (parse table shapes, ArrayIterator,
  SplQueue, @template T of string constraints on Util)
- Decompose StatefulLexer nested array into three typed flat arrays
- Replace static $regex local var in RegexLexer with typed class property
- Fix undefined variable bug in Analyzer::buildParseTable()
- Update Recognizer tests to new ?string API; fix ArithGrammar closures
  with typed parameters to satisfy PHPStan level 10

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lisachenko lisachenko added this to the 4.0 milestone Mar 25, 2026
@lisachenko lisachenko added the enhancement New feature or request label Mar 25, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lisachenko lisachenko force-pushed the feature/php84-migration branch from 688aef6 to 0dfb668 Compare March 25, 2026 20:32
…rk changes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Modernizes the Dissect lexer/parser toolkit for PHP 8.4+ and raises code quality by adopting PHPStan level 10 with tighter typing, generics, and readonly value objects across the codebase.

Changes:

  • Add PHPStan (level 10) tooling/config and CI workflow; update PHPUnit configuration and composer scripts.
  • Refactor lexer recognizers to return ?string instead of using by-reference outputs; tighten Token::getType() to string.
  • Improve type safety and internal structure (parse table shapes, typed collections, readonly constructor promotion), plus targeted bug fixes in analysis/table building.

Reviewed changes

Copilot reviewed 48 out of 48 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/bootstrap.php Guard Composer ClassLoader usage in test bootstrap
tests/Parser/LALR1/ArithGrammar.php Type closures for PHPStan compliance
tests/Parser/LALR1/Analysis/AnalyzerTest.php Strengthen assertions on conflict payload shape
tests/Lexer/TokenStream/ArrayTokenStreamTest.php Remove nullable stream property
tests/Lexer/StubRegexLexer.php Adjust test lexer typing / numeric handling
tests/Lexer/Recognizer/SimpleRecognizerTest.php Update tests for ?string match API
tests/Lexer/Recognizer/RegexRecognizerTest.php Update tests for ?string match API
tests/Lexer/AbstractLexerTest.php Remove nullable lexer property
src/Util/Util.php Add generics; change string length/substring internals
src/Parser/Rule.php Readonly constructor promotion; tighten precedence setter type
src/Parser/LALR1/Parser.php Parse table shape typing; modern callback invocation
src/Parser/LALR1/Dumper/TableDumper.php Add parse table shape annotation
src/Parser/LALR1/Dumper/ProductionTableDumper.php Add param typing/return types; formatting fixes
src/Parser/LALR1/Dumper/DebugTableDumper.php Readonly promotion; typed helper methods
src/Parser/LALR1/Dumper/AutomatonDumper.php Readonly promotion; stricter param typing
src/Parser/LALR1/Analysis/State.php Readonly promotion; add array element typing
src/Parser/LALR1/Analysis/KernelSet/Node.php Readonly promotion; typed kernel representation
src/Parser/LALR1/Analysis/KernelSet/KernelSet.php Tighten kernel types; typed hashing callback
src/Parser/LALR1/Analysis/Item.php Readonly promotion; stricter active-component handling
src/Parser/LALR1/Analysis/Exception/ShiftReduceConflictException.php Readonly promotion; tighten ctor types
src/Parser/LALR1/Analysis/Exception/ReduceReduceConflictException.php Readonly promotion; tighten ctor types
src/Parser/LALR1/Analysis/Exception/ConflictException.php Make state/automaton readonly
src/Parser/LALR1/Analysis/Automaton.php Add array shape typing; tighten hasState signature
src/Parser/LALR1/Analysis/Analyzer.php Destructure arrays; add precise collection typing
src/Parser/LALR1/Analysis/AnalysisResult.php Add phpstan type alias; readonly promotion
src/Parser/Grammar.php Tighten types/collections; fix minor spelling in docs
src/Node/Node.php Add generics; add void return types; improve phpdoc shapes
src/Node/CommonNode.php Add typed node/attr maps; iterator return typing
src/Lexer/TokenStream/TokenStream.php Add IteratorAggregate generic annotation
src/Lexer/TokenStream/ArrayTokenStream.php Tighten method signatures; iterator typing
src/Lexer/Token.php Narrow getType() to string
src/Lexer/StatefulLexer.php Decompose state arrays; adopt new recognizer API
src/Lexer/SimpleLexer.php Adopt new recognizer API; minor typing tweaks
src/Lexer/RegexLexer.php Cache regex in property; guard preg_split failure
src/Lexer/Recognizer/SimpleRecognizer.php Change match API to ?string; readonly string
src/Lexer/Recognizer/RegexRecognizer.php Change match API to ?string; readonly regex
src/Lexer/Recognizer/Recognizer.php Update interface/docs for ?string match API
src/Lexer/Exception/RecognitionException.php Readonly promotion; fix spelling in doc
src/Lexer/CommonToken.php Readonly promotion; align Token type to string
src/Console/Command/DissectCommand.php Tighten input handling/types; helper retrieval typing
src/Console/Application.php Tighten constructor param type
phpunit.xml Update PHPUnit schema version
phpstan.neon Add PHPStan config (level 10 + PHPUnit extension)
composer.json Add PHPStan deps and script; require PHP 8.4
README.md Rewrite/expand docs and quickstart example
LICENSE Update copyright year
CHANGELOG.md Add 4.0.0 release notes
.github/workflows/phpstan.yml Add PHPStan GitHub Actions workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Util/Util.php Outdated
Comment thread src/Node/CommonNode.php
Comment thread README.md Outdated
- Util::substring() was using mb_substr() (char offsets) while
  stringLength() uses strlen() (byte offsets), causing wrong slice
  positions for multibyte input in AbstractLexer; switch to substr()
- CommonNode had split backing arrays ($nodes vs $children): constructor
  populated $nodes but getNode/setNode/count/getIterator all used
  $children, making constructor-passed nodes invisible to all accessors;
  consolidate everything to $children
- README Quick Example used token() for regex patterns and wrong skip()
  signature; fix to use regex() for patterns and skip('WS') for type name

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lisachenko lisachenko merged commit ffb981b into master Mar 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PHP-8.4 PHP-8.5

Development

Successfully merging this pull request may close these issues.

2 participants