Completed
Push — master ( 4fc578...451eab )
by Dmitry
02:14
created

ImageHandler::handleQueue()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 27
Code Lines 18

Duplication

Lines 6
Ratio 22.22 %

Importance

Changes 0
Metric Value
dl 6
loc 27
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 18
nc 12
nop 0
1
<?php
2
3
namespace Dumkaaa\BxOptimize\Handler;
4
5
class ImageHandler extends Handler
6
{
7
    /** {@inheritdoc} */
8
    protected $validExt = [
9
        'png',
10
        'jpeg',
11
        'jpg',
12
    ];
13
    protected $args = [
14
        'png' => ' -o2 ',
15
        'jpg' => '  -progressive -copy none -optimize -outfile %s %s', // dest, src
16
        'jpeg' => '  -progressive -copy none -optimize -outfile %s %s', // dest, src
17
    ];
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function handleQueue()
23
    {
24
        $handlers = [];
25
        foreach ($this->validExt as $ext) {
26
            $handlers[$ext] = HandlerTools::getBinaryHandler($ext);
27
        }
28
29
        foreach ($this->files as $file) {
30
31
            $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
32
33
            if($handlers[$ext]) {
34
                echo get_class()." обрабатывает файл: $file\n";
35
                switch ($ext) {
36 View Code Duplication
                    case 'png':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
                        exec($handlers[$ext] . ' ' . $this->args[$ext]  . ' ' . escapeshellarg($file));
38
                        break;
39
                    case 'jpg':
40 View Code Duplication
                    case 'jpeg':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
                        exec($handlers[$ext]  . ' ' . $this->args[$ext]  . ' ' . escapeshellarg($file) . ' ' . escapeshellarg($file));
42
                        break;
43
                }
44
            } else {
45
                echo "Не найден бинарный обработчик для файла: $file\n";
46
            }
47
        }
48
    }
49
}
50