Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.33% covered (success)
93.33%
14 / 15
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReflectionClassList
93.33% covered (success)
93.33%
14 / 15
66.67% covered (warning)
66.67%
2 / 3
3.00
0.00% covered (danger)
0.00%
0 / 1
 offsetGet
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toStringArray
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 filterOnApieContext
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Core\Lists;
3
4use Apie\Core\Context\ApieContext;
5use Apie\Core\ContextConstants;
6use ReflectionClass;
7
8/**
9 * @extends ItemList<ReflectionClass<object>>
10 */
11final class ReflectionClassList extends ItemList
12{
13    /**
14     * @return ReflectionClass<object>
15     */
16    public function offsetGet(mixed $offset): ReflectionClass
17    {
18        return parent::offsetGet($offset);
19    }
20
21    /**
22     * @return string[]
23     */
24    public function toStringArray(): array
25    {
26        return array_map(
27            function (ReflectionClass $refl) {
28                return $refl->getName();
29            },
30            $this->internal
31        );
32    }
33
34    public function filterOnApieContext(ApieContext $apieContext, bool $runtimeChecks = true): self
35    {
36        $clone = new ReflectionClassList();
37        $clone->internal = array_values(array_filter(
38            $this->internal,
39            function (ReflectionClass $item) use ($apieContext, $runtimeChecks) {
40                return $apieContext->withContext(ContextConstants::RESOURCE_NAME, $item->name)->appliesToContext($item, $runtimeChecks);
41            }
42        ));
43        return $clone;
44    }
45}