Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ItemListFaker
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 fakeFor
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Apie\Faker\Fakers;
4
5use Apie\Core\Lists\ItemList;
6use Apie\Faker\Interfaces\ApieClassFaker;
7use Faker\Generator;
8use ReflectionClass;
9
10/** @implements ApieClassFaker<ItemList> */
11class ItemListFaker implements ApieClassFaker
12{
13    public function supports(ReflectionClass $class): bool
14    {
15        return $class->isSubclassOf(ItemList::class) || $class->name === ItemList::class;
16    }
17
18    public function fakeFor(Generator $generator, ReflectionClass $class): object
19    {
20        $returnType = $class->getMethod('offsetGet')->getReturnType();
21        $itemCount = $generator->numberBetween(1, 4);
22        $arguments = [];
23        for ($i = 0; $i < $itemCount; $i++) {
24            $arguments[] = $generator->fakeFromType($returnType);
25        }
26        return $class->newInstance($arguments);
27    }
28}