Skip to content

Commit aed8cdb

Browse files
committed
Eliminate Doctrine deprecations
1 parent 3dfc855 commit aed8cdb

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ parameters:
3232
identifier: 'identical.alwaysFalse'
3333
reportUnmatched: false
3434
path: 'src/EntityPreloader.php'
35+
-
36+
message: '#internal interface Doctrine\\ORM\\Mapping\\PropertyAccessors\\PropertyAccessor#' # internal, although returned from public ClassMetadata::getPropertyAccessor
37+
path: 'src/EntityPreloader.php'
3538
-
3639
identifier: shipmonk.defaultMatchArmWithEnum
3740
reportUnmatched: false # only new dbal issue

phpunit.xml.dist

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313
displayDetailsOnTestsThatTriggerErrors="true"
1414
displayDetailsOnTestsThatTriggerWarnings="true"
1515
displayDetailsOnTestsThatTriggerNotices="true"
16+
displayDetailsOnTestsThatTriggerDeprecations="true"
1617
cacheDirectory="cache/phpunit"
1718
>
19+
<php>
20+
<ini name="error_reporting" value="-1"/>
21+
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
22+
</php>
23+
1824
<testsuites>
1925
<testsuite name="default">
2026
<directory>tests</directory>
2127
</testsuite>
2228
</testsuites>
2329

24-
<source>
30+
<source ignoreSuppressionOfDeprecations="true">
2531
<include>
2632
<directory>src</directory>
2733
</include>

