|
41 | 41 | */
|
42 | 42 | final class EagerLoadingExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
|
43 | 43 | {
|
44 |
| - private PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory; |
45 |
| - private PropertyMetadataFactoryInterface $propertyMetadataFactory; |
46 |
| - private ?ClassMetadataFactoryInterface $classMetadataFactory; |
47 |
| - private int $maxJoins; |
48 |
| - private bool $forceEager; |
49 |
| - private bool $fetchPartial; |
50 |
| - |
51 |
| - public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, int $maxJoins = 30, bool $forceEager = true, bool $fetchPartial = false, ClassMetadataFactoryInterface $classMetadataFactory = null) |
| 44 | + public function __construct(private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory, private readonly int $maxJoins = 30, private readonly bool $forceEager = true, private readonly bool $fetchPartial = false, private readonly ?ClassMetadataFactoryInterface $classMetadataFactory = null) |
52 | 45 | {
|
53 |
| - $this->propertyNameCollectionFactory = $propertyNameCollectionFactory; |
54 |
| - $this->propertyMetadataFactory = $propertyMetadataFactory; |
55 |
| - $this->classMetadataFactory = $classMetadataFactory; |
56 |
| - $this->maxJoins = $maxJoins; |
57 |
| - $this->forceEager = $forceEager; |
58 |
| - $this->fetchPartial = $fetchPartial; |
59 | 46 | }
|
60 | 47 |
|
61 | 48 | /**
|
@@ -141,11 +128,11 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
|
141 | 128 |
|
142 | 129 | try {
|
143 | 130 | $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $association, $options);
|
144 |
| - } catch (PropertyNotFoundException $propertyNotFoundException) { |
| 131 | + } catch (PropertyNotFoundException) { |
145 | 132 | // skip properties not found
|
146 | 133 | continue;
|
147 | 134 | // @phpstan-ignore-next-line indeed this can be thrown by the SerializerPropertyMetadataFactory
|
148 |
| - } catch (ResourceClassNotFoundException $resourceClassNotFoundException) { |
| 135 | + } catch (ResourceClassNotFoundException) { |
149 | 136 | // skip associations that are not resource classes
|
150 | 137 | continue;
|
151 | 138 | }
|
@@ -207,7 +194,7 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
|
207 | 194 | if (true === $fetchPartial) {
|
208 | 195 | try {
|
209 | 196 | $this->addSelect($queryBuilder, $mapping['targetEntity'], $associationAlias, $options);
|
210 |
| - } catch (ResourceClassNotFoundException $resourceClassNotFoundException) { |
| 197 | + } catch (ResourceClassNotFoundException) { |
211 | 198 | continue;
|
212 | 199 | }
|
213 | 200 | } else {
|
@@ -283,9 +270,7 @@ private function addSelect(QueryBuilder $queryBuilder, string $entity, string $a
|
283 | 270 |
|
284 | 271 | private function addSelectOnce(QueryBuilder $queryBuilder, string $alias): void
|
285 | 272 | {
|
286 |
| - $existingSelects = array_reduce($queryBuilder->getDQLPart('select') ?? [], function ($existing, $dqlSelect) { |
287 |
| - return ($dqlSelect instanceof Select) ? array_merge($existing, $dqlSelect->getParts()) : $existing; |
288 |
| - }, []); |
| 273 | + $existingSelects = array_reduce($queryBuilder->getDQLPart('select') ?? [], fn ($existing, $dqlSelect) => ($dqlSelect instanceof Select) ? array_merge($existing, $dqlSelect->getParts()) : $existing, []); |
289 | 274 |
|
290 | 275 | if (!\in_array($alias, $existingSelects, true)) {
|
291 | 276 | $queryBuilder->addSelect($alias);
|
|
0 commit comments