InotifyConsumerFactory::consume()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 20
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inotify;
6
7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class InotifyConsumerFactory
12
{
13
    private $inotifyProxy;
14
    /**
15
     * @var EventDispatcherInterface
16
     */
17
    private $eventDispatcher;
18
19
    public function __construct(
20
        InotifyProxyInterface $inotifyProxy = null,
21
        EventDispatcherInterface $eventDispatcher = null
22
    ) {
23
        $this->inotifyProxy = $inotifyProxy;
24
        $this->eventDispatcher = $eventDispatcher;
25
26
        if (null === $eventDispatcher) {
27
            $this->eventDispatcher = new EventDispatcher();
28
        }
29
        if (null === $inotifyProxy) {
30
            $this->inotifyProxy = new InotifyProxy();
31
        }
32
    }
33
34
    /**
35
     * @param WatchedResourceCollection|WatchedResource[] $collection
36
     */
37
    public function consume(WatchedResourceCollection $collection): void
38
    {
39
        foreach ($collection as $resource) {
40
            $this->inotifyProxy->addWatch($resource);
0 ignored issues
show
Bug introduced by
The method addWatch() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            $this->inotifyProxy->/** @scrutinizer ignore-call */ 
41
                                 addWatch($resource);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        }
42
43
        while ($events = $this->inotifyProxy->read()) {
44
            foreach ($events as $event) {
45
                $this->eventDispatcher->dispatch($event);
46
            }
47
        }
48
49
        $this->inotifyProxy->closeWatchers();
50
    }
51
52
    public function registerSubscriber(EventSubscriberInterface $eventSubscribers): self
53
    {
54
        $this->eventDispatcher->addSubscriber($eventSubscribers);
55
56
        return $this;
57
    }
58
}