Passed
Push — main ( 4ee80d...af755d )
by Dimitri
03:46
created

EventDiscover   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A discove() 0 12 5
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Event;
13
14
use BlitzPHP\Autoloader\Locator;
15
use BlitzPHP\Container\Services;
16
use BlitzPHP\Contracts\Event\EventListenerInterface;
0 ignored issues
show
Bug introduced by
The type BlitzPHP\Contracts\Event\EventListenerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use BlitzPHP\Contracts\Event\EventManagerInterface;
18
19
/**
20
 * Decouvre et inclus tous les ecouteurs d'evenement
21
 */
22
class EventDiscover
23
{
24
	protected Locator $locator;
25
26
	public function __construct(protected EventManagerInterface $event)
27
	{
28
		$this->locator = Services::locator();
29
	}
30
31
	public function discove()
32
	{
33
		$files = $this->locator->listFiles('Events/');
34
35
		foreach ($files as $file) {
36
            $className = $this->locator->getClassname($file);
37
38
            if ($className === '' || ! class_exists($className) || ! is_a($className, EventListenerInterface::class, true)) {
39
                continue;
40
            }
41
42
			Services::factory($className)->listen($this->event);
43
        }
44
	}
45
}