| Total Complexity | 4 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | abstract class AbstractHandler implements ChainInterface |
||
| 11 | { |
||
| 12 | protected AbstractHandler $nextHandler; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param string $request |
||
| 16 | */ |
||
| 17 | public function execute(string $request): void |
||
| 18 | { |
||
| 19 | if ($request === get_called_class()) { |
||
| 20 | printf("%s %s".PHP_EOL, get_called_class(), "has handle an error"); |
||
| 21 | return; |
||
| 22 | } |
||
| 23 | |||
| 24 | if (!isset($this->nextHandler)) { |
||
| 25 | throw new \InvalidArgumentException($request . " does not exist in the chain"); |
||
| 26 | } |
||
| 27 | |||
| 28 | $this->nextHandler->execute($request); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param AbstractHandler $handler |
||
| 33 | * @return AbstractHandler |
||
| 34 | */ |
||
| 35 | public function setNext(AbstractHandler $handler): AbstractHandler |
||
| 39 | } |
||
| 40 | } |
||
| 41 |