Total Complexity | 6 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | final class Context |
||
20 | { |
||
21 | /** |
||
22 | * @var object[] |
||
23 | */ |
||
24 | private array $objects = []; |
||
25 | |||
26 | /** |
||
27 | * @param iterable<object> $objects |
||
28 | */ |
||
29 | public function __construct(iterable $objects = []) |
||
30 | { |
||
31 | foreach ($objects as $object) { |
||
32 | $this->add($object); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Adds an object to the context. |
||
38 | */ |
||
39 | public function add(object $object): self |
||
40 | { |
||
41 | array_unshift($this->objects, $object); |
||
42 | |||
43 | return $this; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Returns the object matching the specified class. |
||
48 | * |
||
49 | * @template T of object |
||
50 | * |
||
51 | * @param class-string<T> $class |
||
1 ignored issue
–
show
|
|||
52 | * |
||
53 | * @return T |
||
54 | * |
||
55 | * @throws NotInContext |
||
56 | */ |
||
57 | public function get(string $class): object |
||
66 | } |
||
67 | } |
||
68 |