1 | <?php |
||
12 | abstract class AbstractImage implements ImageInterface |
||
13 | { |
||
14 | protected const POSITIONS = [ |
||
15 | 'NORTHWEST' => ['x' => 0, 'y' => 0, 'padX' => 10, 'padY' => 10], |
||
16 | 'NORTH' => ['x' => 1, 'y' => 0, 'padX' => 0, 'padY' => 10], |
||
17 | 'NORTHEAST' => ['x' => 2, 'y' => 0, 'padX' => -10, 'padY' => 10], |
||
18 | 'WEST' => ['x' => 0, 'y' => 1, 'padX' => 10, 'padY' => 0], |
||
19 | 'CENTER' => ['x' => 1, 'y' => 1, 'padX' => 0, 'padY' => 0], |
||
20 | 'EAST' => ['x' => 2, 'y' => 1, 'padX' => -10, 'padY' => 0], |
||
21 | 'SOUTHWEST' => ['x' => 0, 'y' => 2, 'padX' => 10, 'padY' => -10], |
||
22 | 'SOUTH' => ['x' => 1, 'y' => 2, 'padX' => 0, 'padY' => -10], |
||
23 | 'SOUTHEAST' => ['x' => 2, 'y' => 2, 'padX' => -10, 'padY' => -10] |
||
24 | ]; |
||
25 | |||
26 | protected $image; |
||
27 | |||
28 | protected $width; |
||
29 | |||
30 | protected $height; |
||
31 | |||
32 | protected $orientation; |
||
33 | |||
34 | /** |
||
35 | * @param int $value |
||
36 | * @param int $range |
||
37 | * @return bool |
||
38 | */ |
||
39 | protected function compareRangeValue(int $value, int $range): bool |
||
43 | |||
44 | /** |
||
45 | * @param int $width |
||
46 | * @param int $height |
||
47 | * @param Image $background |
||
48 | * @return ImageInterface |
||
49 | */ |
||
50 | protected function setBackground(int $width, int $height, $background): ImageInterface |
||
63 | |||
64 | 13 | protected function setOrientation(): void |
|
68 | |||
69 | public function getOrientation(): string |
||
73 | |||
74 | /** |
||
75 | * @param string $mode |
||
76 | * @param int $param |
||
77 | * @return ImageInterface |
||
78 | * @throws InvalidArgumentException |
||
79 | */ |
||
80 | 2 | public function resizeBy(string $mode, int $param): ImageInterface |
|
93 | |||
94 | /** |
||
95 | * @param int $width |
||
96 | * @return ImageInterface |
||
97 | */ |
||
98 | 1 | public function resizeByWidth(int $width): ImageInterface |
|
102 | |||
103 | /** |
||
104 | * @return int |
||
105 | */ |
||
106 | 14 | public function getHeight(): int |
|
110 | |||
111 | /** |
||
112 | * @param int $height |
||
113 | */ |
||
114 | 13 | protected function setHeight(int $height): void |
|
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | 14 | public function getWidth(): int |
|
126 | |||
127 | /** |
||
128 | * @param int $width |
||
129 | */ |
||
130 | 13 | protected function setWidth(int $width): void |
|
134 | |||
135 | /** |
||
136 | * @param int $height |
||
137 | * @return ImageInterface |
||
138 | */ |
||
139 | 1 | public function resizeByHeight(int $height): ImageInterface |
|
143 | |||
144 | /** |
||
145 | * @param int $percent |
||
146 | * @return ImageInterface |
||
147 | */ |
||
148 | 1 | public function resizeByPercent(int $percent): ImageInterface |
|
154 | |||
155 | abstract protected function newImage(int $width, int $height); |
||
156 | |||
157 | /** |
||
158 | * @param ImageInterface|Image $watermark |
||
159 | * @param string $position |
||
160 | * @return ImageInterface |
||
161 | * @throws InvalidArgumentException |
||
162 | */ |
||
163 | 1 | public function watermark($watermark, string $position): ImageInterface |
|
175 | |||
176 | /** |
||
177 | * @param ImageInterface|Image $watermark |
||
178 | * @param int $x |
||
179 | * @param int $y |
||
180 | * @return ImageInterface |
||
181 | */ |
||
182 | abstract protected function prepareWatermark($watermark, int $x, int $y): ImageInterface; |
||
183 | |||
184 | /** |
||
185 | * @param int $width |
||
186 | * @param int $height |
||
187 | * @return ImageInterface |
||
188 | */ |
||
189 | 2 | public function thumbnail(int $width, int $height): ImageInterface |
|
200 | |||
201 | /** |
||
202 | * @param int $width |
||
203 | * @param int $height |
||
204 | * @return ImageInterface |
||
205 | */ |
||
206 | abstract protected function prepareThumbnail(int $width, int $height): ImageInterface; |
||
207 | |||
208 | /** |
||
209 | * @return string chunked base64 |
||
210 | */ |
||
211 | 1 | public function getBase64(): string |
|
216 | |||
217 | /** |
||
218 | * @param $image |
||
219 | */ |
||
220 | 13 | protected function setImage($image): void |
|
224 | |||
225 | 16 | public function getImage() |
|
229 | |||
230 | /** |
||
231 | * System method |
||
232 | * |
||
233 | * @param void |
||
234 | */ |
||
235 | abstract protected function setSizes(): void; |
||
236 | |||
237 | /** |
||
238 | * @param string $image |
||
239 | * @throws Exception |
||
240 | */ |
||
241 | 14 | protected function init(string $image): void |
|
257 | |||
258 | /** |
||
259 | * @param string $base64 |
||
260 | * @return void |
||
261 | * @throws Exception |
||
262 | */ |
||
263 | 4 | protected function getImageByBase64(string $base64): void |
|
267 | |||
268 | /** |
||
269 | * @param string $source |
||
270 | * @return ImageInterface |
||
271 | */ |
||
272 | abstract protected function tmp(string $source): ImageInterface; |
||
273 | |||
274 | /** |
||
275 | * @param string $url |
||
276 | * @return InvalidArgumentException|null |
||
277 | * @throws Exception |
||
278 | * @throws InvalidArgumentException |
||
279 | * @throws LogicException |
||
280 | * @throws RuntimeException |
||
281 | */ |
||
282 | 3 | protected function getImageByURL(string $url): ?InvalidArgumentException |
|
296 | } |
||
297 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: