Skip to content

Commit 5b68b8c

Browse files
alongoszclaude
andcommitted
Fixed SiteAccessAwareEntityManager::find() dropping lock arguments
The decorator narrowed EntityManagerInterface::find() to two parameters, so callers requesting a pessimistic or optimistic lock (e.g. LockMode::PESSIMISTIC_WRITE) silently got no lock and no error. The arguments are now forwarded to the wrapped entity manager, the same way Doctrine\ORM\Decorator\EntityManagerDecorator does. Added a scoped PHPStan ignore, as ObjectManager::find() declares only two parameters in both doctrine/persistence v2 and v3. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3295f38 commit 5b68b8c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ parameters:
1717
- tests/*
1818
-
1919
message: "#^Cannot call method warning\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
20+
-
21+
# ObjectManager::find() declares 2 parameters, but the runtime EntityManager
22+
# supports $lockMode and $lockVersion, forwarded like Doctrine\ORM\Decorator\EntityManagerDecorator does
23+
message: '#^Method Doctrine\\Persistence\\ObjectManager\:\:find\(\) invoked with 4 parameters, 2 required\.$#'
24+
identifier: arguments.count
25+
count: 1
26+
path: src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php
2027
paths:
2128
- src
2229
- tests

src/lib/Persistence/Doctrine/SiteAccessAwareEntityManager.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,18 @@ public function getCache(): ?Cache
226226
return $this->getWrapped()->getCache();
227227
}
228228

229-
public function find($className, $id): ?object
229+
/**
230+
* @template T of object
231+
*
232+
* @param class-string<T> $className
233+
* @param int|null $lockMode one of the \Doctrine\DBAL\LockMode::* constants or null
234+
* @param int|null $lockVersion
235+
*
236+
* @return T|null
237+
*/
238+
public function find($className, $id, $lockMode = null, $lockVersion = null): ?object
230239
{
231-
return $this->getWrapped()->find($className, $id);
240+
return $this->getWrapped()->find($className, $id, $lockMode, $lockVersion);
232241
}
233242

234243
/**

0 commit comments

Comments
 (0)