Conditions | 3 |
Paths | 3 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
39 | 3 | public function set(string $id, $value) |
|
40 | { |
||
41 | 3 | if(isset($this->container[$id])){ |
|
42 | 1 | throw new ContainerException(sprintf( |
|
43 | 1 | 'Element with id %s already exists. You must use "extend" to modify the value', |
|
44 | 1 | $id |
|
45 | )); |
||
46 | } |
||
47 | |||
48 | 3 | if(is_callable($value)){ |
|
49 | 1 | $me = $this; |
|
50 | 1 | $result = function() use($value, $me){ |
|
51 | 1 | return $value($me); |
|
52 | 1 | }; |
|
53 | |||
54 | 1 | $value = $result; |
|
55 | } |
||
56 | |||
57 | 3 | $this->container[$id] = $value; |
|
58 | 3 | } |
|
72 | } |