Skip to content

Define DBAL 4's parameter type aliases in the Connection stub, and accept LockMode for the lock mode - #171

Merged
danog merged 1 commit into
psalm:2.xfrom
farikd:fix-dbal4-orm3-stub-types
Nov 19, 2026
Merged

danog merged 1 commit into
psalm:2.xfrom
farikd:fix-dbal4-orm3-stub-types

Conversation

@farikd

@farikd farikd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #170.

Psalm 7.11 enables this plugin automatically for Doctrine projects. With v2.12.2 on DBAL 4 and ORM 3, two stub problems give false InvalidArgument errors.

WrapperParameterTypeArray in the DBAL 4 Connection stub

The stub uses @phpstan-param WrapperParameterTypeArray $types but doesn't declare the alias. The stub replaces the class docblock where DBAL declares it, so Psalm reads it as the class Doctrine\DBAL\WrapperParameterTypeArray. Every $types argument is reported.

The stub now declares WrapperParameterType and WrapperParameterTypeArray as DBAL 4 does.

The lock mode of find() and refresh()

EntityRepository::find(), EntityManager::find() and refresh(), and EntityManagerInterface::find() and refresh() typed the lock mode as ?int. ORM 3 takes the DBAL 4 LockMode enum, so find($id, LockMode::PESSIMISTIC_WRITE) was reported.

They now take LockMode|int|null, as ORM 3 declares. With DBAL before 4, LockMode is a class of int constants, so the existing int calls still match.

Tests

  • New Connection.feature: named and positional $types on every query method that takes them, plus an invalid type that must still be reported. Gated to DBAL >= 4.
  • Lock-mode scenarios for each changed method. Gated to ORM >= 3.

All 22 new scenarios fail before the change. The suite passes locally:

  • stable deps, PHP 8.5, DBAL 4.6, ORM 3.8: 160 tests, 9 skipped
  • lowest deps, PHP 8.2, DBAL 2.13, ORM 2.9: 160 tests, 26 skipped

phpcs and Psalm are clean.

🤖 Generated with Claude Code

…cept LockMode for the lock mode

The DBAL 4 Connection stub used WrapperParameterTypeArray without declaring it. The stub replaces the class
docblock where DBAL declares it, so Psalm read it as a class that doesn't exist and reported every $types
argument. The stub now declares WrapperParameterType and WrapperParameterTypeArray as DBAL does.

EntityRepository::find(), EntityManager::find() and refresh(), and EntityManagerInterface::find() and
refresh() typed the lock mode as ?int. ORM 3 takes the DBAL 4 LockMode enum, so they now take
LockMode|int|null. With DBAL before 4, LockMode is a class of int constants, and the int still matches.

Fixes psalm#170

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@farikd
farikd changed the base branch from master to 2.x November 19, 2026 09:47
@danog

danog commented Nov 19, 2026

Copy link
Copy Markdown
Member

THanks!

@danog
danog merged commit e92e484 into psalm:2.x Nov 19, 2026
12 checks passed
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.

DBAL 4 / ORM 3 stubs: undefined WrapperParameterTypeArray alias in Connection, and ?int lock mode in EntityRepository::find()

2 participants