Total Complexity | 4 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
14 | class ClassLoader extends AbstractLoader |
||
15 | { |
||
16 | /** |
||
17 | * Logic to create entries |
||
18 | * @var callable |
||
19 | */ |
||
20 | protected $apply; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * MappingGenerator constructor. |
||
25 | * |
||
26 | * @param \Iterator $classes |
||
27 | * @param callable $apply Logic to create entries for a class |
||
28 | */ |
||
29 | 8 | public function __construct(\Iterator $classes, callable $apply = null) |
|
30 | { |
||
31 | 8 | $this->apply = $apply ?? [$this, 'createEntry']; |
|
32 | |||
33 | 8 | parent::__construct($classes); |
|
34 | 7 | } |
|
35 | |||
36 | |||
37 | /** |
||
38 | * Create new entries |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | 8 | protected function prepareNext(): void |
|
43 | { |
||
44 | 8 | if (!$this->items->valid()) { |
|
45 | 2 | return; |
|
46 | } |
||
47 | |||
48 | 6 | $class = $this->items->current(); |
|
49 | 6 | $entries = call_user_func($this->apply, $class); |
|
50 | |||
51 | 6 | expect_type($entries, 'array', \UnexpectedValueException::class, |
|
52 | 6 | "Failed to load container entries for '$class': Expected array, callback returned %s"); |
|
53 | |||
54 | 5 | $this->entries = new \ArrayIterator($entries); |
|
55 | |||
56 | 5 | $this->items->next(); |
|
57 | 5 | } |
|
58 | |||
59 | /** |
||
60 | * Create a container entry for a class using autowiring. |
||
61 | * |
||
62 | * @param string $class |
||
63 | * @return \Closure[] |
||
64 | */ |
||
65 | 1 | protected function createEntry(string $class) |
|
70 | 1 | } |
|
71 | ]; |
||
72 | } |
||
74 |