| Total Complexity | 8 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class FootballSubject implements SubjectInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $subjectName; |
||
| 18 | /** |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | private $observers = []; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * FootballSubject constructor. |
||
| 25 | * @param string $subjectName |
||
| 26 | */ |
||
| 27 | public function __construct(string $subjectName) |
||
| 28 | { |
||
| 29 | $this->subjectName = $subjectName; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param ObserverInterface $observer |
||
| 34 | * @throws \Exception |
||
| 35 | */ |
||
| 36 | public function attachObserver(ObserverInterface $observer): void |
||
| 37 | { |
||
| 38 | if (array_key_exists($observer->getObserverName(), $this->observers)) { |
||
| 39 | throw new \InvalidArgumentException('Observer is already exist'); |
||
| 40 | } |
||
| 41 | |||
| 42 | $this->observers[$observer->getObserverName()] = $observer; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param string $subjectName |
||
| 47 | */ |
||
| 48 | public function detachObserver(string $subjectName): void |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param EventInterface $event |
||
| 59 | */ |
||
| 60 | public function notifyObservers(EventInterface $event): void |
||
| 61 | { |
||
| 62 | foreach ($this->observers as $observer) { |
||
| 63 | printf( |
||
| 64 | "%s has get information about: %s %s \n", |
||
| 65 | $observer->getObserverName(), |
||
| 66 | $this->subjectName, |
||
| 67 | $event->getEventName() |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | public function getSubjectName(): string |
||
| 78 | } |
||
| 79 | } |
||
| 80 |