Optimizer::optimize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Dumkaaa\BxOptimize;
4
5
use Dumkaaa\BxOptimize\Handler\HandlerInterface;
6
7
class Optimizer implements OptimizerInterface
8
{
9
    /** @var Finder\FinderInterface null */
10
    protected $finder = null;
11
12
    /** @var Handler\HandlerInterface */
13
    protected $handlers;
14
15
    /** @var array Массив найденных файлов для обработки */
16
    private $files = [];
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function __construct(Finder\FinderInterface $finder = null, Handler\HandlerProcessor $handler = null)
22
    {
23
        $this->finder = $finder;
24
        $this->handlers = $handler->getHandlers();
0 ignored issues
show
Bug introduced by
It seems like $handler is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function optimize()
31
    {
32
        $this->findFiles();
33
        $this->setQueue();
34
        $this->handleQueue();
35
    }
36
37
    private function setQueue()
38
    {
39
        /** @var HandlerInterface $handler */
40
        foreach ($this->handlers as $handler) {
0 ignored issues
show
Bug introduced by
The expression $this->handlers of type object<Dumkaaa\BxOptimiz...ndler\HandlerInterface> is not traversable.
Loading history...
41
            foreach ($this->files as $file) {
42
                if (!$handler->canHandleFile($file)) {
43
                    continue;
44
                } else {
45
                    $handler->queueFile($file);
46
                }
47
            }
48
        }
49
    }
50
51
    private function handleQueue()
52
    {
53
        /** @var HandlerInterface $handler */
54
        foreach ($this->handlers as $handler) {
0 ignored issues
show
Bug introduced by
The expression $this->handlers of type object<Dumkaaa\BxOptimiz...ndler\HandlerInterface> is not traversable.
Loading history...
55
            $handler->handleQueue();
56
        }
57
    }
58
59
    private function findFiles()
60
    {
61
        $this->files = $this->finder->findFiles();
62
    }
63
}
64