Test Failed
Push — master ( 2eb5f5...513ae9 )
by Maximo
12:27 queued 05:35
created

EventsManagerProvider::attachEvents()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 1
b 0
f 1
nc 3
nop 2
dl 0
loc 17
ccs 0
cts 13
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Canvas\Providers;
4
5
use Phalcon\Di\ServiceProviderInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\Di\ServiceProviderInterface 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...
6
use Phalcon\DiInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\DiInterface 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...
7
use Canvas\Listener\Subscription;
8
use Canvas\EventsManager;
9
use Canvas\Listener\User;
10
11
class EventsManagerProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * List of the listeners use by the app.
15
     *
16
     * [
17
     *  'eventName' => 'className'
18
     * ];
19
     *
20
     * @var array
21
     */
22
    protected $listeners = [
23
    ];
24
25
    protected $canvasListeners = [
26
        'subscription' => Subscription::class,
27
        'user' => User::class,
28
    ];
29
30
    /**
31
     * @param DiInterface $container
32
     */
33
    public function register(DiInterface $container)
34
    {
35
        $container->setShared(
36
            'events',
37
            function () {
38
                $eventsManager = new EventsManager();
39
40
                return $eventsManager;
41
            }
42
        );
43
44
        $this->attachEvents($container, $this->listeners);
45
        $this->attachEvents($container, $this->canvasListeners);
46
    }
47
48
    /**
49
     * given the DI attach the list of containers.
50
     *
51
     * @param DiInterface $container
52
     * @param array $listeners
53
     * @return void
54
     */
55
    protected function attachEvents(DiInterface $container, array $listeners): bool
56
    {
57
        if (empty($listeners)) {
58
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type void.
Loading history...
59
        }
60
        $eventsManager = $container->get('eventsManager');
61
62
        //navigate the list of listener and create the events
63
        foreach ($listeners as $key => $listen) {
64
            //create the events given the key
65
            $eventsManager->attach(
66
                $key,
67
                new $listen()
68
            );
69
        }
70
71
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type void.
Loading history...
72
    }
73
}
74