| Conditions | 5 |
| Paths | 2 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 5.2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 50 | 242 | public function set($keyword, $factory) |
|
| 51 | { |
||
| 52 | 242 | 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 | 150 | $this->rules[$keyword] = function ($container) use ($factory) { |
|
| 59 | 150 | static $object; |
|
| 60 | |||
| 61 | 150 | if (is_null($object)) { |
|
| 62 | 150 | $object = is_string($factory) ? new $factory() : $factory($container); |
|
| 63 | } |
||
| 64 | |||
| 65 | 150 | return $object; |
|
| 66 | }; |
||
| 67 | 242 | } |
|
| 68 | } |
||
| 69 |