Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Methods | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| add | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Boiler; |
| 6 | |
| 7 | use Celemas\Boiler\Exception\UnexpectedValueException; |
| 8 | |
| 9 | /** @internal */ |
| 10 | final class Methods |
| 11 | { |
| 12 | /** @var array<non-empty-string, Method> */ |
| 13 | private array $methods = []; |
| 14 | |
| 15 | /** @param non-empty-string $name */ |
| 16 | public function add(string $name, callable $callable, bool $safe = false): void |
| 17 | { |
| 18 | $this->methods[$name] = new Method($callable, $safe); |
| 19 | } |
| 20 | |
| 21 | public function get(string $name): Method |
| 22 | { |
| 23 | return array_key_exists($name, $this->methods) |
| 24 | ? $this->methods[$name] |
| 25 | : throw new UnexpectedValueException("Method '{$name}' does not exist"); |
| 26 | } |
| 27 | } |