AbstractSpriteProcessor   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 16
loc 64
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A overwrite() 0 6 1
A setFilepath() 0 6 1
A setImages() 0 6 1
A setSpaces() 0 6 1
B save() 16 16 5

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 CSSPrites\SpriteProcessor;
4
5
use CSSPrites\AbstractConfigurable;
6
use CSSPrites\ImageProcessor\ImageProcessorInterface;
7
8
abstract class AbstractSpriteProcessor extends AbstractConfigurable
9
{
10
    protected $filepath;
11
    protected $overwrite = false;
12
13
    protected $image;
14
    protected $processor;
15
16
    protected $imageProcessor;
17
    protected $images;
18
19
    protected $spaces     = 0;
20
    protected $background = null;
21
22 18
    public function __construct(ImageProcessorInterface $imageProcessor)
23
    {
24 18
        $this->imageProcessor = $imageProcessor;
25 18
    }
26
27 15
    public function overwrite($value)
28
    {
29 15
        $this->overwrite = $value;
30
31 15
        return $this;
32
    }
33
34 15
    public function setFilepath($filepath)
35
    {
36 15
        $this->filepath = $filepath;
37
38 15
        return $this;
39
    }
40
41 18
    public function setImages($images)
42
    {
43 18
        $this->images = $images;
44
45 18
        return $this;
46
    }
47
48 18
    public function setSpaces($spaces)
49
    {
50 18
        $this->spaces = (int) $spaces;
51
52 18
        return $this;
53
    }
54
55 18 View Code Duplication
    public function save()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
56
    {
57 18
        if (empty($this->filepath)) {
58 3
            throw new \Exception('No file path set on the Processor');
59
        }
60
61 15
        if ($this->overwrite === false && file_exists($this->filepath)) {
62 3
            throw new \Exception('File "'.$this->filepath.'" already exists and overwriting is disabled in the Processor');
63
        }
64
65 12
        if (file_exists($this->filepath)) {
66 3
            unlink($this->filepath);
67 3
        }
68
69 12
        return $this->image->save($this->filepath);
70
    }
71
}
72