| Total Complexity | 6 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 9 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | class FootballSubject implements SubjectInterface |
||
| 13 | { |
||
| 14 | use NameTrait; |
||
| 15 | |||
| 16 | private array $observers = []; |
||
| 17 | |||
| 18 | public function attachObserver(ObserverInterface $observer): void |
||
| 19 | { |
||
| 20 | if (array_key_exists($observer->getName(), $this->observers)) { |
||
| 21 | throw new \InvalidArgumentException("Observer is already exist"); |
||
| 22 | } |
||
| 23 | |||
| 24 | $this->observers[$observer->getName()] = $observer; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function detachObserver(string $name): void |
||
| 28 | { |
||
| 29 | if (!array_key_exists($name, $this->observers)) { |
||
| 30 | throw new \InvalidArgumentException("Observer is not exist"); |
||
| 31 | } |
||
| 32 | |||
| 33 | unset($this->observers[$name]); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function notifyObservers(EventInterface $event): void |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | } |
||
| 48 |