Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MydbEvent
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 getEventMetadata
n/a
0 / 0
n/a
0 / 0
0
 getListeners
n/a
0 / 0
n/a
0 / 0
0
 notify
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 getEventName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This file is part of the sshilko/php-sql-mydb package.
4 *
5 * (c) Sergei Shilko <contact@sshilko.com>
6 *
7 * MIT License
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 * @license https://opensource.org/licenses/mit-license.php MIT
12 */
13
14declare(strict_types = 1);
15
16namespace sql;
17
18use sql\MydbException\EventException;
19
20abstract class MydbEvent implements MydbEventInterface, MydbEventMetadataInterface
21{
22
23    /**
24     * @psalm-return array<array-key, mixed>|null
25     */
26    abstract public function getEventMetadata(): ?array;
27
28    /**
29     * @return array<\sql\MydbListenerInterface>
30     */
31    abstract protected function getListeners(): array;
32
33    /**
34     * @throws \sql\MydbException\EventException
35     */
36    public function notify(): void
37    {
38        foreach ($this->getListeners() as $listenerInstance) {
39            if ($listenerInstance instanceof MydbListenerInterface) {
40                if (false === $listenerInstance->observe($this)) {
41                    break;
42                }
43            } else {
44                throw new EventException();
45            }
46        }
47    }
48
49    public function getEventName(): string
50    {
51        return static::class;
52    }
53}