Conditions | 5 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 5.3906 |
Changes | 0 |
1 | <?php |
||
50 | 250 | public function set($keyword, $factory) |
|
51 | { |
||
52 | 250 | if (!(is_string($factory) || $factory instanceof \Closure)) { |
|
53 | throw new \InvalidArgumentException( |
||
54 | sprintf('Expected a string or Closure, got %s', gettype($keyword)) |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | 158 | $this->rules[$keyword] = function ($container) use ($factory) { |
|
59 | 158 | static $object; |
|
60 | |||
61 | 158 | if (is_null($object)) { |
|
62 | 158 | $object = is_string($factory) ? new $factory() : $factory($container); |
|
63 | 79 | } |
|
64 | |||
65 | 158 | return $object; |
|
66 | }; |
||
67 | 250 | } |
|
68 | } |
||
69 |