Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       7 / 7  | 
               | 
       100.00%  | 
       3 / 3  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| FakeEntityList |         | 
       100.00%  | 
       7 / 7  | 
               | 
       100.00%  | 
       3 / 3  | 
       4 |         | 
       100.00%  | 
       1 / 1  | 
      
| __construct |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| getTotalCount |         | 
       100.00%  | 
       4 / 4  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| getIterator |         | 
       100.00%  | 
       2 / 2  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| 1 | <?php | 
| 2 | namespace Apie\Faker\Datalayers; | 
| 3 | |
| 4 | use Apie\Core\Attributes\FakeCount; | 
| 5 | use Apie\Core\BoundedContext\BoundedContextId; | 
| 6 | use Apie\Core\Datalayers\Concerns\CreatePaginatedResultRuntime; | 
| 7 | use Apie\Core\Datalayers\Lists\EntityListInterface; | 
| 8 | use Apie\Core\Datalayers\Search\LazyLoadedListFilterer; | 
| 9 | use Apie\Core\Entities\EntityInterface; | 
| 10 | use Faker\Generator; | 
| 11 | use Iterator; | 
| 12 | use ReflectionClass; | 
| 13 | |
| 14 | /** | 
| 15 | * @template T of EntityInterface | 
| 16 | * @implements EntityListInterface<T> | 
| 17 | */ | 
| 18 | final 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 | } |