Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
InternalListener
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onEvent
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
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\MydbListener;
17
18use Psr\Log\LoggerInterface;
19use sql\MydbEvent\InternalConnectionBegin;
20use sql\MydbEvent\InternalConnectionEnd;
21use sql\MydbEventMetadataInterface;
22use sql\MydbListener;
23use function in_array;
24use function is_array;
25use function is_null;
26
27class InternalListener extends MydbListener
28{
29
30    public function __construct(protected ?LoggerInterface $logger = null)
31    {
32    }
33
34    protected function onEvent(MydbEventMetadataInterface $event): ?bool
35    {
36        if (in_array($event->getEventName(), [InternalConnectionBegin::class, InternalConnectionEnd::class], true)) {
37            if ($this->logger) {
38                $this->logger->debug(
39                    'Received event: ' . $event->getEventName()
40                );
41            }
42        }
43
44        return is_array($event->getEventMetadata()) || is_null($event->getEventMetadata());
45    }
46}