fix(phpstan): resolve preg_match offset access errors#84
Open
fix(phpstan): resolve preg_match offset access errors#84
Conversation
Use non-capturing groups for unused captures in regex patterns and assert match offsets exist, so PHPStan can verify safe array access. 🤖 Generated with Claude Code
Replace raw (int) casts on preg_match captures with SafeCast::toInt to ensure invalid values throw rather than silently converting to 0. 🤖 Generated with Claude Code
There was a problem hiding this comment.
Pull request overview
This PR resolves 8 PHPStan offsetAccess.notFound errors by converting unnecessary capturing groups in regex patterns to non-capturing groups ((?:...)) and adding assert(isset(...)) statements to help PHPStan verify safe array access on remaining match offsets.
Changes:
- Replaced capturing groups with non-capturing groups in regex patterns across
Chromosome,GenomicPosition, andGenomicRegion, updating match array indices accordingly - Added
assert(isset(...))for match offsets inIlluminaRunFolder,GenomicPosition, andGenomicRegion - Switched from
(int)casts toSafeCast::toInt()inGenomicPositionandGenomicRegionfor consistency
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Chromosome.php | Changed (chr)? to (?:chr)? and updated match index from [2] to [1] |
| src/GenomicPosition.php | Non-capturing group for g. prefix, updated match indices, added assert, used SafeCast |
| src/GenomicRegion.php | Non-capturing groups for g. prefix and range suffix, updated match indices, added assert, used SafeCast |
| src/IlluminaRunFolder.php | Added assert(isset($matches[1])) for two preg_match results |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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.
Summary
(?:...)) for regex captures that are never referenced, reducing match array indicesassert(isset(...))for remaining match offsets so PHPStan can verify safe array accessoffsetAccess.notFounderrors acrossChromosome,GenomicPosition,GenomicRegion, andIlluminaRunFolderTest plan
make stanpasses with 0 errorsmake testpasses (664 tests, 3862 assertions)🤖 Generated with Claude Code