Skip to content

fix(phpstan): resolve preg_match offset access errors#84

Open
spawnia wants to merge 2 commits intomasterfrom
fix-phpstan-preg-match-offset-errors
Open

fix(phpstan): resolve preg_match offset access errors#84
spawnia wants to merge 2 commits intomasterfrom
fix-phpstan-preg-match-offset-errors

Conversation

@spawnia
Copy link
Member

@spawnia spawnia commented Mar 17, 2026

Summary

  • Use non-capturing groups ((?:...)) for regex captures that are never referenced, reducing match array indices
  • Add assert(isset(...)) for remaining match offsets so PHPStan can verify safe array access
  • Fixes all 8 offsetAccess.notFound errors across Chromosome, GenomicPosition, GenomicRegion, and IlluminaRunFolder

Test plan

  • make stan passes with 0 errors
  • make test passes (664 tests, 3862 assertions)

🤖 Generated with Claude Code

spawnia added 2 commits March 17, 2026 09:49
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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and GenomicRegion, updating match array indices accordingly
  • Added assert(isset(...)) for match offsets in IlluminaRunFolder, GenomicPosition, and GenomicRegion
  • Switched from (int) casts to SafeCast::toInt() in GenomicPosition and GenomicRegion for 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.

@spawnia spawnia requested a review from simbig March 17, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants