AbstractSpriteProcessor::setFilepath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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