Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DoctrineListFactory
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFor
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\DoctrineEntityDatalayer\Factories;
3
4use Apie\Core\BoundedContext\BoundedContextId;
5use Apie\Core\Datalayers\Lists\EntityListInterface;
6use Apie\Core\Entities\EntityInterface;
7use Apie\DoctrineEntityDatalayer\Lists\DoctrineEntityList;
8use Apie\DoctrineEntityDatalayer\OrmBuilder;
9use Apie\StorageMetadata\DomainToStorageConverter;
10use ReflectionClass;
11
12final class DoctrineListFactory
13{
14    public function __construct(
15        private readonly OrmBuilder $ormBuilder,
16        private readonly EntityQueryFilterFactory $entityQueryFilterFactory,
17        private readonly DomainToStorageConverter $domainToStorageConverter
18    ) {
19    }
20
21    /**
22     * @template T of EntityInterface
23     * @param ReflectionClass<T> $entityClass
24     * @param ReflectionClass<object> $doctrineEntityClass
25     * @return EntityListInterface<T>
26     */
27    public function createFor(ReflectionClass $entityClass, ReflectionClass $doctrineEntityClass, BoundedContextId $boundedContextId): EntityListInterface
28    {
29        $filters = $this->entityQueryFilterFactory->createFilterList($doctrineEntityClass, $boundedContextId);
30        $entityQueryFactory = new EntityQueryFactory(
31            $this->ormBuilder->createEntityManager(),
32            $doctrineEntityClass,
33            $boundedContextId,
34            ...$filters
35        );
36        return new DoctrineEntityList(
37            $this->ormBuilder,
38            $this->domainToStorageConverter,
39            $entityQueryFactory,
40            $entityClass,
41            $boundedContextId
42        );
43    }
44}