• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nextras / orm / 41909495460

04 Nov 2026 08:44PM UTC coverage: 92.015% (-0.002%) from 92.017%
41909495460

push

github

web-flow
Merge pull request #842 from nextras/js/dresscode

Setup DressCode

288 of 347 new or added lines in 66 files covered. (83.0%)

14 existing lines in 9 files now uncovered.

4402 of 4784 relevant lines covered (92.02%)

6.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.5
/src/Collection/Functions/FetchPropertyFunction.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Collection\Functions;
4

5

6
use Nette\Utils\Arrays;
7
use Nextras\Dbal\Platforms\Data\Column;
8
use Nextras\Dbal\Platforms\Data\Fqn;
9
use Nextras\Dbal\QueryBuilder\QueryBuilder;
10
use Nextras\Orm\Collection\Aggregations\Aggregator;
11
use Nextras\Orm\Collection\Aggregations\AnyAggregator;
12
use Nextras\Orm\Collection\Functions\Result\ArrayExpressionResult;
13
use Nextras\Orm\Collection\Functions\Result\DbalExpressionResult;
14
use Nextras\Orm\Collection\Functions\Result\DbalTableJoin;
15
use Nextras\Orm\Collection\Helpers\ArrayCollectionHelper;
16
use Nextras\Orm\Collection\Helpers\DbalQueryBuilderHelper;
17
use Nextras\Orm\Entity\Embeddable\EmbeddableContainer;
18
use Nextras\Orm\Entity\IEntity;
19
use Nextras\Orm\Entity\Reflection\EntityMetadata;
20
use Nextras\Orm\Entity\Reflection\PropertyMetadata;
21
use Nextras\Orm\Entity\Reflection\PropertyRelationshipMetadata;
22
use Nextras\Orm\Entity\Reflection\PropertyRelationshipMetadata as Relationship;
23
use Nextras\Orm\Exception\InvalidArgumentException;
24
use Nextras\Orm\Exception\InvalidStateException;
25
use Nextras\Orm\Mapper\Dbal\Conventions\IConventions;
26
use Nextras\Orm\Mapper\Dbal\DbalMapper;
27
use Nextras\Orm\Mapper\IMapper;
28
use Nextras\Orm\Model\IModel;
29
use Nextras\Orm\Repository\IRepository;
30
use function array_values;
31
use function assert;
32
use function count;
33
use function is_array;
34

35

