Skip to content

Reduce PHPStan baseline by addressing actual issues#1083

Open
dereuromark wants to merge 2 commits into5.xfrom
phpstan-baseline-cleanup
Open

Reduce PHPStan baseline by addressing actual issues#1083
dereuromark wants to merge 2 commits into5.xfrom
phpstan-baseline-cleanup

Conversation

@dereuromark
Copy link
Copy Markdown
Member

@dereuromark dereuromark commented May 9, 2026

Summary

Removes 13 of 15 stale entries from phpstan-baseline.neon by fixing the underlying issues. All non-BC; remaining 2 entries kept in baseline.

Fixes applied

  • BakeSeedCommand: drop wrong inline @var annotation, cast option value; rewrite reference foreach to track removable keys explicitly so PHPStan can follow the flow.
  • AbstractAdapter: tighten generateBulkInsertSql @param type to array<int, array<string, mixed>> and cast keys to string for array_map.
  • AdapterFactory: declare final constructor so new static() is safe.
  • MysqlAdapter: drop redundant nested isset() check inside the same branch.
  • Environment: useTransactions() is declared on MigrationInterface, so the method_exists guard was dead; the test that asserted on the redundant hasTransactions call is updated. up()/down() dispatch is now guarded by method_exists for the codepath that doesn't have a change() method.
  • Manager: cast strpos result and fall back to 0 in max() for the unreachable empty case.
  • TableFinder: drop redundant isset checks on list keys that explode/array_reverse always populate.
  • MigrationHelper: rewrite assignment as if/else so PHPStan can narrow the variable type.

Remaining baseline entries

  • Index::setUnique dynamic dispatch — early continue handles unique, but PHPStan can't track it.
  • SqliteAdapter null check on query result — required for test mocks where the mocked method returns null.

BC concerns deferred

  • Adding up(): void / down(): void to MigrationInterface would clear the remaining method.notFound entries on Environment but is a BC break for third parties implementing the interface directly. Suggest 6.x.

Remove 13 stale baseline entries by fixing the underlying issues:

- BakeSeedCommand: drop wrong @var annotation, cast option value;
  rewrite reference foreach to track removable keys explicitly
- AbstractAdapter: tighten generateBulkInsertSql @param type and
  cast keys to string for array_map
- AdapterFactory: declare final constructor (allows safe new static)
- MysqlAdapter: drop redundant nested isset() checks
- Environment: useTransactions() is on the interface, drop the dead
  method_exists guard; gate up()/down() dispatch with method_exists
- Manager: cast strpos result, fall back to 0 in max()
- TableFinder: drop redundant isset checks on always-set list keys
- MigrationHelper: rewrite as if/else so PHPStan can narrow the type

Two entries remain in the baseline:
- Index::setUnique dynamic dispatch (handled via continue)
- SqliteAdapter null check kept for test mock compatibility
Match parent visibility on inherited buildOptionParser overrides,
type the closure parameter, simplify if/else to ternary, and add
the newline rector wants.
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.

1 participant