Modernize codebase for PHP 8.4+ and add PHPStan level 10#4
Merged
Conversation
lisachenko
commented
Mar 25, 2026
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>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
688aef6 to
0dfb668
Compare
…rk changes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
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
?stringinstead of using by-reference outputs; tightenToken::getType()tostring. - 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.
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.