Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
FakeEntityList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
4
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
 getTotalCount
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getIterator
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Faker\Datalayers;
3
4use Apie\Core\Attributes\FakeCount;
5use Apie\Core\BoundedContext\BoundedContextId;
6use Apie\Core\Datalayers\Concerns\CreatePaginatedResultRuntime;
7use Apie\Core\Datalayers\Lists\EntityListInterface;
8use Apie\Core\Datalayers\Search\LazyLoadedListFilterer;
9use Apie\Core\Entities\EntityInterface;
10use Faker\Generator;
11use Iterator;
12use ReflectionClass;
13
14/**
15 * @template T of EntityInterface
16 * @implements EntityListInterface<T>
17 */
18final class FakeEntityList implements EntityListInterface
19{
20    use CreatePaginatedResultRuntime;
21
22    /**
23     * @param ReflectionClass<T> $class
24     */
25    public function __construct(
26        private readonly ReflectionClass $class,
27        private readonly BoundedContextId $boundedContextId,
28        private readonly LazyLoadedListFilterer $filterer,
29        private readonly Generator $faker
30    ) {
31    }
32
33    public function getTotalCount(): int
34    {
35        $attributes = $this->class->getAttributes(FakeCount::class);
36        if (empty($attributes)) {
37            return 10;
38        }
39        return reset($attributes)->newInstance()->count;
40    }
41
42    public function getIterator(): Iterator
43    {
44        $count = $this->getTotalCount();
45
46        return new FakeIterator($count, $this->class, $this->faker);
47    }
48}