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

ImageHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 6
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C handleQueue() 6 27 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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