@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function setTimeout(int $timeout) : FileDownloader |
43 | 43 | { |
44 | - if($timeout > 0) |
|
44 | + if ($timeout > 0) |
|
45 | 45 | { |
46 | 46 | $this->timeout = $timeout; |
47 | 47 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param bool $enabled |
54 | 54 | * @return FileDownloader |
55 | 55 | */ |
56 | - public function setSSLEnabled(bool $enabled=true) : FileDownloader |
|
56 | + public function setSSLEnabled(bool $enabled = true) : FileDownloader |
|
57 | 57 | { |
58 | 58 | $this->SSLEnabled = $enabled; |
59 | 59 | return $this; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $output = curl_exec($ch); |
76 | 76 | |
77 | - if($output === false) |
|
77 | + if ($output === false) |
|
78 | 78 | { |
79 | 79 | throw new FileHelper_Exception( |
80 | 80 | 'Unable to open URL', |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | curl_close($ch); |
91 | 91 | |
92 | - if(is_string($output)) |
|
92 | + if (is_string($output)) |
|
93 | 93 | { |
94 | 94 | return $output; |
95 | 95 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
118 | 118 | curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); |
119 | 119 | |
120 | - if(!$this->SSLEnabled) |
|
120 | + if (!$this->SSLEnabled) |
|
121 | 121 | { |
122 | 122 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
123 | 123 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
@@ -11,17 +11,17 @@ discard block |
||
11 | 11 | |
12 | 12 | abstract class ColorContainer extends StyleContainer |
13 | 13 | { |
14 | - public function rgbaValues(int $red, int $green, int $blue, float $alpha=0) : StyleBuilder |
|
14 | + public function rgbaValues(int $red, int $green, int $blue, float $alpha = 0) : StyleBuilder |
|
15 | 15 | { |
16 | 16 | return $this->rgba(ColorFactory::createCSS($red, $green, $blue, $alpha)); |
17 | 17 | } |
18 | 18 | |
19 | - public function rgba(RGBAColor $color, bool $important=false) : StyleBuilder |
|
19 | + public function rgba(RGBAColor $color, bool $important = false) : StyleBuilder |
|
20 | 20 | { |
21 | 21 | return $this->setStyle($color->toCSS(), $important); |
22 | 22 | } |
23 | 23 | |
24 | - public function hex(RGBAColor $color, bool $important=false) : StyleBuilder |
|
24 | + public function hex(RGBAColor $color, bool $important = false) : StyleBuilder |
|
25 | 25 | { |
26 | 26 | return $this->setStyle('#'.$color->toHEX(), $important); |
27 | 27 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @return StyleBuilder |
35 | 35 | * @throws ColorException |
36 | 36 | */ |
37 | - public function hexString(string $hex, bool $important=false) : StyleBuilder |
|
37 | + public function hexString(string $hex, bool $important = false) : StyleBuilder |
|
38 | 38 | { |
39 | 39 | return $this->hex(ColorFactory::createFromHEX($hex), $important); |
40 | 40 | } |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | protected array $colors = array(); |
74 | 74 | |
75 | 75 | /** |
76 | - * @var resource|NULL |
|
77 | - */ |
|
76 | + * @var resource|NULL |
|
77 | + */ |
|
78 | 78 | protected $newImage; |
79 | 79 | |
80 | - /** |
|
81 | - * @var resource |
|
82 | - */ |
|
80 | + /** |
|
81 | + * @var resource |
|
82 | + */ |
|
83 | 83 | protected $sourceImage; |
84 | 84 | |
85 | 85 | /** |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - /** |
|
192 | - * Factory method: creates a new helper with a blank image. |
|
193 | - * |
|
194 | - * @param integer $width |
|
195 | - * @param integer $height |
|
196 | - * @param string $type The target file type when saving |
|
197 | - * @return ImageHelper |
|
198 | - * @throws ImageHelper_Exception |
|
199 | - * |
|
200 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
201 | - */ |
|
191 | + /** |
|
192 | + * Factory method: creates a new helper with a blank image. |
|
193 | + * |
|
194 | + * @param integer $width |
|
195 | + * @param integer $height |
|
196 | + * @param string $type The target file type when saving |
|
197 | + * @return ImageHelper |
|
198 | + * @throws ImageHelper_Exception |
|
199 | + * |
|
200 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
201 | + */ |
|
202 | 202 | public static function createNew(int $width, int $height, string $type='png') : self |
203 | 203 | { |
204 | 204 | $img = imagecreatetruecolor($width, $height); |
@@ -249,17 +249,17 @@ discard block |
||
249 | 249 | return new ImageHelper($file, null, self::getFileImageType($file)); |
250 | 250 | } |
251 | 251 | |
252 | - /** |
|
253 | - * Sets a global image helper configuration value. Available |
|
254 | - * configuration settings are: |
|
255 | - * |
|
256 | - * <ul> |
|
257 | - * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether to try and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
258 | - * </ul> |
|
259 | - * |
|
260 | - * @param string $name |
|
261 | - * @param mixed|NULL $value |
|
262 | - */ |
|
252 | + /** |
|
253 | + * Sets a global image helper configuration value. Available |
|
254 | + * configuration settings are: |
|
255 | + * |
|
256 | + * <ul> |
|
257 | + * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether to try and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
258 | + * </ul> |
|
259 | + * |
|
260 | + * @param string $name |
|
261 | + * @param mixed|NULL $value |
|
262 | + */ |
|
263 | 263 | public static function setConfig(string $name, $value) : void |
264 | 264 | { |
265 | 265 | if(isset(self::$config[$name])) { |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | - /** |
|
271 | - * Shorthand for setting the automatic memory adjustment |
|
272 | - * global configuration setting. |
|
273 | - * |
|
274 | - * @param bool $enabled |
|
275 | - * @return void |
|
276 | - */ |
|
270 | + /** |
|
271 | + * Shorthand for setting the automatic memory adjustment |
|
272 | + * global configuration setting. |
|
273 | + * |
|
274 | + * @param bool $enabled |
|
275 | + * @return void |
|
276 | + */ |
|
277 | 277 | public static function setAutoMemoryAdjustment(bool $enabled=true) : void |
278 | 278 | { |
279 | 279 | self::setConfig('auto-memory-adjustment', $enabled); |
@@ -747,12 +747,12 @@ discard block |
||
747 | 747 | return $this; |
748 | 748 | } |
749 | 749 | |
750 | - /** |
|
751 | - * Attempts to adjust the memory to the required size |
|
752 | - * to work with the current image. |
|
753 | - * |
|
754 | - * @return boolean |
|
755 | - */ |
|
750 | + /** |
|
751 | + * Attempts to adjust the memory to the required size |
|
752 | + * to work with the current image. |
|
753 | + * |
|
754 | + * @return boolean |
|
755 | + */ |
|
756 | 756 | protected function adjustMemory() : bool |
757 | 757 | { |
758 | 758 | if(!self::$config['auto-memory-adjustment']) { |
@@ -805,15 +805,15 @@ discard block |
||
805 | 805 | return $this->resampleImage($width, $height); |
806 | 806 | } |
807 | 807 | |
808 | - /** |
|
809 | - * Creates a new image from the current image, |
|
810 | - * resampling it to the new size. |
|
811 | - * |
|
812 | - * @param int $newWidth |
|
813 | - * @param int $newHeight |
|
814 | - * @throws ImageHelper_Exception |
|
815 | - * @return ImageHelper |
|
816 | - */ |
|
808 | + /** |
|
809 | + * Creates a new image from the current image, |
|
810 | + * resampling it to the new size. |
|
811 | + * |
|
812 | + * @param int $newWidth |
|
813 | + * @param int $newHeight |
|
814 | + * @throws ImageHelper_Exception |
|
815 | + * @return ImageHelper |
|
816 | + */ |
|
817 | 817 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
818 | 818 | { |
819 | 819 | if($this->isVector()) { |
@@ -885,17 +885,17 @@ discard block |
||
885 | 885 | return array_unique($types); |
886 | 886 | } |
887 | 887 | |
888 | - /** |
|
889 | - * Displays an existing image resource. |
|
890 | - * |
|
891 | - * @param resource $resource |
|
892 | - * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
893 | - * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG |
|
894 | - * |
|
895 | - * @throws ImageHelper_Exception |
|
896 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
897 | - * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
898 | - */ |
|
888 | + /** |
|
889 | + * Displays an existing image resource. |
|
890 | + * |
|
891 | + * @param resource $resource |
|
892 | + * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
893 | + * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG |
|
894 | + * |
|
895 | + * @throws ImageHelper_Exception |
|
896 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
897 | + * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
898 | + */ |
|
899 | 899 | public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
900 | 900 | { |
901 | 901 | self::requireResource($resource); |
@@ -979,11 +979,11 @@ discard block |
||
979 | 979 | readfile($imageFile); |
980 | 980 | } |
981 | 981 | |
982 | - /** |
|
983 | - * Displays the current image. |
|
984 | - * |
|
985 | - * NOTE: You must call `exit()` manually after this. |
|
986 | - */ |
|
982 | + /** |
|
983 | + * Displays the current image. |
|
984 | + * |
|
985 | + * NOTE: You must call `exit()` manually after this. |
|
986 | + */ |
|
987 | 987 | public function display() : void |
988 | 988 | { |
989 | 989 | self::displayImageStream( |
@@ -1097,14 +1097,14 @@ discard block |
||
1097 | 1097 | return $this; |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - /** |
|
1101 | - * Requires the subject to be a resource. |
|
1102 | - * |
|
1103 | - * @param resource|GdImage|mixed $subject |
|
1104 | - * |
|
1105 | - * @throws ImageHelper_Exception |
|
1106 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1107 | - */ |
|
1100 | + /** |
|
1101 | + * Requires the subject to be a resource. |
|
1102 | + * |
|
1103 | + * @param resource|GdImage|mixed $subject |
|
1104 | + * |
|
1105 | + * @throws ImageHelper_Exception |
|
1106 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1107 | + */ |
|
1108 | 1108 | public static function requireResource($subject) : void |
1109 | 1109 | { |
1110 | 1110 | if(is_resource($subject) && imagesx($subject)) { |
@@ -1125,14 +1125,14 @@ discard block |
||
1125 | 1125 | ); |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - /** |
|
1129 | - * Creates a new image resource, with transparent background. |
|
1130 | - * |
|
1131 | - * @param int $width |
|
1132 | - * @param int $height |
|
1133 | - * @throws ImageHelper_Exception |
|
1134 | - * @return resource |
|
1135 | - */ |
|
1128 | + /** |
|
1129 | + * Creates a new image resource, with transparent background. |
|
1130 | + * |
|
1131 | + * @param int $width |
|
1132 | + * @param int $height |
|
1133 | + * @throws ImageHelper_Exception |
|
1134 | + * @return resource |
|
1135 | + */ |
|
1136 | 1136 | public function createNewImage(int $width, int $height) |
1137 | 1137 | { |
1138 | 1138 | $img = imagecreatetruecolor($width, $height); |
@@ -1156,38 +1156,38 @@ discard block |
||
1156 | 1156 | * @param int $y |
1157 | 1157 | * @return $this |
1158 | 1158 | */ |
1159 | - public function fillWhite(int $x=0, int $y=0) : self |
|
1160 | - { |
|
1161 | - $this->addRGBColor('white', 255, 255, 255); |
|
1159 | + public function fillWhite(int $x=0, int $y=0) : self |
|
1160 | + { |
|
1161 | + $this->addRGBColor('white', 255, 255, 255); |
|
1162 | 1162 | return $this->fill('white', $x, $y); |
1163 | - } |
|
1163 | + } |
|
1164 | 1164 | |
1165 | 1165 | /** |
1166 | 1166 | * @return $this |
1167 | 1167 | * @throws ImageHelper_Exception |
1168 | 1168 | */ |
1169 | - public function fillTransparent() : self |
|
1170 | - { |
|
1169 | + public function fillTransparent() : self |
|
1170 | + { |
|
1171 | 1171 | $this->enableAlpha(); |
1172 | 1172 | |
1173 | - self::fillImageTransparent($this->newImage); |
|
1173 | + self::fillImageTransparent($this->newImage); |
|
1174 | 1174 | |
1175 | - return $this; |
|
1176 | - } |
|
1175 | + return $this; |
|
1176 | + } |
|
1177 | 1177 | |
1178 | 1178 | /** |
1179 | 1179 | * @param resource $resource |
1180 | 1180 | * @return void |
1181 | 1181 | * @throws ImageHelper_Exception |
1182 | 1182 | */ |
1183 | - public static function fillImageTransparent($resource) : void |
|
1184 | - { |
|
1185 | - self::requireResource($resource); |
|
1183 | + public static function fillImageTransparent($resource) : void |
|
1184 | + { |
|
1185 | + self::requireResource($resource); |
|
1186 | 1186 | |
1187 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1188 | - imagecolortransparent ($resource, $transparent); |
|
1189 | - imagefill($resource, 0, 0, $transparent); |
|
1190 | - } |
|
1187 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1188 | + imagecolortransparent ($resource, $transparent); |
|
1189 | + imagefill($resource, 0, 0, $transparent); |
|
1190 | + } |
|
1191 | 1191 | |
1192 | 1192 | /** |
1193 | 1193 | * @param string $colorName |
@@ -1195,11 +1195,11 @@ discard block |
||
1195 | 1195 | * @param int $y |
1196 | 1196 | * @return $this |
1197 | 1197 | */ |
1198 | - public function fill(string $colorName, int $x=0, int $y=0) : self |
|
1199 | - { |
|
1200 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1201 | - return $this; |
|
1202 | - } |
|
1198 | + public function fill(string $colorName, int $x=0, int $y=0) : self |
|
1199 | + { |
|
1200 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1201 | + return $this; |
|
1202 | + } |
|
1203 | 1203 | |
1204 | 1204 | /** |
1205 | 1205 | * @param string $name |
@@ -1243,9 +1243,9 @@ discard block |
||
1243 | 1243 | return $this; |
1244 | 1244 | } |
1245 | 1245 | |
1246 | - /** |
|
1247 | - * @return resource |
|
1248 | - */ |
|
1246 | + /** |
|
1247 | + * @return resource |
|
1248 | + */ |
|
1249 | 1249 | public function getImage() |
1250 | 1250 | { |
1251 | 1251 | return $this->newImage; |
@@ -1293,17 +1293,17 @@ discard block |
||
1293 | 1293 | * |
1294 | 1294 | * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
1295 | 1295 | */ |
1296 | - public function getSize() : ImageHelper_Size |
|
1296 | + public function getSize() : ImageHelper_Size |
|
1297 | 1297 | { |
1298 | - return self::getImageSize($this->newImage); |
|
1298 | + return self::getImageSize($this->newImage); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | - /** |
|
1302 | - * Sets the TTF font file to use for text operations. |
|
1303 | - * |
|
1304 | - * @param string $filePath |
|
1305 | - * @return $this |
|
1306 | - */ |
|
1301 | + /** |
|
1302 | + * Sets the TTF font file to use for text operations. |
|
1303 | + * |
|
1304 | + * @param string $filePath |
|
1305 | + * @return $this |
|
1306 | + */ |
|
1307 | 1307 | public function setFontTTF(string $filePath) : self |
1308 | 1308 | { |
1309 | 1309 | $this->TTFFile = $filePath; |
@@ -1381,7 +1381,7 @@ discard block |
||
1381 | 1381 | return; |
1382 | 1382 | } |
1383 | 1383 | |
1384 | - throw new ImageHelper_Exception( |
|
1384 | + throw new ImageHelper_Exception( |
|
1385 | 1385 | 'No true type font specified', |
1386 | 1386 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
1387 | 1387 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
@@ -1404,37 +1404,37 @@ discard block |
||
1404 | 1404 | * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
1405 | 1405 | * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
1406 | 1406 | */ |
1407 | - public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1408 | - { |
|
1409 | - if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
1410 | - { |
|
1411 | - return new ImageHelper_Size(array( |
|
1412 | - 'width' => imagesx($pathOrResource), |
|
1413 | - 'height' => imagesy($pathOrResource), |
|
1414 | - 'channels' => 1, |
|
1415 | - 'bits' => 8 |
|
1416 | - )); |
|
1417 | - } |
|
1407 | + public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1408 | + { |
|
1409 | + if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
1410 | + { |
|
1411 | + return new ImageHelper_Size(array( |
|
1412 | + 'width' => imagesx($pathOrResource), |
|
1413 | + 'height' => imagesy($pathOrResource), |
|
1414 | + 'channels' => 1, |
|
1415 | + 'bits' => 8 |
|
1416 | + )); |
|
1417 | + } |
|
1418 | 1418 | |
1419 | - $type = self::getFileImageType($pathOrResource); |
|
1419 | + $type = self::getFileImageType($pathOrResource); |
|
1420 | 1420 | |
1421 | 1421 | $sizeMethods = array( |
1422 | 1422 | 'svg' => array(self::class, 'getImageSize_svg') |
1423 | 1423 | ); |
1424 | 1424 | |
1425 | - if(isset($sizeMethods[$type])) |
|
1426 | - { |
|
1427 | - return ClassHelper::requireObjectInstanceOf( |
|
1425 | + if(isset($sizeMethods[$type])) |
|
1426 | + { |
|
1427 | + return ClassHelper::requireObjectInstanceOf( |
|
1428 | 1428 | ImageHelper_Size::class, |
1429 | 1429 | $sizeMethods[$type]($pathOrResource) |
1430 | 1430 | ); |
1431 | - } |
|
1431 | + } |
|
1432 | 1432 | |
1433 | - $info = getimagesize($pathOrResource); |
|
1433 | + $info = getimagesize($pathOrResource); |
|
1434 | 1434 | |
1435 | - if($info !== false) { |
|
1436 | - return new ImageHelper_Size($info); |
|
1437 | - } |
|
1435 | + if($info !== false) { |
|
1436 | + return new ImageHelper_Size($info); |
|
1437 | + } |
|
1438 | 1438 | |
1439 | 1439 | throw new ImageHelper_Exception( |
1440 | 1440 | 'Error opening image file', |
@@ -1444,7 +1444,7 @@ discard block |
||
1444 | 1444 | ), |
1445 | 1445 | self::ERROR_CANNOT_GET_IMAGE_SIZE |
1446 | 1446 | ); |
1447 | - } |
|
1447 | + } |
|
1448 | 1448 | |
1449 | 1449 | /** |
1450 | 1450 | * @param string $imagePath |
@@ -1454,78 +1454,78 @@ discard block |
||
1454 | 1454 | * @throws XMLHelper_Exception |
1455 | 1455 | * @throws JsonException |
1456 | 1456 | */ |
1457 | - protected static function getImageSize_svg(string $imagePath) : ImageHelper_Size |
|
1458 | - { |
|
1459 | - $xml = XMLHelper::createSimplexml(); |
|
1460 | - $xml->loadFile($imagePath); |
|
1457 | + protected static function getImageSize_svg(string $imagePath) : ImageHelper_Size |
|
1458 | + { |
|
1459 | + $xml = XMLHelper::createSimplexml(); |
|
1460 | + $xml->loadFile($imagePath); |
|
1461 | 1461 | |
1462 | - if($xml->hasErrors()) { |
|
1463 | - throw new ImageHelper_Exception( |
|
1464 | - 'Error opening SVG image', |
|
1465 | - sprintf( |
|
1466 | - 'The XML content of the image [%s] could not be parsed.', |
|
1467 | - $imagePath |
|
1462 | + if($xml->hasErrors()) { |
|
1463 | + throw new ImageHelper_Exception( |
|
1464 | + 'Error opening SVG image', |
|
1465 | + sprintf( |
|
1466 | + 'The XML content of the image [%s] could not be parsed.', |
|
1467 | + $imagePath |
|
1468 | 1468 | ), |
1469 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1469 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1470 | 1470 | ); |
1471 | - } |
|
1471 | + } |
|
1472 | 1472 | |
1473 | - $data = $xml->toArray(); |
|
1474 | - $xml->dispose(); |
|
1475 | - unset($xml); |
|
1473 | + $data = $xml->toArray(); |
|
1474 | + $xml->dispose(); |
|
1475 | + unset($xml); |
|
1476 | 1476 | |
1477 | - if(!isset($data['@attributes']['viewBox'])) { |
|
1478 | - throw new ImageHelper_Exception( |
|
1479 | - 'SVG Image is corrupted', |
|
1480 | - sprintf( |
|
1481 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1482 | - $imagePath |
|
1477 | + if(!isset($data['@attributes']['viewBox'])) { |
|
1478 | + throw new ImageHelper_Exception( |
|
1479 | + 'SVG Image is corrupted', |
|
1480 | + sprintf( |
|
1481 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1482 | + $imagePath |
|
1483 | 1483 | ), |
1484 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1484 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1485 | 1485 | ); |
1486 | - } |
|
1486 | + } |
|
1487 | 1487 | |
1488 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1489 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1488 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1489 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1490 | 1490 | |
1491 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1492 | - $size = explode(',', $viewBox); |
|
1491 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1492 | + $size = explode(',', $viewBox); |
|
1493 | 1493 | |
1494 | - if(count($size) !== 4) |
|
1495 | - { |
|
1496 | - throw new ImageHelper_Exception( |
|
1497 | - 'SVG image has an invalid viewBox attribute', |
|
1498 | - sprintf( |
|
1499 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1500 | - $viewBox, |
|
1501 | - $imagePath |
|
1494 | + if(count($size) !== 4) |
|
1495 | + { |
|
1496 | + throw new ImageHelper_Exception( |
|
1497 | + 'SVG image has an invalid viewBox attribute', |
|
1498 | + sprintf( |
|
1499 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1500 | + $viewBox, |
|
1501 | + $imagePath |
|
1502 | 1502 | ), |
1503 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
1503 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
1504 | 1504 | ); |
1505 | - } |
|
1505 | + } |
|
1506 | 1506 | |
1507 | - $boxWidth = (float)$size[2]; |
|
1508 | - $boxHeight = (float)$size[3]; |
|
1507 | + $boxWidth = (float)$size[2]; |
|
1508 | + $boxHeight = (float)$size[3]; |
|
1509 | 1509 | |
1510 | - // calculate the x and y units of the document: |
|
1511 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1512 | - // |
|
1513 | - // The viewbox combined with the width and height of the svg |
|
1514 | - // allow calculating how many pixels are in one unit of the |
|
1515 | - // width and height of the document. |
|
1510 | + // calculate the x and y units of the document: |
|
1511 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1516 | 1512 | // |
1517 | - $xUnits = $svgWidth / $boxWidth; |
|
1518 | - $yUnits = $svgHeight / $boxHeight; |
|
1513 | + // The viewbox combined with the width and height of the svg |
|
1514 | + // allow calculating how many pixels are in one unit of the |
|
1515 | + // width and height of the document. |
|
1516 | + // |
|
1517 | + $xUnits = $svgWidth / $boxWidth; |
|
1518 | + $yUnits = $svgHeight / $boxHeight; |
|
1519 | 1519 | |
1520 | - $pxWidth = $xUnits * $svgWidth; |
|
1521 | - $pxHeight = $yUnits * $svgHeight; |
|
1520 | + $pxWidth = $xUnits * $svgWidth; |
|
1521 | + $pxHeight = $yUnits * $svgHeight; |
|
1522 | 1522 | |
1523 | - return new ImageHelper_Size(array( |
|
1523 | + return new ImageHelper_Size(array( |
|
1524 | 1524 | (int)$pxWidth, |
1525 | 1525 | (int)$pxHeight, |
1526 | - 'bits' => 8 |
|
1527 | - )); |
|
1528 | - } |
|
1526 | + 'bits' => 8 |
|
1527 | + )); |
|
1528 | + } |
|
1529 | 1529 | |
1530 | 1530 | /** |
1531 | 1531 | * Crops the image to the specified width and height, optionally |
@@ -1584,26 +1584,26 @@ discard block |
||
1584 | 1584 | return $image->getColorAt(0, 0); |
1585 | 1585 | } |
1586 | 1586 | |
1587 | - /** |
|
1588 | - * Calculates the image's average color value, and |
|
1589 | - * returns an associative array with red, green, |
|
1590 | - * blue and alpha keys. |
|
1591 | - * |
|
1592 | - * @throws ImageHelper_Exception |
|
1593 | - * @return RGBAColor |
|
1594 | - */ |
|
1587 | + /** |
|
1588 | + * Calculates the image's average color value, and |
|
1589 | + * returns an associative array with red, green, |
|
1590 | + * blue and alpha keys. |
|
1591 | + * |
|
1592 | + * @throws ImageHelper_Exception |
|
1593 | + * @return RGBAColor |
|
1594 | + */ |
|
1595 | 1595 | public function calcAverageColorRGB() : RGBAColor |
1596 | 1596 | { |
1597 | - return $this->calcAverageColor(); |
|
1597 | + return $this->calcAverageColor(); |
|
1598 | 1598 | } |
1599 | 1599 | |
1600 | - /** |
|
1601 | - * Calculates the image's average color value, and |
|
1602 | - * returns a hex color string (without the #). |
|
1603 | - * |
|
1604 | - * @throws ImageHelper_Exception |
|
1605 | - * @return string |
|
1606 | - */ |
|
1600 | + /** |
|
1601 | + * Calculates the image's average color value, and |
|
1602 | + * returns a hex color string (without the #). |
|
1603 | + * |
|
1604 | + * @throws ImageHelper_Exception |
|
1605 | + * @return string |
|
1606 | + */ |
|
1607 | 1607 | public function calcAverageColorHex() : string |
1608 | 1608 | { |
1609 | 1609 | return $this->calcAverageColor()->toHEX(); |
@@ -1653,15 +1653,15 @@ discard block |
||
1653 | 1653 | return $this->calcAverageColorRGB()->getBrightness(); |
1654 | 1654 | } |
1655 | 1655 | |
1656 | - /** |
|
1657 | - * Retrieves a md5 hash of the source image file. |
|
1658 | - * |
|
1659 | - * NOTE: Only works when the helper has been created |
|
1660 | - * from a file. Otherwise, an exception is thrown. |
|
1661 | - * |
|
1662 | - * @return string |
|
1663 | - * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
1664 | - */ |
|
1656 | + /** |
|
1657 | + * Retrieves a md5 hash of the source image file. |
|
1658 | + * |
|
1659 | + * NOTE: Only works when the helper has been created |
|
1660 | + * from a file. Otherwise, an exception is thrown. |
|
1661 | + * |
|
1662 | + * @return string |
|
1663 | + * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
1664 | + */ |
|
1665 | 1665 | public function getHash() : string |
1666 | 1666 | { |
1667 | 1667 | if($this->newImage === null) |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @see ImageHelper::ERROR_GD_LIBRARY_NOT_INSTALLED |
122 | 122 | */ |
123 | - public function __construct(?string $sourceFile=null, $resource=null, ?string $type=null) |
|
123 | + public function __construct(?string $sourceFile = null, $resource = null, ?string $type = null) |
|
124 | 124 | { |
125 | 125 | // ensure that the GD library is installed |
126 | - if(!function_exists('imagecreate')) |
|
126 | + if (!function_exists('imagecreate')) |
|
127 | 127 | { |
128 | 128 | throw new ImageHelper_Exception( |
129 | 129 | 'The PHP GD extension is not installed or not enabled.', |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | ); |
133 | 133 | } |
134 | 134 | |
135 | - if(is_resource($resource) || $resource instanceof GdImage) |
|
135 | + if (is_resource($resource) || $resource instanceof GdImage) |
|
136 | 136 | { |
137 | 137 | $this->sourceImage = $resource; |
138 | 138 | $this->type = $type; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | if ($type === null) { |
157 | 157 | throw new ImageHelper_Exception( |
158 | 158 | 'Error opening image', |
159 | - 'Not a valid supported image type for image ' . $this->file, |
|
159 | + 'Not a valid supported image type for image '.$this->file, |
|
160 | 160 | self::ERROR_UNSUPPORTED_IMAGE_TYPE |
161 | 161 | ); |
162 | 162 | } |
@@ -164,14 +164,14 @@ discard block |
||
164 | 164 | $this->type = $type; |
165 | 165 | $this->info = self::getImageSize($this->file); |
166 | 166 | |
167 | - if(!$this->isVector()) |
|
167 | + if (!$this->isVector()) |
|
168 | 168 | { |
169 | - $method = 'imagecreatefrom' . $this->type; |
|
169 | + $method = 'imagecreatefrom'.$this->type; |
|
170 | 170 | $this->sourceImage = $method($this->file); |
171 | 171 | if (!$this->sourceImage) { |
172 | 172 | throw new ImageHelper_Exception( |
173 | 173 | 'Error creating new image', |
174 | - $method . ' failed', |
|
174 | + $method.' failed', |
|
175 | 175 | self::ERROR_FAILED_TO_CREATE_NEW_IMAGE |
176 | 176 | ); |
177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $this->width = $this->info->getWidth(); |
184 | 184 | $this->height = $this->info->getHeight(); |
185 | 185 | |
186 | - if(!$this->isVector()) { |
|
186 | + if (!$this->isVector()) { |
|
187 | 187 | $this->setNewImage($this->duplicateImage($this->sourceImage)); |
188 | 188 | } |
189 | 189 | } |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
201 | 201 | */ |
202 | - public static function createNew(int $width, int $height, string $type='png') : self |
|
202 | + public static function createNew(int $width, int $height, string $type = 'png') : self |
|
203 | 203 | { |
204 | 204 | $img = imagecreatetruecolor($width, $height); |
205 | - if($img !== false) { |
|
205 | + if ($img !== false) { |
|
206 | 206 | return self::createFromResource($img, $type); |
207 | 207 | } |
208 | 208 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return ImageHelper |
227 | 227 | * @throws ImageHelper_Exception |
228 | 228 | */ |
229 | - public static function createFromResource($resource, ?string $type=null) : ImageHelper |
|
229 | + public static function createFromResource($resource, ?string $type = null) : ImageHelper |
|
230 | 230 | { |
231 | 231 | self::requireResource($resource); |
232 | 232 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public static function setConfig(string $name, $value) : void |
264 | 264 | { |
265 | - if(isset(self::$config[$name])) { |
|
265 | + if (isset(self::$config[$name])) { |
|
266 | 266 | self::$config[$name] = $value; |
267 | 267 | } |
268 | 268 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @param bool $enabled |
275 | 275 | * @return void |
276 | 276 | */ |
277 | - public static function setAutoMemoryAdjustment(bool $enabled=true) : void |
|
277 | + public static function setAutoMemoryAdjustment(bool $enabled = true) : void |
|
278 | 278 | { |
279 | 279 | self::setConfig('auto-memory-adjustment', $enabled); |
280 | 280 | } |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function enableAlpha() : self |
316 | 316 | { |
317 | - if(!$this->alpha) |
|
317 | + if (!$this->alpha) |
|
318 | 318 | { |
319 | 319 | self::addAlphaSupport($this->newImage, false); |
320 | 320 | $this->alpha = true; |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | * @param int|float $percent |
355 | 355 | * @return $this |
356 | 356 | */ |
357 | - public function sharpen($percent=0) : self |
|
357 | + public function sharpen($percent = 0) : self |
|
358 | 358 | { |
359 | - if($percent <= 0) { |
|
359 | + if ($percent <= 0) { |
|
360 | 360 | return $this; |
361 | 361 | } |
362 | 362 | |
@@ -369,9 +369,9 @@ discard block |
||
369 | 369 | * @param int|float $percent |
370 | 370 | * @return $this |
371 | 371 | */ |
372 | - public function blur($percent=0) : self |
|
372 | + public function blur($percent = 0) : self |
|
373 | 373 | { |
374 | - if($percent <= 0) { |
|
374 | + if ($percent <= 0) { |
|
375 | 375 | return $this; |
376 | 376 | } |
377 | 377 | |
@@ -388,12 +388,12 @@ discard block |
||
388 | 388 | { |
389 | 389 | // get a value that's equal to 64 - abs( factor ) |
390 | 390 | // ( using min/max to limit the factor to 0 - 64 to not get out of range values ) |
391 | - $val1Adjustment = 64 - min( 64, max( 0, abs( $factor ) ) ); |
|
391 | + $val1Adjustment = 64 - min(64, max(0, abs($factor))); |
|
392 | 392 | |
393 | 393 | // the base factor for the "current" pixel depends on if we are blurring or sharpening. |
394 | 394 | // If we are blurring use 1, if sharpening use 9. |
395 | 395 | $val1Base = 9; |
396 | - if( abs( $factor ) !== $factor ) { |
|
396 | + if (abs($factor) !== $factor) { |
|
397 | 397 | $val1Base = 1; |
398 | 398 | } |
399 | 399 | |
@@ -406,24 +406,24 @@ discard block |
||
406 | 406 | |
407 | 407 | // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening. |
408 | 408 | $val2 = -1; |
409 | - if( abs( $factor ) !== $factor ) { |
|
409 | + if (abs($factor) !== $factor) { |
|
410 | 410 | $val2 = 1; |
411 | 411 | } |
412 | 412 | |
413 | 413 | // setup matrix .. |
414 | 414 | $matrix = array( |
415 | - array( $val2, $val2, $val2 ), |
|
416 | - array( $val2, $val1, $val2 ), |
|
417 | - array( $val2, $val2, $val2 ) |
|
415 | + array($val2, $val2, $val2), |
|
416 | + array($val2, $val1, $val2), |
|
417 | + array($val2, $val2, $val2) |
|
418 | 418 | ); |
419 | 419 | |
420 | 420 | // calculate the correct divisor |
421 | 421 | // actual divisor is equal to "$divisor = $val1 + $val2 * 8;" |
422 | 422 | // but the following line is more generic |
423 | - $divisor = array_sum( array_map( 'array_sum', $matrix ) ); |
|
423 | + $divisor = array_sum(array_map('array_sum', $matrix)); |
|
424 | 424 | |
425 | 425 | // apply the matrix |
426 | - imageconvolution( $this->newImage, $matrix, $divisor, 0 ); |
|
426 | + imageconvolution($this->newImage, $matrix, $divisor, 0); |
|
427 | 427 | |
428 | 428 | return $this; |
429 | 429 | } |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | */ |
553 | 553 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
554 | 554 | { |
555 | - if($this->isVector()) { |
|
555 | + if ($this->isVector()) { |
|
556 | 556 | return $this; |
557 | 557 | } |
558 | 558 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | |
574 | 574 | public function resampleAndCrop(int $width, int $height) : ImageHelper |
575 | 575 | { |
576 | - if($this->isVector()) { |
|
576 | + if ($this->isVector()) { |
|
577 | 577 | return $this; |
578 | 578 | } |
579 | 579 | |
@@ -619,14 +619,14 @@ discard block |
||
619 | 619 | * @param bool $fill Whether to fill the whole canvas with the transparency |
620 | 620 | * @throws ImageHelper_Exception |
621 | 621 | */ |
622 | - public static function addAlphaSupport($canvas, bool $fill=true) : void |
|
622 | + public static function addAlphaSupport($canvas, bool $fill = true) : void |
|
623 | 623 | { |
624 | 624 | self::requireResource($canvas); |
625 | 625 | |
626 | - imagealphablending($canvas,true); |
|
626 | + imagealphablending($canvas, true); |
|
627 | 627 | imagesavealpha($canvas, true); |
628 | 628 | |
629 | - if($fill) { |
|
629 | + if ($fill) { |
|
630 | 630 | self::fillImageTransparent($canvas); |
631 | 631 | } |
632 | 632 | } |
@@ -642,13 +642,13 @@ discard block |
||
642 | 642 | * @return $this |
643 | 643 | * @throws ImageHelper_Exception |
644 | 644 | */ |
645 | - public function save(string $targetFile, bool $dispose=true) : self |
|
645 | + public function save(string $targetFile, bool $dispose = true) : self |
|
646 | 646 | { |
647 | - if($this->isVector()) { |
|
647 | + if ($this->isVector()) { |
|
648 | 648 | return $this; |
649 | 649 | } |
650 | 650 | |
651 | - if(!is_resource($this->newImage)) { |
|
651 | + if (!is_resource($this->newImage)) { |
|
652 | 652 | throw new ImageHelper_Exception( |
653 | 653 | 'Error creating new image', |
654 | 654 | 'Cannot save an image, no valid image resource was created. You have to call one of the resample methods to create a new image.', |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | unlink($targetFile); |
661 | 661 | } |
662 | 662 | |
663 | - $method = 'image' . $this->type; |
|
663 | + $method = 'image'.$this->type; |
|
664 | 664 | if (!$method($this->newImage, $targetFile, $this->resolveQuality())) { |
665 | 665 | throw new ImageHelper_Exception( |
666 | 666 | 'Error creating new image', |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | ); |
682 | 682 | } |
683 | 683 | |
684 | - if($dispose) { |
|
684 | + if ($dispose) { |
|
685 | 685 | $this->dispose(); |
686 | 686 | } |
687 | 687 | |
@@ -693,11 +693,11 @@ discard block |
||
693 | 693 | */ |
694 | 694 | public function dispose() : self |
695 | 695 | { |
696 | - if(is_resource($this->sourceImage)) { |
|
696 | + if (is_resource($this->sourceImage)) { |
|
697 | 697 | imagedestroy($this->sourceImage); |
698 | 698 | } |
699 | 699 | |
700 | - if(is_resource($this->newImage)) { |
|
700 | + if (is_resource($this->newImage)) { |
|
701 | 701 | imagedestroy($this->newImage); |
702 | 702 | } |
703 | 703 | |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | */ |
756 | 756 | protected function adjustMemory() : bool |
757 | 757 | { |
758 | - if(!self::$config['auto-memory-adjustment']) { |
|
758 | + if (!self::$config['auto-memory-adjustment']) { |
|
759 | 759 | return true; |
760 | 760 | } |
761 | 761 | |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { |
785 | 785 | $newLimit = ($memoryLimit + (memory_get_usage() + $memoryNeeded)) / $MB; |
786 | 786 | $newLimit = ceil($newLimit); |
787 | - ini_set('memory_limit', $newLimit . 'M'); |
|
787 | + ini_set('memory_limit', $newLimit.'M'); |
|
788 | 788 | |
789 | 789 | return true; |
790 | 790 | } |
@@ -816,16 +816,16 @@ discard block |
||
816 | 816 | */ |
817 | 817 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
818 | 818 | { |
819 | - if($this->isVector()) { |
|
819 | + if ($this->isVector()) { |
|
820 | 820 | return $this; |
821 | 821 | } |
822 | 822 | |
823 | - if($this->newWidth===$newWidth && $this->newHeight===$newHeight) { |
|
823 | + if ($this->newWidth === $newWidth && $this->newHeight === $newHeight) { |
|
824 | 824 | return $this; |
825 | 825 | } |
826 | 826 | |
827 | - if($newWidth < 1) { $newWidth = 1; } |
|
828 | - if($newHeight < 1) { $newHeight = 1; } |
|
827 | + if ($newWidth < 1) { $newWidth = 1; } |
|
828 | + if ($newHeight < 1) { $newHeight = 1; } |
|
829 | 829 | |
830 | 830 | $this->adjustMemory(); |
831 | 831 | |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | */ |
857 | 857 | public static function getFileImageType($pathOrResource) : ?string |
858 | 858 | { |
859 | - if(!is_string($pathOrResource)) { |
|
859 | + if (!is_string($pathOrResource)) { |
|
860 | 860 | return 'png'; |
861 | 861 | } |
862 | 862 | |
@@ -896,15 +896,15 @@ discard block |
||
896 | 896 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
897 | 897 | * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
898 | 898 | */ |
899 | - public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
|
899 | + public static function displayImageStream($resource, string $imageType, int $quality = -1) : void |
|
900 | 900 | { |
901 | 901 | self::requireResource($resource); |
902 | 902 | |
903 | 903 | $imageType = self::requireValidStreamType($imageType); |
904 | 904 | |
905 | - header('Content-type:image/' . $imageType); |
|
905 | + header('Content-type:image/'.$imageType); |
|
906 | 906 | |
907 | - $function = 'image' . $imageType; |
|
907 | + $function = 'image'.$imageType; |
|
908 | 908 | |
909 | 909 | $function($resource, null, $quality); |
910 | 910 | } |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | { |
922 | 922 | $imageType = strtolower($imageType); |
923 | 923 | |
924 | - if(in_array($imageType, self::$streamTypes)) |
|
924 | + if (in_array($imageType, self::$streamTypes)) |
|
925 | 925 | { |
926 | 926 | return $imageType; |
927 | 927 | } |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | if (headers_sent($file, $line)) { |
949 | 949 | throw new ImageHelper_Exception( |
950 | 950 | 'Error displaying image', |
951 | - 'Headers have already been sent: in file ' . $file . ':' . $line, |
|
951 | + 'Headers have already been sent: in file '.$file.':'.$line, |
|
952 | 952 | self::ERROR_HEADERS_ALREADY_SENT |
953 | 953 | ); |
954 | 954 | } |
@@ -965,16 +965,16 @@ discard block |
||
965 | 965 | } |
966 | 966 | |
967 | 967 | $format = self::getFileImageType($imageFile); |
968 | - if($format === 'svg') { |
|
968 | + if ($format === 'svg') { |
|
969 | 969 | $format = 'svg+xml'; |
970 | 970 | } |
971 | 971 | |
972 | - $contentType = 'image/' . $format; |
|
972 | + $contentType = 'image/'.$format; |
|
973 | 973 | |
974 | 974 | header('Content-Type: '.$contentType); |
975 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($imageFile)) . " GMT"); |
|
975 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($imageFile))." GMT"); |
|
976 | 976 | header('Cache-Control: public'); |
977 | - header('Content-Length: ' . filesize($imageFile)); |
|
977 | + header('Content-Length: '.filesize($imageFile)); |
|
978 | 978 | |
979 | 979 | readfile($imageFile); |
980 | 980 | } |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
1006 | 1006 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
1007 | 1007 | */ |
1008 | - public function trim(?RGBAColor $color=null) : ImageHelper |
|
1008 | + public function trim(?RGBAColor $color = null) : ImageHelper |
|
1009 | 1009 | { |
1010 | 1010 | return $this->trimImage($this->newImage, $color); |
1011 | 1011 | } |
@@ -1054,9 +1054,9 @@ discard block |
||
1054 | 1054 | * |
1055 | 1055 | * @throws ImageHelper_Exception |
1056 | 1056 | */ |
1057 | - protected function trimImage($img, ?RGBAColor $trimColor=null) : ImageHelper |
|
1057 | + protected function trimImage($img, ?RGBAColor $trimColor = null) : ImageHelper |
|
1058 | 1058 | { |
1059 | - if($this->isVector()) { |
|
1059 | + if ($this->isVector()) { |
|
1060 | 1060 | return $this; |
1061 | 1061 | } |
1062 | 1062 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | $trimmer = new ImageTrimmer($this, $img, $trimColor); |
1066 | 1066 | $new = $trimmer->trim(); |
1067 | 1067 | |
1068 | - if($new === null) { |
|
1068 | + if ($new === null) { |
|
1069 | 1069 | return $this; |
1070 | 1070 | } |
1071 | 1071 | |
@@ -1092,7 +1092,7 @@ discard block |
||
1092 | 1092 | |
1093 | 1093 | $this->newImage = $image; |
1094 | 1094 | $this->newWidth = imagesx($image); |
1095 | - $this->newHeight= imagesy($image); |
|
1095 | + $this->newHeight = imagesy($image); |
|
1096 | 1096 | |
1097 | 1097 | return $this; |
1098 | 1098 | } |
@@ -1107,11 +1107,11 @@ discard block |
||
1107 | 1107 | */ |
1108 | 1108 | public static function requireResource($subject) : void |
1109 | 1109 | { |
1110 | - if(is_resource($subject) && imagesx($subject)) { |
|
1110 | + if (is_resource($subject) && imagesx($subject)) { |
|
1111 | 1111 | return; |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - if($subject instanceof GdImage) { |
|
1114 | + if ($subject instanceof GdImage) { |
|
1115 | 1115 | return; |
1116 | 1116 | } |
1117 | 1117 | |
@@ -1137,7 +1137,7 @@ discard block |
||
1137 | 1137 | { |
1138 | 1138 | $img = imagecreatetruecolor($width, $height); |
1139 | 1139 | |
1140 | - if($img === false) |
|
1140 | + if ($img === false) |
|
1141 | 1141 | { |
1142 | 1142 | throw new ImageHelper_Exception( |
1143 | 1143 | 'Error creating new image', |
@@ -1156,7 +1156,7 @@ discard block |
||
1156 | 1156 | * @param int $y |
1157 | 1157 | * @return $this |
1158 | 1158 | */ |
1159 | - public function fillWhite(int $x=0, int $y=0) : self |
|
1159 | + public function fillWhite(int $x = 0, int $y = 0) : self |
|
1160 | 1160 | { |
1161 | 1161 | $this->addRGBColor('white', 255, 255, 255); |
1162 | 1162 | return $this->fill('white', $x, $y); |
@@ -1185,7 +1185,7 @@ discard block |
||
1185 | 1185 | self::requireResource($resource); |
1186 | 1186 | |
1187 | 1187 | $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
1188 | - imagecolortransparent ($resource, $transparent); |
|
1188 | + imagecolortransparent($resource, $transparent); |
|
1189 | 1189 | imagefill($resource, 0, 0, $transparent); |
1190 | 1190 | } |
1191 | 1191 | |
@@ -1195,7 +1195,7 @@ discard block |
||
1195 | 1195 | * @param int $y |
1196 | 1196 | * @return $this |
1197 | 1197 | */ |
1198 | - public function fill(string $colorName, int $x=0, int $y=0) : self |
|
1198 | + public function fill(string $colorName, int $x = 0, int $y = 0) : self |
|
1199 | 1199 | { |
1200 | 1200 | imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
1201 | 1201 | return $this; |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | * @param int|float $angle |
1224 | 1224 | * @return $this |
1225 | 1225 | */ |
1226 | - public function textTTF(string $text, $size, string $colorName, int $x=0, int $y=0, $angle=0) : self |
|
1226 | + public function textTTF(string $text, $size, string $colorName, int $x = 0, int $y = 0, $angle = 0) : self |
|
1227 | 1227 | { |
1228 | 1228 | imagealphablending($this->newImage, true); |
1229 | 1229 | |
@@ -1260,11 +1260,11 @@ discard block |
||
1260 | 1260 | * @return $this |
1261 | 1261 | * @throws ImageHelper_Exception |
1262 | 1262 | */ |
1263 | - public function paste(ImageHelper $target, int $xpos=0, int $ypos=0, int $sourceX=0, int $sourceY=0) : self |
|
1263 | + public function paste(ImageHelper $target, int $xpos = 0, int $ypos = 0, int $sourceX = 0, int $sourceY = 0) : self |
|
1264 | 1264 | { |
1265 | 1265 | $img = $target->getImage(); |
1266 | 1266 | |
1267 | - if($target->isAlpha()) { |
|
1267 | + if ($target->isAlpha()) { |
|
1268 | 1268 | $this->enableAlpha(); |
1269 | 1269 | } |
1270 | 1270 | |
@@ -1326,10 +1326,10 @@ discard block |
||
1326 | 1326 | */ |
1327 | 1327 | $sizes = array(); |
1328 | 1328 | |
1329 | - for($i=1; $i<=1000; $i += 0.1) { |
|
1329 | + for ($i = 1; $i <= 1000; $i += 0.1) { |
|
1330 | 1330 | $size = $this->calcTextSize($text, $i); |
1331 | 1331 | $sizes[] = $size; |
1332 | - if($size->getWidth() >= $matchWidth) { |
|
1332 | + if ($size->getWidth() >= $matchWidth) { |
|
1333 | 1333 | break; |
1334 | 1334 | } |
1335 | 1335 | } |
@@ -1341,7 +1341,7 @@ discard block |
||
1341 | 1341 | $diffLast = $last->getWidth() - $matchWidth; |
1342 | 1342 | $diffPrev = $matchWidth - $prev->getWidth(); |
1343 | 1343 | |
1344 | - if($diffLast <= $diffPrev) { |
|
1344 | + if ($diffLast <= $diffPrev) { |
|
1345 | 1345 | return $last; |
1346 | 1346 | } |
1347 | 1347 | |
@@ -1370,14 +1370,14 @@ discard block |
||
1370 | 1370 | 'bottom_left_y' => $box[1], |
1371 | 1371 | 'bottom_right_x' => $box[2], |
1372 | 1372 | 'bottom_right_y' => $box[3], |
1373 | - 'width' => $box[4]-$box[0], |
|
1374 | - 'height' => $box[1]-$box[7] |
|
1373 | + 'width' => $box[4] - $box[0], |
|
1374 | + 'height' => $box[1] - $box[7] |
|
1375 | 1375 | )); |
1376 | 1376 | } |
1377 | 1377 | |
1378 | 1378 | protected function requireTTFFont() : void |
1379 | 1379 | { |
1380 | - if(!empty($this->TTFFile)) { |
|
1380 | + if (!empty($this->TTFFile)) { |
|
1381 | 1381 | return; |
1382 | 1382 | } |
1383 | 1383 | |
@@ -1406,7 +1406,7 @@ discard block |
||
1406 | 1406 | */ |
1407 | 1407 | public static function getImageSize($pathOrResource) : ImageHelper_Size |
1408 | 1408 | { |
1409 | - if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
1409 | + if (is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
1410 | 1410 | { |
1411 | 1411 | return new ImageHelper_Size(array( |
1412 | 1412 | 'width' => imagesx($pathOrResource), |
@@ -1422,7 +1422,7 @@ discard block |
||
1422 | 1422 | 'svg' => array(self::class, 'getImageSize_svg') |
1423 | 1423 | ); |
1424 | 1424 | |
1425 | - if(isset($sizeMethods[$type])) |
|
1425 | + if (isset($sizeMethods[$type])) |
|
1426 | 1426 | { |
1427 | 1427 | return ClassHelper::requireObjectInstanceOf( |
1428 | 1428 | ImageHelper_Size::class, |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | |
1433 | 1433 | $info = getimagesize($pathOrResource); |
1434 | 1434 | |
1435 | - if($info !== false) { |
|
1435 | + if ($info !== false) { |
|
1436 | 1436 | return new ImageHelper_Size($info); |
1437 | 1437 | } |
1438 | 1438 | |
@@ -1459,7 +1459,7 @@ discard block |
||
1459 | 1459 | $xml = XMLHelper::createSimplexml(); |
1460 | 1460 | $xml->loadFile($imagePath); |
1461 | 1461 | |
1462 | - if($xml->hasErrors()) { |
|
1462 | + if ($xml->hasErrors()) { |
|
1463 | 1463 | throw new ImageHelper_Exception( |
1464 | 1464 | 'Error opening SVG image', |
1465 | 1465 | sprintf( |
@@ -1474,7 +1474,7 @@ discard block |
||
1474 | 1474 | $xml->dispose(); |
1475 | 1475 | unset($xml); |
1476 | 1476 | |
1477 | - if(!isset($data['@attributes']['viewBox'])) { |
|
1477 | + if (!isset($data['@attributes']['viewBox'])) { |
|
1478 | 1478 | throw new ImageHelper_Exception( |
1479 | 1479 | 'SVG Image is corrupted', |
1480 | 1480 | sprintf( |
@@ -1491,7 +1491,7 @@ discard block |
||
1491 | 1491 | $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
1492 | 1492 | $size = explode(',', $viewBox); |
1493 | 1493 | |
1494 | - if(count($size) !== 4) |
|
1494 | + if (count($size) !== 4) |
|
1495 | 1495 | { |
1496 | 1496 | throw new ImageHelper_Exception( |
1497 | 1497 | 'SVG image has an invalid viewBox attribute', |
@@ -1538,7 +1538,7 @@ discard block |
||
1538 | 1538 | * @return $this |
1539 | 1539 | * @throws ImageHelper_Exception |
1540 | 1540 | */ |
1541 | - public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
|
1541 | + public function crop(int $width, int $height, int $x = 0, int $y = 0) : ImageHelper |
|
1542 | 1542 | { |
1543 | 1543 | $new = $this->createNewImage($width, $height); |
1544 | 1544 | |
@@ -1622,7 +1622,7 @@ discard block |
||
1622 | 1622 | */ |
1623 | 1623 | public function getColorAt(int $x, int $y) : RGBAColor |
1624 | 1624 | { |
1625 | - if($x > $this->getWidth() || $y > $this->getHeight()) |
|
1625 | + if ($x > $this->getWidth() || $y > $this->getHeight()) |
|
1626 | 1626 | { |
1627 | 1627 | throw new ImageHelper_Exception( |
1628 | 1628 | 'Position out of bounds', |
@@ -1664,7 +1664,7 @@ discard block |
||
1664 | 1664 | */ |
1665 | 1665 | public function getHash() : string |
1666 | 1666 | { |
1667 | - if($this->newImage === null) |
|
1667 | + if ($this->newImage === null) |
|
1668 | 1668 | { |
1669 | 1669 | throw new ImageHelper_Exception( |
1670 | 1670 | 'No image loaded to create a hash for.', |
@@ -137,8 +137,7 @@ discard block |
||
137 | 137 | $this->sourceImage = $resource; |
138 | 138 | $this->type = $type; |
139 | 139 | $this->info = self::getImageSize($resource); |
140 | - } |
|
141 | - else |
|
140 | + } else |
|
142 | 141 | { |
143 | 142 | $this->file = $sourceFile; |
144 | 143 | if (!file_exists($this->file)) { |
@@ -580,8 +579,7 @@ discard block |
||
580 | 579 | if ($this->width <= $this->height) |
581 | 580 | { |
582 | 581 | $this->resampleByWidth($width); |
583 | - } |
|
584 | - else |
|
582 | + } else |
|
585 | 583 | { |
586 | 584 | $this->resampleByHeight($height); |
587 | 585 | } |
@@ -30,27 +30,27 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function __construct(array $size) |
32 | 32 | { |
33 | - if(!isset($size['width'])) { |
|
33 | + if (!isset($size['width'])) { |
|
34 | 34 | $size['width'] = $size[0]; |
35 | 35 | } |
36 | 36 | |
37 | - if(!isset($size['height'])) { |
|
37 | + if (!isset($size['height'])) { |
|
38 | 38 | $size['height'] = $size[1]; |
39 | 39 | } |
40 | 40 | |
41 | - if(!isset($size[0])) { |
|
41 | + if (!isset($size[0])) { |
|
42 | 42 | $size[0] = $size['width']; |
43 | 43 | } |
44 | 44 | |
45 | - if(!isset($size[1])) { |
|
45 | + if (!isset($size[1])) { |
|
46 | 46 | $size[1] = $size['height']; |
47 | 47 | } |
48 | 48 | |
49 | - if(!isset($size['channels'])) { |
|
49 | + if (!isset($size['channels'])) { |
|
50 | 50 | $size['channels'] = 1; |
51 | 51 | } |
52 | 52 | |
53 | - if(!isset($size['bits'])) { |
|
53 | + if (!isset($size['bits'])) { |
|
54 | 54 | $size['bits'] = -1; |
55 | 55 | } |
56 | 56 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public static function create($arrayOrInstance) : ImageHelper_Size |
65 | 65 | { |
66 | - if($arrayOrInstance instanceof self) { |
|
66 | + if ($arrayOrInstance instanceof self) { |
|
67 | 67 | return new self($arrayOrInstance->toArray()); |
68 | 68 | } |
69 | 69 |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $path = realpath($this->path); |
109 | 109 | |
110 | - if($path !== false) |
|
110 | + if ($path !== false) |
|
111 | 111 | { |
112 | 112 | return FileHelper::normalizePath($path); |
113 | 113 | } |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | * @return $this |
127 | 127 | * @throws FileHelper_Exception |
128 | 128 | */ |
129 | - private function requireTrue(bool $condition, string $conditionLabel, ?int $errorCode=null) : self |
|
129 | + private function requireTrue(bool $condition, string $conditionLabel, ?int $errorCode = null) : self |
|
130 | 130 | { |
131 | - if($condition === true) |
|
131 | + if ($condition === true) |
|
132 | 132 | { |
133 | 133 | return $this; |
134 | 134 | } |
135 | 135 | |
136 | - if($errorCode === null) |
|
136 | + if ($errorCode === null) |
|
137 | 137 | { |
138 | 138 | $errorCode = FileHelper::ERROR_FILE_DOES_NOT_EXIST; |
139 | 139 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return $this |
151 | 151 | * @throws FileHelper_Exception |
152 | 152 | */ |
153 | - public function requireExists(?int $errorCode=null) : self |
|
153 | + public function requireExists(?int $errorCode = null) : self |
|
154 | 154 | { |
155 | 155 | return $this->requireTrue( |
156 | 156 | !empty($this->path) && realpath($this->path) !== false, |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @return $this |
165 | 165 | * @throws FileHelper_Exception |
166 | 166 | */ |
167 | - public function requireReadable(?int $errorCode=null) : self |
|
167 | + public function requireReadable(?int $errorCode = null) : self |
|
168 | 168 | { |
169 | 169 | $this->requireExists($errorCode); |
170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @return $this |
181 | 181 | * @throws FileHelper_Exception |
182 | 182 | */ |
183 | - public function requireWritable(?int $errorCode=null) : self |
|
183 | + public function requireWritable(?int $errorCode = null) : self |
|
184 | 184 | { |
185 | 185 | return $this->requireTrue( |
186 | 186 | $this->isWritable(), |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function requireIsFile() : FileInfo |
199 | 199 | { |
200 | - if($this instanceof FileInfo) |
|
200 | + if ($this instanceof FileInfo) |
|
201 | 201 | { |
202 | 202 | return $this; |
203 | 203 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function requireIsFolder() : FolderInfo |
222 | 222 | { |
223 | - if($this instanceof FolderInfo) |
|
223 | + if ($this instanceof FolderInfo) |
|
224 | 224 | { |
225 | 225 | return $this; |
226 | 226 | } |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public static function type2string($path) : string |
243 | 243 | { |
244 | - if($path instanceof PathInfoInterface) |
|
244 | + if ($path instanceof PathInfoInterface) |
|
245 | 245 | { |
246 | 246 | return $path->getPath(); |
247 | 247 | } |
248 | 248 | |
249 | - if($path instanceof SplFileInfo) |
|
249 | + if ($path instanceof SplFileInfo) |
|
250 | 250 | { |
251 | 251 | return $path->getPathname(); |
252 | 252 | } |
@@ -268,24 +268,24 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public static function resolveType($path) : PathInfoInterface |
270 | 270 | { |
271 | - if($path instanceof PathInfoInterface) |
|
271 | + if ($path instanceof PathInfoInterface) |
|
272 | 272 | { |
273 | 273 | return $path; |
274 | 274 | } |
275 | 275 | |
276 | 276 | $path = self::type2string($path); |
277 | 277 | |
278 | - if(FolderInfo::is_dir($path)) |
|
278 | + if (FolderInfo::is_dir($path)) |
|
279 | 279 | { |
280 | 280 | return FolderInfo::factory($path); |
281 | 281 | } |
282 | 282 | |
283 | - if(FileInfo::is_file($path)) |
|
283 | + if (FileInfo::is_file($path)) |
|
284 | 284 | { |
285 | 285 | return FileInfo::factory($path); |
286 | 286 | } |
287 | 287 | |
288 | - if(!empty($path) && $path !== '.' && $path !== '..') |
|
288 | + if (!empty($path) && $path !== '.' && $path !== '..') |
|
289 | 289 | { |
290 | 290 | return new IndeterminatePath($path); |
291 | 291 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | public function getModifiedDate() : ?DateTime |
341 | 341 | { |
342 | 342 | $time = filemtime($this->getPath()); |
343 | - if($time === false) { |
|
343 | + if ($time === false) { |
|
344 | 344 | return null; |
345 | 345 | } |
346 | 346 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | { |
42 | 42 | // Doing this manually, as FileHelper::saveFile() |
43 | 43 | // checks if the target is a file, which will fail. |
44 | - if(file_put_contents($this->getPath(), '') === false) { |
|
44 | + if (file_put_contents($this->getPath(), '') === false) { |
|
45 | 45 | throw new FileHelper_Exception( |
46 | 46 | 'Cannot create file', |
47 | 47 | '', |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | // Doing this manually, as FileHelper::createFolder() |
60 | 60 | // checks if the target is a folder, which will fail. |
61 | - if(!mkdir($path, 0777, true) && !is_dir($path)) |
|
61 | + if (!mkdir($path, 0777, true) && !is_dir($path)) |
|
62 | 62 | { |
63 | 63 | throw new FileHelper_Exception( |
64 | 64 | 'Cannot create folder', |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | |
73 | 73 | public function convertTo(string $type) : PathInfoInterface |
74 | 74 | { |
75 | - if($type === self::CONVERT_TYPE_FILE) { |
|
75 | + if ($type === self::CONVERT_TYPE_FILE) { |
|
76 | 76 | return $this->convertToFile(); |
77 | 77 | } |
78 | 78 | |
79 | - if($type === self::CONVERT_TYPE_FOLDER) { |
|
79 | + if ($type === self::CONVERT_TYPE_FOLDER) { |
|
80 | 80 | return $this->convertToFolder(); |
81 | 81 | } |
82 | 82 |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function checkSyntax() |
58 | 58 | { |
59 | - if(!FileHelper::canMakePHPCalls()) |
|
59 | + if (!FileHelper::canMakePHPCalls()) |
|
60 | 60 | { |
61 | 61 | return true; |
62 | 62 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | // when the validation is successful, the first entry |
69 | 69 | // in the array contains the success message. When it |
70 | 70 | // is invalid, the first entry is always empty. |
71 | - if(!empty($output[0])) { |
|
71 | + if (!empty($output[0])) { |
|
72 | 72 | return true; |
73 | 73 | } |
74 | 74 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $pathString = AbstractPathInfo::type2string($path); |
32 | 32 | |
33 | - if(empty($path)) { |
|
33 | + if (empty($path)) { |
|
34 | 34 | throw new FileHelper_Exception( |
35 | 35 | 'Invalid', |
36 | 36 | '', |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | ); |
39 | 39 | } |
40 | 40 | |
41 | - if($path instanceof FileInfo || FileInfo::is_file($pathString)) |
|
41 | + if ($path instanceof FileInfo || FileInfo::is_file($pathString)) |
|
42 | 42 | { |
43 | 43 | throw new FileHelper_Exception( |
44 | 44 | 'Cannot use a file', |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | - if(!isset(self::$infoCache[$pathString])) |
|
53 | + if (!isset(self::$infoCache[$pathString])) |
|
54 | 54 | { |
55 | 55 | self::$infoCache[$pathString] = new FolderInfo($pathString); |
56 | 56 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $path = trim($path); |
88 | 88 | $test = trim($path, '/\\'); |
89 | 89 | |
90 | - if($path === '' || $test === '.' || $test === '..') |
|
90 | + if ($path === '' || $test === '.' || $test === '..') |
|
91 | 91 | { |
92 | 92 | return false; |
93 | 93 | } |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function delete() : FolderInfo |
107 | 107 | { |
108 | - if(!$this->exists()) |
|
108 | + if (!$this->exists()) |
|
109 | 109 | { |
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - if(rmdir($this->path)) |
|
113 | + if (rmdir($this->path)) |
|
114 | 114 | { |
115 | 115 | return $this; |
116 | 116 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function create() : FolderInfo |
138 | 138 | { |
139 | - if(is_dir($this->path) || mkdir($this->path, 0777, true) || is_dir($this->path)) |
|
139 | + if (is_dir($this->path) || mkdir($this->path, 0777, true) || is_dir($this->path)) |
|
140 | 140 | { |
141 | 141 | return $this; |
142 | 142 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | return FileHelper::createFolder($this->getPath().'/'.$name); |
187 | 187 | } |
188 | 188 | |
189 | - public function saveFile(string $fileName, string $content='') : FileInfo |
|
189 | + public function saveFile(string $fileName, string $content = '') : FileInfo |
|
190 | 190 | { |
191 | 191 | return FileHelper::saveFile($this.'/'.$fileName, $content); |
192 | 192 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return JSONFile |
199 | 199 | * @throws FileHelper_Exception |
200 | 200 | */ |
201 | - public function saveJSONFile(array $data, string $fileName, bool $pretty=false) : JSONFile |
|
201 | + public function saveJSONFile(array $data, string $fileName, bool $pretty = false) : JSONFile |
|
202 | 202 | { |
203 | 203 | return FileHelper::saveAsJSON($data, $this.'/'.$fileName, $pretty); |
204 | 204 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @param array<string,mixed> $data |
44 | 44 | */ |
45 | - public function __construct(array $data=array()) |
|
45 | + public function __construct(array $data = array()) |
|
46 | 46 | { |
47 | 47 | $this->data = $data; |
48 | 48 | } |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * @param ArrayDataCollection|array<string,mixed>|NULL $data |
52 | 52 | * @return ArrayDataCollection |
53 | 53 | */ |
54 | - public static function create($data=array()) : ArrayDataCollection |
|
54 | + public static function create($data = array()) : ArrayDataCollection |
|
55 | 55 | { |
56 | - if($data instanceof self) { |
|
56 | + if ($data instanceof self) { |
|
57 | 57 | return $data; |
58 | 58 | } |
59 | 59 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function setKeys(array $data) : self |
76 | 76 | { |
77 | - foreach($data as $key => $value) |
|
77 | + foreach ($data as $key => $value) |
|
78 | 78 | { |
79 | 79 | $this->setKey($key, $value); |
80 | 80 | } |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | { |
143 | 143 | $value = $this->getKey($name); |
144 | 144 | |
145 | - if(is_string($value)) { |
|
145 | + if (is_string($value)) { |
|
146 | 146 | return $value; |
147 | 147 | } |
148 | 148 | |
149 | - if(is_numeric($value)) { |
|
149 | + if (is_numeric($value)) { |
|
150 | 150 | return (string)$value; |
151 | 151 | } |
152 | 152 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | { |
166 | 166 | $value = $this->getKey($name); |
167 | 167 | |
168 | - if(is_numeric($value)) { |
|
168 | + if (is_numeric($value)) { |
|
169 | 169 | return (int)$value; |
170 | 170 | } |
171 | 171 | |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | $value = $this->getKey($name); |
188 | 188 | |
189 | 189 | // Does not need to be decoded after all |
190 | - if(is_array($value)) { |
|
190 | + if (is_array($value)) { |
|
191 | 191 | return $value; |
192 | 192 | } |
193 | 193 | |
194 | - if(empty($value) || !is_string($value)) { |
|
194 | + if (empty($value) || !is_string($value)) { |
|
195 | 195 | return array(); |
196 | 196 | } |
197 | 197 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $value = $this->getKey($name); |
204 | 204 | |
205 | - if(is_array($value)) { |
|
205 | + if (is_array($value)) { |
|
206 | 206 | return $value; |
207 | 207 | } |
208 | 208 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | { |
214 | 214 | $value = $this->getKey($name); |
215 | 215 | |
216 | - if(is_string($value)) { |
|
216 | + if (is_string($value)) { |
|
217 | 217 | $value = strtolower($value); |
218 | 218 | } |
219 | 219 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | { |
232 | 232 | $value = $this->getKey($name); |
233 | 233 | |
234 | - if(is_numeric($value)) { |
|
234 | + if (is_numeric($value)) { |
|
235 | 235 | return (float)$value; |
236 | 236 | } |
237 | 237 | |
@@ -288,11 +288,11 @@ discard block |
||
288 | 288 | { |
289 | 289 | $value = $this->getString($name); |
290 | 290 | |
291 | - if(empty($value)) { |
|
291 | + if (empty($value)) { |
|
292 | 292 | return null; |
293 | 293 | } |
294 | 294 | |
295 | - if(is_numeric($value)) { |
|
295 | + if (is_numeric($value)) { |
|
296 | 296 | $date = new DateTime(); |
297 | 297 | $date->setTimestamp((int)$value); |
298 | 298 | return $date; |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | { |
375 | 375 | $date = $this->getDateTime($name); |
376 | 376 | |
377 | - if($date !== null) |
|
377 | + if ($date !== null) |
|
378 | 378 | { |
379 | 379 | return $date->getTimestamp(); |
380 | 380 | } |
@@ -301,8 +301,7 @@ discard block |
||
301 | 301 | try |
302 | 302 | { |
303 | 303 | return new DateTime($value); |
304 | - } |
|
305 | - catch (Exception $e) |
|
304 | + } catch (Exception $e) |
|
306 | 305 | { |
307 | 306 | return null; |
308 | 307 | } |
@@ -320,8 +319,7 @@ discard block |
||
320 | 319 | try |
321 | 320 | { |
322 | 321 | return Microtime::createFromString($this->getString($name)); |
323 | - } |
|
324 | - catch (Exception $e) |
|
322 | + } catch (Exception $e) |
|
325 | 323 | { |
326 | 324 | return null; |
327 | 325 | } |