src/EntityPreloader.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use Doctrine\DBAL\Types\Type;
99
use Doctrine\ORM\EntityManagerInterface;
1010
use Doctrine\ORM\Mapping\ClassMetadata;
11+
use Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessor;
1112
use Doctrine\ORM\PersistentCollection;
1213
use Doctrine\ORM\QueryBuilder;
1314
use LogicException;
14-
use ReflectionProperty;
1515
use function array_chunk;
1616
use function array_values;
1717
use function count;
@@ -123,18 +123,18 @@ private function loadProxies(
123123
int $maxFetchJoinSameFieldCount,
124124
): array
125125
{
126-
$identifierReflection = $classMetadata->getSingleIdReflectionProperty(); // e.g. Order::$id reflection
126+
$identifierAccessor = $classMetadata->getSingleIdPropertyAccessor(); // e.g. Order::$id reflection
127127
$identifierName = $classMetadata->getSingleIdentifierFieldName(); // e.g. 'id'
128128

129-
if ($identifierReflection === null) {
129+
if ($identifierAccessor === null) {
130130
throw new LogicException('Doctrine should use RuntimeReflectionService which never returns null.');
131131
}
132132

133133
$uniqueEntities = [];
134134
$uninitializedIds = [];
135135

136136
foreach ($entities as $entity) {
137-
$entityId = $identifierReflection->getValue($entity);
137+
$entityId = $identifierAccessor->getValue($entity);
138138
$entityKey = (string) $entityId;
139139
$uniqueEntities[$entityKey] = $entity;
140140

@@ -170,11 +170,11 @@ private function preloadToMany(
170170
int $maxFetchJoinSameFieldCount,
171171
): array
172172
{
173-
$sourceIdentifierReflection = $sourceClassMetadata->getSingleIdReflectionProperty(); // e.g. Order::$id reflection
174-
$sourcePropertyReflection = $sourceClassMetadata->getReflectionProperty($sourcePropertyName); // e.g. Order::$items reflection
175-
$targetIdentifierReflection = $targetClassMetadata->getSingleIdReflectionProperty();
173+
$sourceIdentifierAccessor = $sourceClassMetadata->getSingleIdPropertyAccessor(); // e.g. Order::$id reflection
174+
$sourcePropertyAccessor = $sourceClassMetadata->getPropertyAccessor($sourcePropertyName); // e.g. Order::$items reflection
175+
$targetIdentifierAccessor = $targetClassMetadata->getSingleIdPropertyAccessor();
176176

177-
if ($sourceIdentifierReflection === null || $sourcePropertyReflection === null || $targetIdentifierReflection === null) {
177+
if ($sourceIdentifierAccessor === null || $sourcePropertyAccessor === null || $targetIdentifierAccessor === null) {
178178
throw new LogicException('Doctrine should use RuntimeReflectionService which never returns null.');
179179
}
180180

@@ -184,9 +184,9 @@ private function preloadToMany(
184184
$uninitializedCollections = [];
185185

186186
foreach ($sourceEntities as $sourceEntity) {
187-
$sourceEntityId = $sourceIdentifierReflection->getValue($sourceEntity);
187+
$sourceEntityId = $sourceIdentifierAccessor->getValue($sourceEntity);
188188
$sourceEntityKey = (string) $sourceEntityId;
189-
$sourceEntityCollection = $sourcePropertyReflection->getValue($sourceEntity);
189+
$sourceEntityCollection = $sourcePropertyAccessor->getValue($sourceEntity);
190190

191191
if (
192192
$sourceEntityCollection instanceof PersistentCollection
@@ -199,7 +199,7 @@ private function preloadToMany(
199199
}
200200

201201
foreach ($sourceEntityCollection as $targetEntity) {
202-
$targetEntityKey = (string) $targetIdentifierReflection->getValue($targetEntity);
202+
$targetEntityKey = (string) $targetIdentifierAccessor->getValue($targetEntity);
203203
$targetEntities[$targetEntityKey] = $targetEntity;
204204
}
205205
}
@@ -216,10 +216,10 @@ private function preloadToMany(
216216
$targetEntitiesChunk = $innerLoader(
217217
associationMapping: $associationMapping,
218218
sourceClassMetadata: $sourceClassMetadata,
219-
sourceIdentifierReflection: $sourceIdentifierReflection,
219+
sourceIdentifierAccessor: $sourceIdentifierAccessor,
220220
sourcePropertyName: $sourcePropertyName,
221221
targetClassMetadata: $targetClassMetadata,
222-
targetIdentifierReflection: $targetIdentifierReflection,
222+
targetIdentifierAccessor: $targetIdentifierAccessor,
223223
uninitializedSourceEntityIdsChunk: array_values($uninitializedSourceEntityIdsChunk),
224224
uninitializedCollections: $uninitializedCollections,
225225
maxFetchJoinSameFieldCount: $maxFetchJoinSameFieldCount,
@@ -253,20 +253,20 @@ private function preloadToMany(
253253
private function preloadOneToManyInner(
254254
array|ArrayAccess $associationMapping,
255255
ClassMetadata $sourceClassMetadata,
256-
ReflectionProperty $sourceIdentifierReflection,
256+
PropertyAccessor $sourceIdentifierAccessor,
257257
string $sourcePropertyName,
258258
ClassMetadata $targetClassMetadata,
259-
ReflectionProperty $targetIdentifierReflection,
259+
PropertyAccessor $targetIdentifierAccessor,
260260
array $uninitializedSourceEntityIdsChunk,
261261
array $uninitializedCollections,
262262
int $maxFetchJoinSameFieldCount,
263263
): array
264264
{
265265
$targetPropertyName = $sourceClassMetadata->getAssociationMappedByTargetField($sourcePropertyName); // e.g. 'order'
266-
$targetPropertyReflection = $targetClassMetadata->getReflectionProperty($targetPropertyName); // e.g. Item::$order reflection
266+
$targetPropertyAccessor = $targetClassMetadata->getPropertyAccessor($targetPropertyName); // e.g. Item::$order reflection
267267
$targetEntities = [];
268268

269-
if ($targetPropertyReflection === null) {
269+
if ($targetPropertyAccessor === null) {
270270
throw new LogicException('Doctrine should use RuntimeReflectionService which never returns null.');
271271
}
272272

@@ -280,11 +280,11 @@ private function preloadOneToManyInner(
280280
);
281281

282282
foreach ($targetEntitiesList as $targetEntity) {
283-
$sourceEntity = $targetPropertyReflection->getValue($targetEntity);
284-
$sourceEntityKey = (string) $sourceIdentifierReflection->getValue($sourceEntity);
283+
$sourceEntity = $targetPropertyAccessor->getValue($targetEntity);
284+
$sourceEntityKey = (string) $sourceIdentifierAccessor->getValue($sourceEntity);
285285
$uninitializedCollections[$sourceEntityKey]->add($targetEntity);
286286

287-
$targetEntityKey = (string) $targetIdentifierReflection->getValue($targetEntity);
287+
$targetEntityKey = (string) $targetIdentifierAccessor->getValue($targetEntity);
288288
$targetEntities[$targetEntityKey] = $targetEntity;
289289
}
290290

@@ -306,10 +306,10 @@ private function preloadOneToManyInner(
306306
private function preloadManyToManyInner(
307307
array|ArrayAccess $associationMapping,
308308
ClassMetadata $sourceClassMetadata,
309-
ReflectionProperty $sourceIdentifierReflection,
309+
PropertyAccessor $sourceIdentifierAccessor,
310310
string $sourcePropertyName,
311311
ClassMetadata $targetClassMetadata,
312-
ReflectionProperty $targetIdentifierReflection,
312+
PropertyAccessor $targetIdentifierAccessor,
313313
array $uninitializedSourceEntityIdsChunk,
314314
array $uninitializedCollections,
315315
int $maxFetchJoinSameFieldCount,
@@ -356,7 +356,7 @@ private function preloadManyToManyInner(
356356
}
357357

358358
foreach ($this->loadEntitiesBy($targetClassMetadata, $targetIdentifierName, $sourceClassMetadata, array_values($uninitializedTargetEntityIds), $maxFetchJoinSameFieldCount) as $targetEntity) {
359-
$targetEntityKey = (string) $targetIdentifierReflection->getValue($targetEntity);
359+
$targetEntityKey = (string) $targetIdentifierAccessor->getValue($targetEntity);
360360
$targetEntities[$targetEntityKey] = $targetEntity;
361361
}
362362

@@ -389,17 +389,17 @@ private function preloadToOne(
389389
int $maxFetchJoinSameFieldCount,
390390
): array
391391
{
392-
$sourcePropertyReflection = $sourceClassMetadata->getReflectionProperty($sourcePropertyName); // e.g. Item::$order reflection
392+
$sourcePropertyAccessor = $sourceClassMetadata->getPropertyAccessor($sourcePropertyName); // e.g. Item::$order reflection
393393

394-
if ($sourcePropertyReflection === null) {
394+
if ($sourcePropertyAccessor === null) {
395395
throw new LogicException('Doctrine should use RuntimeReflectionService which never returns null.');
396396
}
397397

398398
$batchSize ??= self::PRELOAD_ENTITY_DEFAULT_BATCH_SIZE;
399399
$targetEntities = [];
400400

401401
foreach ($sourceEntities as $sourceEntity) {
402-
$targetEntity = $sourcePropertyReflection->getValue($sourceEntity);
402+
$targetEntity = $sourcePropertyAccessor->getValue($sourceEntity);
403403

404404
if ($targetEntity === null) {
405405
continue;

tests/Fixtures/Blog/Article.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Doctrine\Common\Collections\ReadableCollection;
88
use Doctrine\ORM\Mapping\Column;
99
use Doctrine\ORM\Mapping\Entity;
10+
use Doctrine\ORM\Mapping\InverseJoinColumn;
11+
use Doctrine\ORM\Mapping\JoinColumn;
1012
use Doctrine\ORM\Mapping\ManyToMany;
1113
use Doctrine\ORM\Mapping\ManyToOne;
1214
use Doctrine\ORM\Mapping\OneToMany;
@@ -29,6 +31,8 @@ class Article extends TestEntityWithCustomPrimaryKey
2931
* @var Collection<int, Tag>
3032
*/
3133
#[ManyToMany(targetEntity: Tag::class, inversedBy: 'articles')]
34+
#[JoinColumn(nullable: false)]
35+
#[InverseJoinColumn(nullable: false)]
3236
private Collection $tags;
3337

3438
/**

0 commit comments

Comments
 (0)