Optimizer   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 57
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A optimize() 0 6 1
A setQueue() 0 13 4
A handleQueue() 0 7 2
A findFiles() 0 4 1
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