36
class FetchPropertyFunction implements CollectionFunction
37
{
38
        public function __construct(
5 ✔
39
                /** @var IRepository<*> */
40
                private readonly IRepository $repository,
2 ✔
41
                /** @var IMapper<*> */
42
                private readonly IMapper $mapper,
2 ✔
43
                private readonly IModel $model,
2 ✔
44
        )
45
        {
46
        }
7 ✔
47

48

49
        public function processArrayExpression(
50
                ArrayCollectionHelper $helper,
51
                IEntity $entity,
52
                array $args,
53
                Aggregator|null $aggregator = null,
54
        ): ArrayExpressionResult
55
        {
56
                $argsCount = count($args);
7 ✔
57
                if ($argsCount !== 1) {
7 ✔
58
                        throw new InvalidArgumentException("Expected 1 string argument, $argsCount given.");
×
59
                }
60
                $lhs = $args[0];
7 ✔
61
                if (!is_string($lhs)) {
7 ✔
62
                        $type = gettype($lhs);
×
63
                        throw new InvalidArgumentException("Expected one string argument, $type type given.");
×
64
                }
65

66
                [$tokens, $sourceEntityClassName] = $this->repository->getConditionParser()->parsePropertyExpr($lhs);
7 ✔
67
                $sourceEntityMeta = $this->repository->getEntityMetadata($sourceEntityClassName);
7 ✔
68
                return $this->getValueByTokens($helper, $entity, $tokens, $sourceEntityMeta, $aggregator);
7 ✔
69
        }
70

71

72
        /**
73
         * @param string[] $expressionTokens
74
         * @param Aggregator<mixed>|null $aggregator
75
         */
76
        private function getValueByTokens(
77
                ArrayCollectionHelper $helper,
78
                IEntity $entity,
79
                array $expressionTokens,
80
                EntityMetadata $sourceEntityMeta,
81
                Aggregator|null $aggregator,
82
        ): ArrayExpressionResult
83
        {
84
                if (!$entity instanceof $sourceEntityMeta->className) {
7 ✔
85
                        return new ArrayExpressionResult(
7 ✔
86
                                value: new class {
7 ✔
87
                                        public function __toString()
88
                                        {
NEW
89
                                                return 'undefined';
×
90
                                        }
91
                                },
92
                        );
93
                }
94

95
                $isMultiValue = false;
7 ✔
96
                $values = [];
7 ✔
97
                $stack = [[$entity, $expressionTokens, $sourceEntityMeta]];
7 ✔
98

99
                do {
100
                        /** @var array{IEntity,array<string>,EntityMetadata}|null $shift */
101
                        $shift = array_shift($stack);
7 ✔
102
                        assert($shift !== null);
103
                        $value = $shift[0];
7 ✔
104
                        $tokens = $shift[1];
7 ✔
105
                        $entityMeta = $shift[2];
7 ✔
106

107
                        do {
108
                                $propertyName = array_shift($tokens);
7 ✔
109
                                assert($propertyName !== null);
110
                                $propertyMeta = $entityMeta->getProperty($propertyName); // check if property exists
7 ✔
111
                                // We allow cycling-through even if $value is null to properly detect $isMultiValue
112
                                // to return related aggregator.
113
                                $value = $value !== null && $value->hasValue($propertyName) ? $value->getValue($propertyName) : null;
7 ✔
114

115
                                if ($propertyMeta->relationship) {
7 ✔
116
                                        $entityMeta = $propertyMeta->relationship->entityMetadata;
7 ✔
117
                                        $type = $propertyMeta->relationship->type;
7 ✔
118
                                        if (
119
                                                $type === PropertyRelationshipMetadata::MANY_HAS_MANY
7 ✔
120
                                                || $type === PropertyRelationshipMetadata::ONE_HAS_MANY
7 ✔
121
                                        ) {
122
                                                $isMultiValue = true;
7 ✔
123
                                                if ($value !== null) {
7 ✔
124
                                                        foreach ($value as $subEntity) {
7 ✔
125
                                                                if ($subEntity instanceof $entityMeta->className) {
7 ✔
126
                                                                        $stack[] = [$subEntity, $tokens, $entityMeta];
7 ✔
127
                                                                }
128
                                                        }
129
                                                }
130
                                                continue 2;
7 ✔
131
                                        }
132
                                } elseif ($propertyMeta->wrapper === EmbeddableContainer::class) {
7 ✔
133
                                        assert($propertyMeta->args !== null);
134
                                        $entityMeta = $propertyMeta->args[EmbeddableContainer::class]['metadata'];
7 ✔
135
                                }
136
                        } while ($tokens !== []);
7 ✔
137

138
                        $values[] = $helper->normalizeValue($value, $propertyMeta, checkMultiDimension: false);
7 ✔
139
                } while ($stack !== []);
7 ✔
140

141
                if ($propertyMeta->wrapper === EmbeddableContainer::class) {
7 ✔
142
                        $propertyExpression = implode('->', $expressionTokens);
7 ✔
143
                        throw new InvalidArgumentException("Property expression '$propertyExpression' does not fetch specific property.");
7 ✔
144
                }
145

146
                return new ArrayExpressionResult(
7 ✔
147
                        value: $isMultiValue ? $values : $values[0],
7 ✔
148
                        aggregator: $isMultiValue ? ($aggregator ?? new AnyAggregator()) : null,
7 ✔
149
                        propertyMetadata: $propertyMeta,
150
                );
151
        }
152

153

154
        public function processDbalExpression(
155
                DbalQueryBuilderHelper $helper,
156
                QueryBuilder $builder,
157
                array $args,
158
                Aggregator|null $aggregator = null,
159
        ): DbalExpressionResult
160
        {
161
                $argsCount = count($args);
7 ✔
162
                if ($argsCount !== 1) {
7 ✔
163
                        throw new InvalidArgumentException("Expected 1 string argument, $argsCount given.");
×
164
                }
165
                $lhs = $args[0];
7 ✔
166
                if (!is_string($lhs)) {
7 ✔
167
                        $type = gettype($lhs);
×
168
                        throw new InvalidArgumentException("Expected one string argument, $type type given.");
×
169
                }
170

171
                [$tokens, $sourceEntity] = $this->repository->getConditionParser()->parsePropertyExpr($lhs);
7 ✔
172
                return $this->processTokens($tokens, $sourceEntity, $builder, $aggregator);
7 ✔
173
        }
174

175

176
        /**
177
         * @param array<string> $tokens
178
         * @param class-string<IEntity>|null $sourceEntity
179
         * @param Aggregator<mixed>|null $aggregator
180
         */
181
        private function processTokens(
182
                array $tokens,
183
                string|null $sourceEntity,
184
                QueryBuilder $builder,
185
                Aggregator|null $aggregator,
186
        ): DbalExpressionResult
187
        {
188
                $lastToken = array_pop($tokens);
7 ✔
189
                assert($lastToken !== null);
190

191
                $currentMapper = $this->getDbalMapper();
7 ✔
192
                $currentAlias = $builder->getFromAlias();
7 ✔
193
                assert($currentAlias !== null);
194

195
                $currentConventions = $currentMapper->getConventions();
7 ✔
196
                $currentEntityMetadata = $currentMapper->getRepository()->getEntityMetadata($sourceEntity);
7 ✔
197
                $propertyPrefixTokens = '';
7 ✔
198
                $makeDistinct = false;
7 ✔
199

200
                /** @var list<DbalTableJoin> $joins */
201
                $joins = [];
7 ✔
202

203
                foreach ($tokens as $tokenIndex => $token) {
7 ✔
204
                        $property = $currentEntityMetadata->getProperty($token);
7 ✔
205
                        if ($property->relationship !== null) {
7 ✔
206
                                $relType = $property->relationship->type;
7 ✔
207

208
                                // The foreign key lives on the current table (m:1 or the owning side of 1:1), so the
209
                                // related entity's primary key can be read straight from that column.
210
                                $isForeignKeyOnCurrentTable = $relType === Relationship::MANY_HAS_ONE
7 ✔
211
                                        || ($relType === Relationship::ONE_HAS_ONE && $property->relationship->isMain);
7 ✔
212

213
                                // Optimization: the expression ends with `<relation>-><primaryKey>` and the foreign key
214
                                // is local, so we can read the key from the current table and skip the JOIN to the target.
215
                                // e.g. `book->author->id` reads `books.author_id` without JOINing the `authors` table.
216
                                $isRelationToOwnPrimaryKey = $isForeignKeyOnCurrentTable
7 ✔
217
                                        && $tokenIndex === count($tokens) - 1
7 ✔
218
                                        && in_array($lastToken, $property->relationship->entityMetadata->getPrimaryKey(), strict: true);
7 ✔
219
                                if ($isRelationToOwnPrimaryKey) {
7 ✔
220
                                        $lastToken = $token;
7 ✔
221
                                        break;
7 ✔
222
                                }
223

224
                                [
225
                                        $currentAlias,
7 ✔
226
                                        $currentConventions,
7 ✔
227
                                        $currentEntityMetadata,
7 ✔
228
                                        $currentMapper,
7 ✔
229
                                ] = $this->processRelationship(
7 ✔
230
                                        $tokens,
7 ✔
231
                                        $joins,
232
                                        $property,
233
                                        $aggregator,
234
                                        $currentConventions,
235
                                        $currentMapper,
236
                                        $currentAlias,
237
                                        $token,
238
                                        $tokenIndex,
239
                                        $makeDistinct,
240
                                );
241

242
                        } elseif ($property->wrapper === EmbeddableContainer::class) {
7 ✔
243
                                assert($property->args !== null);
244
                                $currentEntityMetadata = $property->args[EmbeddableContainer::class]['metadata'];
7 ✔
245
                                $propertyPrefixTokens .= "$token->";
7 ✔
246
                        } else {
UNCOV
247
                                throw new InvalidArgumentException("Entity $currentEntityMetadata->className::\$$token does not contain a relationship or an embeddable.");
×
248
                        }
249
                }
250

251
                $propertyMetadata = $currentEntityMetadata->getProperty($lastToken);
7 ✔
252
                if ($propertyMetadata->wrapper === EmbeddableContainer::class) {
7 ✔
253
                        $propertyExpression = implode('->', array_merge($tokens, [$lastToken]));
7 ✔
254
                        throw new InvalidArgumentException("Property expression '$propertyExpression' does not fetch specific property.");
7 ✔
255
                }
256

257
                if ($propertyMetadata->relationship !== null) {
7 ✔
258
                        $relType = $propertyMetadata->relationship->type;
7 ✔
259

260
                        // The final property is itself a relationship whose foreign key is *not* on the current
261
                        // table (non-owning side of 1:1, 1:m, m:m), so there is no local column to read: JOIN to the
262
                        // target table and compare against its primary key instead.
263
                        // e.g. `ean->book`, where Ean is the non-owning side, JOINs `books` and compares `books.id`.
264
                        // (A terminal main-side relationship such as `book->author` is not handled here; toColumnExpr()
265
                        // maps it directly onto the local `author_id` column.)
266
                        $isForeignKeyOnTargetTable =
7 ✔
267
                                ($relType === Relationship::ONE_HAS_ONE && !$propertyMetadata->relationship->isMain)
7 ✔
268
                                || $relType === Relationship::ONE_HAS_MANY
7 ✔
269
                                || $relType === Relationship::MANY_HAS_MANY;
7 ✔
270
                        if ($isForeignKeyOnTargetTable) {
7 ✔
271
                                $allTokens = [...$tokens, $lastToken];
7 ✔
272
                                [
273
                                        $currentAlias,
7 ✔
274
                                        $currentConventions,
7 ✔
275
                                        $currentEntityMetadata,
7 ✔
276
                                ] = $this->processRelationship(
7 ✔
277
                                        $allTokens,
7 ✔
278
                                        $joins,
279
                                        $propertyMetadata,
280
                                        $aggregator,
281
                                        $currentConventions,
282
                                        $currentMapper,
283
                                        $currentAlias,
284
                                        $lastToken,
285
                                        count($allTokens) - 1,
7 ✔
286
                                        $makeDistinct,
287
                                );
288
                                $primaryKey = $currentEntityMetadata->getPrimaryKey();
7 ✔
289
                                $lastToken = $primaryKey[0];
7 ✔
290
                                $propertyMetadata = $currentEntityMetadata->getProperty($lastToken);
7 ✔
291
                        }
292
                }
293

294
                $column = $this->toColumnExpr(
7 ✔
295
                        $currentEntityMetadata,
2 ✔
296
                        $propertyMetadata,
297
                        $currentConventions,
298
                        $currentAlias,
299
                        $propertyPrefixTokens,
300
                        $modifier,
301
                );
302

303
                return new DbalExpressionResult(
7 ✔
304
                        expression: '%column',
7 ✔
305
                        args: [$column],
7 ✔
306
                        joins: $joins,
307
                        groupBy: $makeDistinct ? $this->createBaseGroupBy($builder, $this->getDbalMapper()) : [],
7 ✔
308
                        columns: is_array($column) ? $column : [$column],
7 ✔
309
                        aggregator: $makeDistinct ? ($aggregator ?? new AnyAggregator()) : null,
7 ✔
310
                        propertyMetadata: $propertyMetadata,
311
                        valueNormalizer: fn($value) => $this->normalizeValue($value, $propertyMetadata, $currentConventions),
7 ✔
312
                        dbalModifier: $modifier,
313
                );
314
        }
315

316

317
        /**
318
         * @param array<string> $tokens
319
         * @param list<DbalTableJoin> $joins
320
         * @param Aggregator<mixed>|null $aggregator
321
         * @param DbalMapper<*> $currentMapper
322
         * @return array{string, IConventions, EntityMetadata, DbalMapper<*>}
323
         */
324
        private function processRelationship(
325
                array $tokens,
326
                array &$joins,
327
                PropertyMetadata $property,
328
                Aggregator|null $aggregator,
329
                IConventions $currentConventions,
330
                DbalMapper $currentMapper,
331
                string $currentAlias,
332
                mixed $token,
333
                int $tokenIndex,
334
                bool &$makeDistinct,
335
        ): array
336
        {
337
                assert($property->relationship !== null);
338
                $targetMapper = $this->model->getRepository($property->relationship->repository)->getMapper();
7 ✔
339
                assert($targetMapper instanceof DbalMapper);
340

341
                $targetConventions = $targetMapper->getConventions();
7 ✔
342
                $targetEntityMetadata = $property->relationship->entityMetadata;
7 ✔
343

344
                $relType = $property->relationship->type;
7 ✔
345

346
                if ($relType === Relationship::ONE_HAS_ONE && !$property->relationship->isMain) {
7 ✔
347
                        assert($property->relationship->property !== null);
348
                        $toColumn = $targetConventions->convertEntityToStorageKey($property->relationship->property);
7 ✔
349
                        $fromColumn = $currentConventions->getStoragePrimaryKey()[0];
7 ✔
350
                } elseif ($relType === Relationship::ONE_HAS_ONE || $relType === Relationship::MANY_HAS_ONE) {
7 ✔
351
                        $toColumn = $targetConventions->getStoragePrimaryKey()[0];
7 ✔
352
                        $fromColumn = $currentConventions->convertEntityToStorageKey($token);
7 ✔
353
                } elseif ($relType === Relationship::ONE_HAS_MANY) {
7 ✔
354
                        $makeDistinct = true;
7 ✔
355

356
                        assert($property->relationship->property !== null);
357
                        $toColumn = $targetConventions->convertEntityToStorageKey($property->relationship->property);
7 ✔
358
                        $fromColumn = $currentConventions->getStoragePrimaryKey()[0];
7 ✔
359
                } elseif ($relType === Relationship::MANY_HAS_MANY) {
7 ✔
360
                        $makeDistinct = true;
7 ✔
361

362
                        $toColumn = $targetConventions->getStoragePrimaryKey()[0];
7 ✔
363
                        $fromColumn = $currentConventions->getStoragePrimaryKey()[0];
7 ✔
364

365
                        if ($property->relationship->isMain) {
7 ✔
366
                                [$joinTable, [$inColumn, $outColumn]] =
7 ✔
367
                                        $currentMapper->getManyHasManyParameters($property, $targetMapper);
7 ✔
368
                        } else {
369
                                assert($property->relationship->property !== null);
370
                                $sourceProperty = $targetEntityMetadata->getProperty($property->relationship->property);
7 ✔
371
                                [$joinTable, [$outColumn, $inColumn]] =
7 ✔
372
                                        $targetMapper->getManyHasManyParameters($sourceProperty, $currentMapper);
7 ✔
373
                        }
374

375
                        $aggregator ??= new AnyAggregator();
7 ✔
376
                        /** @var literal-string $joinAlias */
377
                        $joinAlias = DbalQueryBuilderHelper::getAlias($joinTable, array_slice($tokens, 0, $tokenIndex));
7 ✔
378
                        $joinAlias .= '_' . $aggregator->getAggregateKey();
7 ✔
379

380
                        $joins[] = new DbalTableJoin(
7 ✔
381
                                toExpression: '%table',
7 ✔
382
                                toArgs: [$joinTable],
7 ✔
383
                                toAlias: $joinAlias,
384
                                onExpression: '%table.%column = %table.%column',
7 ✔
385
                                onArgs: [$currentAlias, $fromColumn, $joinAlias, $inColumn],
7 ✔
386
                                toPrimaryKey: new Fqn(schema: $currentAlias, name: $currentConventions->getStoragePrimaryKey()[0]),
7 ✔
387
                        );
388

389
                        $currentAlias = $joinAlias;
7 ✔
390
                        $fromColumn = $outColumn;
7 ✔
391
                } else {
UNCOV
392
                        throw new InvalidStateException('Should not happen.');
×
393
                }
394

395
                $targetTable = $targetMapper->getTableName();
7 ✔
396
                /** @var literal-string $targetAlias */
397
                $targetAlias = DbalQueryBuilderHelper::getAlias($tokens[$tokenIndex], array_slice($tokens, 0, $tokenIndex));
7 ✔
398
                if ($makeDistinct) {
7 ✔
399
                        $aggregator ??= new AnyAggregator();
7 ✔
400
                        $targetAlias .= '_' . $aggregator->getAggregateKey();
7 ✔
401
                }
402
                $joins[] = new DbalTableJoin(
7 ✔
403
                        toExpression: '%table',
7 ✔
404
                        toArgs: [$targetTable],
7 ✔
405
                        toAlias: $targetAlias,
406
                        onExpression: '%table.%column = %table.%column',
7 ✔
407
                        onArgs: [$currentAlias, $fromColumn, $targetAlias, $toColumn],
7 ✔
408
                        toPrimaryKey: new Fqn(schema: $targetAlias, name: $targetConventions->getStoragePrimaryKey()[0]),
7 ✔
409
                );
410

411
                return [$targetAlias, $targetConventions, $targetEntityMetadata, $targetMapper];
7 ✔
412
        }
413

414

415
        /**
416
         * @param literal-string|list<literal-string|null>|null $modifier
417
         * @return Fqn|list<Fqn>
418
         */
419
        private function toColumnExpr(
420
                EntityMetadata $entityMetadata,
421
                PropertyMetadata $propertyMetadata,
422
                IConventions $conventions,
423
                string $alias,
424
                string $propertyPrefixTokens,
425
                string|array|null &$modifier,
426
        ): Fqn|array
427
        {
428
                if ($propertyMetadata->isPrimary && $propertyMetadata->isVirtual) { // primary-proxy
7 ✔
429
                        $primaryKey = $entityMetadata->getPrimaryKey();
7 ✔
430
                        if (count($primaryKey) > 1) { // composite primary key
7 ✔
431
                                $pair = [];
7 ✔
432
                                /** @var list<literal-string|null> $modifiers */
433
                                $modifiers = [];
7 ✔
434
                                foreach ($primaryKey as $columnName) {
7 ✔
435
                                        $columnName = $conventions->convertEntityToStorageKey($propertyPrefixTokens . $columnName);
7 ✔
436
                                        $pair[] = new Fqn(schema: $alias, name: $columnName);
7 ✔
437
                                        $modifiers[] = $conventions->getModifier($columnName);
7 ✔
438
                                }
439
                                $modifier = $modifiers;
7 ✔
440
                                return $pair;
7 ✔
441
                        } else {
442
                                $propertyName = $primaryKey[0];
7 ✔
443
                        }
444
                } else {
445
                        $propertyName = $propertyMetadata->name;
7 ✔
446
                }
447

448
                $columnName = $conventions->convertEntityToStorageKey($propertyPrefixTokens . $propertyName);
7 ✔
449
                $modifier = $conventions->getModifier($columnName);
7 ✔
450
                return new Fqn(schema: $alias, name: $columnName);
7 ✔
451
        }
452

453

454
        /**
455
         * @param DbalMapper<*> $mapper
456
         * @return list<Fqn>
457
         */
458
        private function createBaseGroupBy(QueryBuilder $builder, DbalMapper $mapper): array
459
        {
460
                $baseTable = $builder->getFromAlias();
7 ✔
461
                assert($baseTable !== null);
462

463
                if ($mapper->getDatabasePlatform()->getName() === 'mssql') {
7 ✔
464
                        $tableName = $mapper->getConventions()->getStorageTable();
7 ✔
465
                        $columns = $mapper->getDatabasePlatform()->getColumns(
7 ✔
466
                                table: $tableName->fqnName->name,
7 ✔
467
                                schema: $tableName->fqnName->schema,
7 ✔
468
                        );
469
                        $groupBy = array_values(array_map(
7 ✔
470
                                fn(Column $column): Fqn => new Fqn(schema: $baseTable, name: $column->name),
7 ✔
471
                                $columns,
472
                        ));
473
                        return $groupBy;
7 ✔
474
                } else {
475
                        $primaryKey = $this->getDbalMapper()->getConventions()->getStoragePrimaryKey();
7 ✔
476
                        $groupBy = [];
7 ✔
477
                        foreach ($primaryKey as $column) {
7 ✔
478
                                $groupBy[] = new Fqn(schema: $baseTable, name: $column);
7 ✔
479
                        }
480
                        return $groupBy;
7 ✔
481
                }
482
        }
483

484

485
        public function normalizeValue(mixed $value, PropertyMetadata $propertyMetadata, IConventions $conventions): mixed
486
        {
487
                if (isset($propertyMetadata->types['array'])) {
7 ✔
488
                        if (is_array($value) && !is_array(reset($value))) {
7 ✔
489
                                $value = [$value];
7 ✔
490
                        }
491
                        if ($propertyMetadata->isPrimary) {
7 ✔
492
                                foreach ($value as $subValue) {
7 ✔
493
                                        if (!Arrays::isList($subValue)) {
7 ✔
494
                                                throw new InvalidArgumentException('Composite primary value has to be passed as a list, without array keys.');
7 ✔
495
                                        }
496
                                }
497
                        }
498
                }
499

500
                if ($propertyMetadata->wrapper !== null) {
7 ✔
501
                        $property = $propertyMetadata->getWrapperPrototype();
7 ✔
502
                        if (is_array($value)) {
7 ✔
503
                                $value = array_map(fn($subValue) => $property->convertToRawValue($subValue), $value);
7 ✔
504
                        } else {
505
                                $value = $property->convertToRawValue($value);
7 ✔
506
                        }
507
                }
508

509
                $tmp = $conventions->convertEntityToStorage([$propertyMetadata->name => $value]);
7 ✔
510
                $value = reset($tmp);
7 ✔
511

512
                return $value;
7 ✔
513
        }
514

515

516
        /**
517
         * @return DbalMapper<*>
518
         */
519
        private function getDbalMapper(): DbalMapper
520
        {
521
                if (!$this->mapper instanceof DbalMapper) {
7 ✔
NEW
522
                        $repository = $this->repository::class;
×
NEW
523
                        $actual = $this->mapper::class;
×
UNCOV
524
                        throw new InvalidStateException("Repository $repository must use DbalMapper. $actual used instead.");
×
525
                }
526

527
                return $this->mapper;
7 ✔
528
        }
529
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc