AbstractImageResizer   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 124
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A cropCommand() 0 3 1
A getBinaryPath() 0 3 1
A canHandle() 0 3 1
A setBinaryOptions() 0 5 1
A setValidatorChain() 0 5 1
A __construct() 0 4 1
A getValidatorChain() 0 3 1
A setBinaryPath() 0 5 1
A getBinaryOptions() 0 3 1
A resizeCommand() 0 3 1
1
<?php
2
3
namespace Rvdlee\ZfImageResizer\Adapter;
4
5
use Exception;
6
use Rvdlee\ZfImageResizer\Interfaces\ImageResizerInterface;
7
use Rvdlee\ZfImageResizer\Model\Image;
8
use Zend\Validator\ValidatorChain;
9
10
abstract class AbstractImageResizer implements ImageResizerInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $binaryOptions;
16
17
    /**
18
     * @var string
19
     */
20
    protected $binaryPath;
21
22
    /**
23
     * @var ValidatorChain
24
     */
25
    protected $validatorChain;
26
27
    /**
28
     * AbstractImageResizer constructor.
29
     *
30
     * @param array          $binaryOptions
31
     * @param ValidatorChain $validatorChain
32
     */
33
    public function __construct(array $binaryOptions, ValidatorChain $validatorChain)
34
    {
35
        $this->setBinaryOptions($binaryOptions)
36
            ->setValidatorChain($validatorChain);
37
    }
38
39
    /**
40
     * @param Image $image
41
     * @param bool  $returnBase64
42
     * @return string
43
     * @throws Exception
44
     */
45
    public function resizeCommand(Image $image, bool $returnBase64 = false): string
46
    {
47
        throw new Exception('This method has not been implemented yet.');
48
    }
49
50
    /**
51
     * @param Image  $image
52
     * @param string $mode
53
     * @param int    $x
54
     * @param int    $y
55
     * @return string
56
     * @throws Exception
57
     */
58
    public function cropCommand(Image $image, string $mode = Image::MANUAL_CROP, int $x = 0, int $y = 0): string
59
    {
60
        throw new Exception('This method has not been implemented yet.');
61
    }
62
63
    /**
64
     * In the Abstract class we just run the validator stack
65
     * that has been configured, you can override ofcourse.
66
     *
67
     * @param string $imagePath
68
     *
69
     * @return bool
70
     */
71
    public function canHandle(string $imagePath) : bool
72
    {
73
        return $this->getValidatorChain()->isValid($imagePath);
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function getBinaryOptions() : array
80
    {
81
        return $this->binaryOptions;
82
    }
83
84
    /**
85
     * @param array $binaryOptions
86
     *
87
     * @return AbstractImageResizer
88
     */
89
    public function setBinaryOptions(array $binaryOptions) : AbstractImageResizer
90
    {
91
        $this->binaryOptions = $binaryOptions;
92
93
        return $this;
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getBinaryPath() : string
100
    {
101
        return $this->binaryPath;
102
    }
103
104
    /**
105
     * @param string $binaryPath
106
     *
107
     * @return AbstractImageResizer
108
     */
109
    public function setBinaryPath(string $binaryPath) : AbstractImageResizer
110
    {
111
        $this->binaryPath = $binaryPath;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return ValidatorChain
118
     */
119
    public function getValidatorChain() : ValidatorChain
120
    {
121
        return $this->validatorChain;
122
    }
123
124
    /**
125
     * @param ValidatorChain $validatorChain
126
     *
127
     * @return AbstractImageResizer
128
     */
129
    public function setValidatorChain(ValidatorChain $validatorChain) : AbstractImageResizer
130
    {
131
        $this->validatorChain = $validatorChain;
132
133
        return $this;
134
    }
135
}