@@ -151,8 +151,7 @@ discard block |
||
151 | 151 | $this->sourceImage = $resource; |
152 | 152 | $this->type = $type; |
153 | 153 | $this->info = self::getImageSize($resource); |
154 | - } |
|
155 | - else |
|
154 | + } else |
|
156 | 155 | { |
157 | 156 | $this->file = $sourceFile; |
158 | 157 | if (!file_exists($this->file)) { |
@@ -561,8 +560,7 @@ discard block |
||
561 | 560 | if ($this->width <= $this->height) |
562 | 561 | { |
563 | 562 | $this->resampleByWidth($width); |
564 | - } |
|
565 | - else |
|
563 | + } else |
|
566 | 564 | { |
567 | 565 | $this->resampleByHeight($height); |
568 | 566 | } |
@@ -1037,8 +1035,7 @@ discard block |
||
1037 | 1035 | { |
1038 | 1036 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
1039 | 1037 | imagecolortransparent($im2, $bg2); |
1040 | - } |
|
1041 | - else |
|
1038 | + } else |
|
1042 | 1039 | { |
1043 | 1040 | $bg2 = imagecolorallocate($im2, $color['red'], $color['green'], $color['blue']); |
1044 | 1041 | } |
@@ -1348,8 +1345,7 @@ discard block |
||
1348 | 1345 | if(method_exists(__CLASS__, $method)) |
1349 | 1346 | { |
1350 | 1347 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
1351 | - } |
|
1352 | - else |
|
1348 | + } else |
|
1353 | 1349 | { |
1354 | 1350 | $info = getimagesize($pathOrResource); |
1355 | 1351 | } |
@@ -50,53 +50,53 @@ discard block |
||
50 | 50 | const COLORFORMAT_HEX = 2; |
51 | 51 | |
52 | 52 | /** |
53 | - * @var string |
|
54 | - */ |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $file; |
56 | 56 | |
57 | - /** |
|
58 | - * @var ImageHelper_Size |
|
59 | - */ |
|
57 | + /** |
|
58 | + * @var ImageHelper_Size |
|
59 | + */ |
|
60 | 60 | protected $info; |
61 | 61 | |
62 | - /** |
|
63 | - * @var string |
|
64 | - */ |
|
62 | + /** |
|
63 | + * @var string |
|
64 | + */ |
|
65 | 65 | protected $type; |
66 | 66 | |
67 | - /** |
|
68 | - * @var resource|NULL |
|
69 | - */ |
|
67 | + /** |
|
68 | + * @var resource|NULL |
|
69 | + */ |
|
70 | 70 | protected $newImage; |
71 | 71 | |
72 | - /** |
|
73 | - * @var resource |
|
74 | - */ |
|
72 | + /** |
|
73 | + * @var resource |
|
74 | + */ |
|
75 | 75 | protected $sourceImage; |
76 | 76 | |
77 | - /** |
|
78 | - * @var int |
|
79 | - */ |
|
77 | + /** |
|
78 | + * @var int |
|
79 | + */ |
|
80 | 80 | protected $width; |
81 | 81 | |
82 | - /** |
|
83 | - * @var int |
|
84 | - */ |
|
82 | + /** |
|
83 | + * @var int |
|
84 | + */ |
|
85 | 85 | protected $height; |
86 | 86 | |
87 | - /** |
|
88 | - * @var int |
|
89 | - */ |
|
87 | + /** |
|
88 | + * @var int |
|
89 | + */ |
|
90 | 90 | protected $newWidth = 0; |
91 | 91 | |
92 | - /** |
|
93 | - * @var int |
|
94 | - */ |
|
92 | + /** |
|
93 | + * @var int |
|
94 | + */ |
|
95 | 95 | protected $newHeight = 0; |
96 | 96 | |
97 | - /** |
|
98 | - * @var int |
|
99 | - */ |
|
97 | + /** |
|
98 | + * @var int |
|
99 | + */ |
|
100 | 100 | protected $quality = 85; |
101 | 101 | |
102 | 102 | /** |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - /** |
|
205 | - * Factory method: creates a new helper with a blank image. |
|
206 | - * |
|
207 | - * @param integer $width |
|
208 | - * @param integer $height |
|
209 | - * @param string $type The target file type when saving |
|
210 | - * @return ImageHelper |
|
211 | - * @throws ImageHelper_Exception |
|
212 | - * |
|
213 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
214 | - */ |
|
204 | + /** |
|
205 | + * Factory method: creates a new helper with a blank image. |
|
206 | + * |
|
207 | + * @param integer $width |
|
208 | + * @param integer $height |
|
209 | + * @param string $type The target file type when saving |
|
210 | + * @return ImageHelper |
|
211 | + * @throws ImageHelper_Exception |
|
212 | + * |
|
213 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
214 | + */ |
|
215 | 215 | public static function createNew($width, $height, $type='png') |
216 | 216 | { |
217 | 217 | $img = imagecreatetruecolor($width, $height); |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
229 | - /** |
|
230 | - * Factory method: creates an image helper from an |
|
231 | - * existing image resource. |
|
232 | - * |
|
233 | - * Note: while the resource is type independent, the |
|
234 | - * type parameter is required for some methods, as well |
|
235 | - * as to be able to save the image. |
|
236 | - * |
|
237 | - * @param resource $resource |
|
238 | - * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
239 | - * @return ImageHelper |
|
240 | - */ |
|
229 | + /** |
|
230 | + * Factory method: creates an image helper from an |
|
231 | + * existing image resource. |
|
232 | + * |
|
233 | + * Note: while the resource is type independent, the |
|
234 | + * type parameter is required for some methods, as well |
|
235 | + * as to be able to save the image. |
|
236 | + * |
|
237 | + * @param resource $resource |
|
238 | + * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
239 | + * @return ImageHelper |
|
240 | + */ |
|
241 | 241 | public static function createFromResource($resource, ?string $type=null) |
242 | 242 | { |
243 | 243 | self::requireResource($resource); |
@@ -245,29 +245,29 @@ discard block |
||
245 | 245 | return new ImageHelper(null, $resource, $type); |
246 | 246 | } |
247 | 247 | |
248 | - /** |
|
249 | - * Factory method: creates an image helper from an |
|
250 | - * image file on disk. |
|
251 | - * |
|
252 | - * @param string $file |
|
253 | - * @return ImageHelper |
|
254 | - */ |
|
248 | + /** |
|
249 | + * Factory method: creates an image helper from an |
|
250 | + * image file on disk. |
|
251 | + * |
|
252 | + * @param string $file |
|
253 | + * @return ImageHelper |
|
254 | + */ |
|
255 | 255 | public static function createFromFile(string $file) : ImageHelper |
256 | 256 | { |
257 | 257 | return new ImageHelper($file); |
258 | 258 | } |
259 | 259 | |
260 | - /** |
|
261 | - * Sets a global image helper configuration value. Available |
|
262 | - * configuration settings are: |
|
263 | - * |
|
264 | - * <ul> |
|
265 | - * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
266 | - * </ul> |
|
267 | - * |
|
268 | - * @param string $name |
|
269 | - * @param mixed $value |
|
270 | - */ |
|
260 | + /** |
|
261 | + * Sets a global image helper configuration value. Available |
|
262 | + * configuration settings are: |
|
263 | + * |
|
264 | + * <ul> |
|
265 | + * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
266 | + * </ul> |
|
267 | + * |
|
268 | + * @param string $name |
|
269 | + * @param mixed $value |
|
270 | + */ |
|
271 | 271 | public static function setConfig($name, $value) |
272 | 272 | { |
273 | 273 | if(isset(self::$config[$name])) { |
@@ -275,22 +275,22 @@ discard block |
||
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | - /** |
|
279 | - * Shorthand for setting the automatic memory adjustment |
|
280 | - * global configuration setting. |
|
281 | - * |
|
282 | - * @param bool $enabled |
|
283 | - */ |
|
278 | + /** |
|
279 | + * Shorthand for setting the automatic memory adjustment |
|
280 | + * global configuration setting. |
|
281 | + * |
|
282 | + * @param bool $enabled |
|
283 | + */ |
|
284 | 284 | public static function setAutoMemoryAdjustment($enabled=true) |
285 | 285 | { |
286 | 286 | self::setConfig('auto-memory-adjustment', $enabled); |
287 | 287 | } |
288 | 288 | |
289 | - /** |
|
290 | - * Duplicates an image resource. |
|
291 | - * @param resource $img |
|
292 | - * @return resource |
|
293 | - */ |
|
289 | + /** |
|
290 | + * Duplicates an image resource. |
|
291 | + * @param resource $img |
|
292 | + * @return resource |
|
293 | + */ |
|
294 | 294 | protected function duplicateImage($img) |
295 | 295 | { |
296 | 296 | self::requireResource($img); |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | return $duplicate; |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * Duplicates the current state of the image into a new |
|
307 | - * image helper instance. |
|
308 | - * |
|
309 | - * @return ImageHelper |
|
310 | - */ |
|
305 | + /** |
|
306 | + * Duplicates the current state of the image into a new |
|
307 | + * image helper instance. |
|
308 | + * |
|
309 | + * @return ImageHelper |
|
310 | + */ |
|
311 | 311 | public function duplicate() |
312 | 312 | { |
313 | 313 | return ImageHelper::createFromResource($this->duplicateImage($this->newImage)); |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | )); |
496 | 496 | } |
497 | 497 | |
498 | - /** |
|
499 | - * Resamples the image to a new width, maintaining |
|
500 | - * aspect ratio. |
|
501 | - * |
|
502 | - * @param int $width |
|
503 | - * @return ImageHelper |
|
504 | - */ |
|
498 | + /** |
|
499 | + * Resamples the image to a new width, maintaining |
|
500 | + * aspect ratio. |
|
501 | + * |
|
502 | + * @param int $width |
|
503 | + * @return ImageHelper |
|
504 | + */ |
|
505 | 505 | public function resampleByWidth(int $width) : ImageHelper |
506 | 506 | { |
507 | 507 | $size = $this->getSizeByWidth($width); |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | return $this; |
512 | 512 | } |
513 | 513 | |
514 | - /** |
|
515 | - * Resamples the image by height, and creates a new image file on disk. |
|
516 | - * |
|
517 | - * @param int $height |
|
518 | - * @return ImageHelper |
|
519 | - */ |
|
514 | + /** |
|
515 | + * Resamples the image by height, and creates a new image file on disk. |
|
516 | + * |
|
517 | + * @param int $height |
|
518 | + * @return ImageHelper |
|
519 | + */ |
|
520 | 520 | public function resampleByHeight($height) : ImageHelper |
521 | 521 | { |
522 | 522 | $size = $this->getSizeByHeight($height); |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | return $this->resampleImage($size->getWidth(), $size->getHeight()); |
525 | 525 | } |
526 | 526 | |
527 | - /** |
|
528 | - * Resamples the image without keeping the aspect ratio. |
|
529 | - * |
|
530 | - * @param int $width |
|
531 | - * @param int $height |
|
532 | - * @return ImageHelper |
|
533 | - */ |
|
527 | + /** |
|
528 | + * Resamples the image without keeping the aspect ratio. |
|
529 | + * |
|
530 | + * @param int $width |
|
531 | + * @param int $height |
|
532 | + * @return ImageHelper |
|
533 | + */ |
|
534 | 534 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
535 | 535 | { |
536 | 536 | if($this->isVector()) { |
@@ -595,12 +595,12 @@ discard block |
||
595 | 595 | |
596 | 596 | protected $alpha = false; |
597 | 597 | |
598 | - /** |
|
599 | - * Configures the specified image resource to make it alpha compatible. |
|
600 | - * |
|
601 | - * @param resource $canvas |
|
602 | - * @param bool $fill Whether to fill the whole canvas with the transparency |
|
603 | - */ |
|
598 | + /** |
|
599 | + * Configures the specified image resource to make it alpha compatible. |
|
600 | + * |
|
601 | + * @param resource $canvas |
|
602 | + * @param bool $fill Whether to fill the whole canvas with the transparency |
|
603 | + */ |
|
604 | 604 | public static function addAlphaSupport($canvas, $fill=true) |
605 | 605 | { |
606 | 606 | self::requireResource($canvas); |
@@ -715,12 +715,12 @@ discard block |
||
715 | 715 | $this->quality = $quality * 1; |
716 | 716 | } |
717 | 717 | |
718 | - /** |
|
719 | - * Attempts to adjust the memory to the required size |
|
720 | - * to work with the current image. |
|
721 | - * |
|
722 | - * @return boolean |
|
723 | - */ |
|
718 | + /** |
|
719 | + * Attempts to adjust the memory to the required size |
|
720 | + * to work with the current image. |
|
721 | + * |
|
722 | + * @return boolean |
|
723 | + */ |
|
724 | 724 | protected function adjustMemory() : bool |
725 | 725 | { |
726 | 726 | if(!self::$config['auto-memory-adjustment']) { |
@@ -760,27 +760,27 @@ discard block |
||
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | |
763 | - /** |
|
764 | - * Stretches the image to the specified dimensions. |
|
765 | - * |
|
766 | - * @param int $width |
|
767 | - * @param int $height |
|
768 | - * @return ImageHelper |
|
769 | - */ |
|
763 | + /** |
|
764 | + * Stretches the image to the specified dimensions. |
|
765 | + * |
|
766 | + * @param int $width |
|
767 | + * @param int $height |
|
768 | + * @return ImageHelper |
|
769 | + */ |
|
770 | 770 | public function stretch(int $width, int $height) : ImageHelper |
771 | 771 | { |
772 | 772 | return $this->resampleImage($width, $height); |
773 | 773 | } |
774 | 774 | |
775 | - /** |
|
776 | - * Creates a new image from the current image, |
|
777 | - * resampling it to the new size. |
|
778 | - * |
|
779 | - * @param int $newWidth |
|
780 | - * @param int $newHeight |
|
781 | - * @throws ImageHelper_Exception |
|
782 | - * @return ImageHelper |
|
783 | - */ |
|
775 | + /** |
|
776 | + * Creates a new image from the current image, |
|
777 | + * resampling it to the new size. |
|
778 | + * |
|
779 | + * @param int $newWidth |
|
780 | + * @param int $newHeight |
|
781 | + * @throws ImageHelper_Exception |
|
782 | + * @return ImageHelper |
|
783 | + */ |
|
784 | 784 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
785 | 785 | { |
786 | 786 | if($this->isVector()) { |
@@ -849,17 +849,17 @@ discard block |
||
849 | 849 | return array_unique($types); |
850 | 850 | } |
851 | 851 | |
852 | - /** |
|
853 | - * Displays an existing image resource. |
|
854 | - * |
|
855 | - * @param resource $resource |
|
856 | - * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
857 | - * @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 |
|
858 | - * |
|
859 | - * @throws ImageHelper_Exception |
|
860 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
861 | - * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
862 | - */ |
|
852 | + /** |
|
853 | + * Displays an existing image resource. |
|
854 | + * |
|
855 | + * @param resource $resource |
|
856 | + * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
857 | + * @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 |
|
858 | + * |
|
859 | + * @throws ImageHelper_Exception |
|
860 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
861 | + * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
862 | + */ |
|
863 | 863 | public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
864 | 864 | { |
865 | 865 | self::requireResource($resource); |
@@ -942,11 +942,11 @@ discard block |
||
942 | 942 | readfile($imageFile); |
943 | 943 | } |
944 | 944 | |
945 | - /** |
|
946 | - * Displays the current image. |
|
947 | - * |
|
948 | - * NOTE: You must call `exit()` manually after this. |
|
949 | - */ |
|
945 | + /** |
|
946 | + * Displays the current image. |
|
947 | + * |
|
948 | + * NOTE: You must call `exit()` manually after this. |
|
949 | + */ |
|
950 | 950 | public function display() : void |
951 | 951 | { |
952 | 952 | $this->displayImageStream( |
@@ -970,16 +970,16 @@ discard block |
||
970 | 970 | return $this->trimImage($this->newImage, $color); |
971 | 971 | } |
972 | 972 | |
973 | - /** |
|
974 | - * Retrieves a color definition by its index. |
|
975 | - * |
|
976 | - * @param resource $img A valid image resource. |
|
977 | - * @param int $colorIndex The color index, as returned by `imagecolorat` for example. |
|
978 | - * @return array<string,int> An array with red, green, blue and alpha keys. |
|
979 | - * |
|
980 | - * @throws ImageHelper_Exception |
|
981 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
982 | - */ |
|
973 | + /** |
|
974 | + * Retrieves a color definition by its index. |
|
975 | + * |
|
976 | + * @param resource $img A valid image resource. |
|
977 | + * @param int $colorIndex The color index, as returned by `imagecolorat` for example. |
|
978 | + * @return array<string,int> An array with red, green, blue and alpha keys. |
|
979 | + * |
|
980 | + * @throws ImageHelper_Exception |
|
981 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
982 | + */ |
|
983 | 983 | public function getIndexedColors($img, int $colorIndex) : array |
984 | 984 | { |
985 | 985 | self::requireResource($img); |
@@ -999,18 +999,18 @@ discard block |
||
999 | 999 | ); |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - /** |
|
1003 | - * Trims the specified image resource by removing the specified color. |
|
1004 | - * Also works with transparency. |
|
1005 | - * |
|
1006 | - * @param resource $img |
|
1007 | - * @param array|NULL $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
|
1008 | - * @return ImageHelper |
|
1009 | - * |
|
1010 | - * @throws ImageHelper_Exception |
|
1011 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1012 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
|
1013 | - */ |
|
1002 | + /** |
|
1003 | + * Trims the specified image resource by removing the specified color. |
|
1004 | + * Also works with transparency. |
|
1005 | + * |
|
1006 | + * @param resource $img |
|
1007 | + * @param array|NULL $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
|
1008 | + * @return ImageHelper |
|
1009 | + * |
|
1010 | + * @throws ImageHelper_Exception |
|
1011 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1012 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
|
1013 | + */ |
|
1014 | 1014 | protected function trimImage($img, ?array $color=null) : ImageHelper |
1015 | 1015 | { |
1016 | 1016 | if($this->isVector()) { |
@@ -1118,14 +1118,14 @@ discard block |
||
1118 | 1118 | return $this; |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - /** |
|
1122 | - * Requires the subject to be a resource. |
|
1123 | - * |
|
1124 | - * @param resource|mixed $subject |
|
1125 | - * |
|
1126 | - * @throws ImageHelper_Exception |
|
1127 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1128 | - */ |
|
1121 | + /** |
|
1122 | + * Requires the subject to be a resource. |
|
1123 | + * |
|
1124 | + * @param resource|mixed $subject |
|
1125 | + * |
|
1126 | + * @throws ImageHelper_Exception |
|
1127 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
1128 | + */ |
|
1129 | 1129 | protected static function requireResource($subject) : void |
1130 | 1130 | { |
1131 | 1131 | if(is_resource($subject)) { |
@@ -1142,14 +1142,14 @@ discard block |
||
1142 | 1142 | ); |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - /** |
|
1146 | - * Creates a new image resource, with transparent background. |
|
1147 | - * |
|
1148 | - * @param int $width |
|
1149 | - * @param int $height |
|
1150 | - * @throws ImageHelper_Exception |
|
1151 | - * @return resource |
|
1152 | - */ |
|
1145 | + /** |
|
1146 | + * Creates a new image resource, with transparent background. |
|
1147 | + * |
|
1148 | + * @param int $width |
|
1149 | + * @param int $height |
|
1150 | + * @throws ImageHelper_Exception |
|
1151 | + * @return resource |
|
1152 | + */ |
|
1153 | 1153 | protected function createNewImage(int $width, int $height) |
1154 | 1154 | { |
1155 | 1155 | $img = imagecreatetruecolor($width, $height); |
@@ -1168,54 +1168,54 @@ discard block |
||
1168 | 1168 | return $img; |
1169 | 1169 | } |
1170 | 1170 | |
1171 | - /** |
|
1172 | - * Whether the two specified colors are the same. |
|
1173 | - * |
|
1174 | - * @param array<string,int> $a |
|
1175 | - * @param array<string,int> $b |
|
1176 | - * @return boolean |
|
1177 | - */ |
|
1178 | - protected function colorsMatch(array $a, array $b) : bool |
|
1179 | - { |
|
1180 | - $parts = array('red', 'green', 'blue'); |
|
1181 | - foreach($parts as $part) { |
|
1182 | - if($a[$part] != $b[$part]) { |
|
1183 | - return false; |
|
1184 | - } |
|
1185 | - } |
|
1171 | + /** |
|
1172 | + * Whether the two specified colors are the same. |
|
1173 | + * |
|
1174 | + * @param array<string,int> $a |
|
1175 | + * @param array<string,int> $b |
|
1176 | + * @return boolean |
|
1177 | + */ |
|
1178 | + protected function colorsMatch(array $a, array $b) : bool |
|
1179 | + { |
|
1180 | + $parts = array('red', 'green', 'blue'); |
|
1181 | + foreach($parts as $part) { |
|
1182 | + if($a[$part] != $b[$part]) { |
|
1183 | + return false; |
|
1184 | + } |
|
1185 | + } |
|
1186 | 1186 | |
1187 | - return true; |
|
1188 | - } |
|
1187 | + return true; |
|
1188 | + } |
|
1189 | 1189 | |
1190 | - public function fillWhite($x=0, $y=0) |
|
1191 | - { |
|
1192 | - $this->addRGBColor('white', 255, 255, 255); |
|
1190 | + public function fillWhite($x=0, $y=0) |
|
1191 | + { |
|
1192 | + $this->addRGBColor('white', 255, 255, 255); |
|
1193 | 1193 | return $this->fill('white', $x, $y); |
1194 | - } |
|
1194 | + } |
|
1195 | 1195 | |
1196 | - public function fillTransparent() : ImageHelper |
|
1197 | - { |
|
1196 | + public function fillTransparent() : ImageHelper |
|
1197 | + { |
|
1198 | 1198 | $this->enableAlpha(); |
1199 | 1199 | |
1200 | - self::fillImageTransparent($this->newImage); |
|
1200 | + self::fillImageTransparent($this->newImage); |
|
1201 | 1201 | |
1202 | - return $this; |
|
1203 | - } |
|
1202 | + return $this; |
|
1203 | + } |
|
1204 | 1204 | |
1205 | - public static function fillImageTransparent($resource) |
|
1206 | - { |
|
1207 | - self::requireResource($resource); |
|
1205 | + public static function fillImageTransparent($resource) |
|
1206 | + { |
|
1207 | + self::requireResource($resource); |
|
1208 | 1208 | |
1209 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1210 | - imagecolortransparent ($resource, $transparent); |
|
1211 | - imagefill($resource, 0, 0, $transparent); |
|
1212 | - } |
|
1209 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1210 | + imagecolortransparent ($resource, $transparent); |
|
1211 | + imagefill($resource, 0, 0, $transparent); |
|
1212 | + } |
|
1213 | 1213 | |
1214 | - public function fill($colorName, $x=0, $y=0) |
|
1215 | - { |
|
1216 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1217 | - return $this; |
|
1218 | - } |
|
1214 | + public function fill($colorName, $x=0, $y=0) |
|
1215 | + { |
|
1216 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1217 | + return $this; |
|
1218 | + } |
|
1219 | 1219 | |
1220 | 1220 | protected $colors = array(); |
1221 | 1221 | |
@@ -1236,9 +1236,9 @@ discard block |
||
1236 | 1236 | return $this; |
1237 | 1237 | } |
1238 | 1238 | |
1239 | - /** |
|
1240 | - * @return resource |
|
1241 | - */ |
|
1239 | + /** |
|
1240 | + * @return resource |
|
1241 | + */ |
|
1242 | 1242 | public function getImage() |
1243 | 1243 | { |
1244 | 1244 | return $this->newImage; |
@@ -1256,26 +1256,26 @@ discard block |
||
1256 | 1256 | return $this; |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - /** |
|
1260 | - * Retrieves the size of the image. |
|
1261 | - * |
|
1262 | - * @return ImageHelper_Size |
|
1263 | - * @throws ImageHelper_Exception |
|
1264 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1265 | - */ |
|
1266 | - public function getSize() : ImageHelper_Size |
|
1259 | + /** |
|
1260 | + * Retrieves the size of the image. |
|
1261 | + * |
|
1262 | + * @return ImageHelper_Size |
|
1263 | + * @throws ImageHelper_Exception |
|
1264 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1265 | + */ |
|
1266 | + public function getSize() : ImageHelper_Size |
|
1267 | 1267 | { |
1268 | - return self::getImageSize($this->newImage); |
|
1268 | + return self::getImageSize($this->newImage); |
|
1269 | 1269 | } |
1270 | 1270 | |
1271 | 1271 | protected $TTFFile; |
1272 | 1272 | |
1273 | - /** |
|
1274 | - * Sets the TTF font file to use for text operations. |
|
1275 | - * |
|
1276 | - * @param string $filePath |
|
1277 | - * @return ImageHelper |
|
1278 | - */ |
|
1273 | + /** |
|
1274 | + * Sets the TTF font file to use for text operations. |
|
1275 | + * |
|
1276 | + * @param string $filePath |
|
1277 | + * @return ImageHelper |
|
1278 | + */ |
|
1279 | 1279 | public function setFontTTF($filePath) |
1280 | 1280 | { |
1281 | 1281 | $this->TTFFile = $filePath; |
@@ -1347,63 +1347,63 @@ discard block |
||
1347 | 1347 | return; |
1348 | 1348 | } |
1349 | 1349 | |
1350 | - throw new ImageHelper_Exception( |
|
1350 | + throw new ImageHelper_Exception( |
|
1351 | 1351 | 'No true type font specified', |
1352 | 1352 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
1353 | 1353 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
1354 | 1354 | ); |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - /** |
|
1358 | - * Retrieves the size of an image file on disk, or |
|
1359 | - * an existing image resource. |
|
1360 | - * |
|
1361 | - * <pre> |
|
1362 | - * array( |
|
1363 | - * 0: (width), |
|
1364 | - * 1: (height), |
|
1365 | - * "channels": the amount of channels |
|
1366 | - * "bits": bits per channel |
|
1357 | + /** |
|
1358 | + * Retrieves the size of an image file on disk, or |
|
1359 | + * an existing image resource. |
|
1360 | + * |
|
1361 | + * <pre> |
|
1362 | + * array( |
|
1363 | + * 0: (width), |
|
1364 | + * 1: (height), |
|
1365 | + * "channels": the amount of channels |
|
1366 | + * "bits": bits per channel |
|
1367 | 1367 | * ) |
1368 | - * </pre> |
|
1369 | - * |
|
1370 | - * @param string|resource $pathOrResource |
|
1371 | - * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
1372 | - * @see ImageHelper_Size |
|
1373 | - * @throws ImageHelper_Exception |
|
1374 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1375 | - * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
1376 | - * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1377 | - * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
1378 | - */ |
|
1379 | - public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1380 | - { |
|
1381 | - if(is_resource($pathOrResource)) |
|
1382 | - { |
|
1383 | - return new ImageHelper_Size(array( |
|
1384 | - 'width' => imagesx($pathOrResource), |
|
1385 | - 'height' => imagesy($pathOrResource), |
|
1386 | - 'channels' => 1, |
|
1387 | - 'bits' => 8 |
|
1388 | - )); |
|
1389 | - } |
|
1368 | + * </pre> |
|
1369 | + * |
|
1370 | + * @param string|resource $pathOrResource |
|
1371 | + * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
1372 | + * @see ImageHelper_Size |
|
1373 | + * @throws ImageHelper_Exception |
|
1374 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1375 | + * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
1376 | + * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1377 | + * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
1378 | + */ |
|
1379 | + public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1380 | + { |
|
1381 | + if(is_resource($pathOrResource)) |
|
1382 | + { |
|
1383 | + return new ImageHelper_Size(array( |
|
1384 | + 'width' => imagesx($pathOrResource), |
|
1385 | + 'height' => imagesy($pathOrResource), |
|
1386 | + 'channels' => 1, |
|
1387 | + 'bits' => 8 |
|
1388 | + )); |
|
1389 | + } |
|
1390 | 1390 | |
1391 | - $type = self::getFileImageType($pathOrResource); |
|
1391 | + $type = self::getFileImageType($pathOrResource); |
|
1392 | 1392 | |
1393 | - $info = false; |
|
1394 | - $method = 'getImageSize_'.$type; |
|
1395 | - if(method_exists(__CLASS__, $method)) |
|
1396 | - { |
|
1397 | - $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
1398 | - } |
|
1399 | - else |
|
1400 | - { |
|
1401 | - $info = getimagesize($pathOrResource); |
|
1402 | - } |
|
1393 | + $info = false; |
|
1394 | + $method = 'getImageSize_'.$type; |
|
1395 | + if(method_exists(__CLASS__, $method)) |
|
1396 | + { |
|
1397 | + $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
1398 | + } |
|
1399 | + else |
|
1400 | + { |
|
1401 | + $info = getimagesize($pathOrResource); |
|
1402 | + } |
|
1403 | 1403 | |
1404 | - if($info !== false) { |
|
1405 | - return new ImageHelper_Size($info); |
|
1406 | - } |
|
1404 | + if($info !== false) { |
|
1405 | + return new ImageHelper_Size($info); |
|
1406 | + } |
|
1407 | 1407 | |
1408 | 1408 | throw new ImageHelper_Exception( |
1409 | 1409 | 'Error opening image file', |
@@ -1413,98 +1413,98 @@ discard block |
||
1413 | 1413 | ), |
1414 | 1414 | self::ERROR_CANNOT_GET_IMAGE_SIZE |
1415 | 1415 | ); |
1416 | - } |
|
1416 | + } |
|
1417 | 1417 | |
1418 | - /** |
|
1419 | - * @param string $imagePath |
|
1420 | - * @throws ImageHelper_Exception |
|
1421 | - * @return array |
|
1422 | - * |
|
1423 | - * @todo This should return a ImageHelper_Size instance. |
|
1424 | - */ |
|
1425 | - protected static function getImageSize_svg(string $imagePath) : array |
|
1426 | - { |
|
1427 | - $xml = XMLHelper::createSimplexml(); |
|
1428 | - $xml->loadFile($imagePath); |
|
1418 | + /** |
|
1419 | + * @param string $imagePath |
|
1420 | + * @throws ImageHelper_Exception |
|
1421 | + * @return array |
|
1422 | + * |
|
1423 | + * @todo This should return a ImageHelper_Size instance. |
|
1424 | + */ |
|
1425 | + protected static function getImageSize_svg(string $imagePath) : array |
|
1426 | + { |
|
1427 | + $xml = XMLHelper::createSimplexml(); |
|
1428 | + $xml->loadFile($imagePath); |
|
1429 | 1429 | |
1430 | - if($xml->hasErrors()) { |
|
1431 | - throw new ImageHelper_Exception( |
|
1432 | - 'Error opening SVG image', |
|
1433 | - sprintf( |
|
1434 | - 'The XML content of the image [%s] could not be parsed.', |
|
1435 | - $imagePath |
|
1430 | + if($xml->hasErrors()) { |
|
1431 | + throw new ImageHelper_Exception( |
|
1432 | + 'Error opening SVG image', |
|
1433 | + sprintf( |
|
1434 | + 'The XML content of the image [%s] could not be parsed.', |
|
1435 | + $imagePath |
|
1436 | 1436 | ), |
1437 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1437 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1438 | 1438 | ); |
1439 | - } |
|
1439 | + } |
|
1440 | 1440 | |
1441 | - $data = $xml->toArray(); |
|
1442 | - $xml->dispose(); |
|
1443 | - unset($xml); |
|
1441 | + $data = $xml->toArray(); |
|
1442 | + $xml->dispose(); |
|
1443 | + unset($xml); |
|
1444 | 1444 | |
1445 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1446 | - throw new ImageHelper_Exception( |
|
1447 | - 'SVG Image is corrupted', |
|
1448 | - sprintf( |
|
1449 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1450 | - $imagePath |
|
1445 | + if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1446 | + throw new ImageHelper_Exception( |
|
1447 | + 'SVG Image is corrupted', |
|
1448 | + sprintf( |
|
1449 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1450 | + $imagePath |
|
1451 | 1451 | ), |
1452 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1452 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1453 | 1453 | ); |
1454 | - } |
|
1454 | + } |
|
1455 | 1455 | |
1456 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1457 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1456 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1457 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1458 | 1458 | |
1459 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1460 | - $size = explode(',', $viewBox); |
|
1459 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1460 | + $size = explode(',', $viewBox); |
|
1461 | 1461 | |
1462 | - if(count($size) != 4) |
|
1463 | - { |
|
1464 | - throw new ImageHelper_Exception( |
|
1465 | - 'SVG image has an invalid viewBox attribute', |
|
1466 | - sprintf( |
|
1467 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1468 | - $viewBox, |
|
1469 | - $imagePath |
|
1462 | + if(count($size) != 4) |
|
1463 | + { |
|
1464 | + throw new ImageHelper_Exception( |
|
1465 | + 'SVG image has an invalid viewBox attribute', |
|
1466 | + sprintf( |
|
1467 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1468 | + $viewBox, |
|
1469 | + $imagePath |
|
1470 | 1470 | ), |
1471 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
1471 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
1472 | 1472 | ); |
1473 | - } |
|
1473 | + } |
|
1474 | 1474 | |
1475 | - $boxWidth = $size[2]; |
|
1476 | - $boxHeight = $size[3]; |
|
1475 | + $boxWidth = $size[2]; |
|
1476 | + $boxHeight = $size[3]; |
|
1477 | 1477 | |
1478 | - // calculate the x and y units of the document: |
|
1479 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1480 | - // |
|
1481 | - // The viewbox combined with the width and heigt of the svg |
|
1482 | - // allow calculating how many pixels are in one unit of the |
|
1483 | - // width and height of the document. |
|
1478 | + // calculate the x and y units of the document: |
|
1479 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1480 | + // |
|
1481 | + // The viewbox combined with the width and heigt of the svg |
|
1482 | + // allow calculating how many pixels are in one unit of the |
|
1483 | + // width and height of the document. |
|
1484 | 1484 | // |
1485 | - $xUnits = $svgWidth / $boxWidth; |
|
1486 | - $yUnits = $svgHeight / $boxHeight; |
|
1485 | + $xUnits = $svgWidth / $boxWidth; |
|
1486 | + $yUnits = $svgHeight / $boxHeight; |
|
1487 | 1487 | |
1488 | - $pxWidth = $xUnits * $svgWidth; |
|
1489 | - $pxHeight = $yUnits * $svgHeight; |
|
1488 | + $pxWidth = $xUnits * $svgWidth; |
|
1489 | + $pxHeight = $yUnits * $svgHeight; |
|
1490 | 1490 | |
1491 | - return array( |
|
1492 | - $pxWidth, |
|
1493 | - $pxHeight, |
|
1494 | - 'bits' => 8 |
|
1495 | - ); |
|
1496 | - } |
|
1491 | + return array( |
|
1492 | + $pxWidth, |
|
1493 | + $pxHeight, |
|
1494 | + 'bits' => 8 |
|
1495 | + ); |
|
1496 | + } |
|
1497 | 1497 | |
1498 | - /** |
|
1499 | - * Crops the image to the specified width and height, optionally |
|
1500 | - * specifying the origin position to crop from. |
|
1501 | - * |
|
1502 | - * @param integer $width |
|
1503 | - * @param integer $height |
|
1504 | - * @param integer $x |
|
1505 | - * @param integer $y |
|
1506 | - * @return ImageHelper |
|
1507 | - */ |
|
1498 | + /** |
|
1499 | + * Crops the image to the specified width and height, optionally |
|
1500 | + * specifying the origin position to crop from. |
|
1501 | + * |
|
1502 | + * @param integer $width |
|
1503 | + * @param integer $height |
|
1504 | + * @param integer $x |
|
1505 | + * @param integer $y |
|
1506 | + * @return ImageHelper |
|
1507 | + */ |
|
1508 | 1508 | public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
1509 | 1509 | { |
1510 | 1510 | $new = $this->createNewImage($width, $height); |
@@ -1526,22 +1526,22 @@ discard block |
||
1526 | 1526 | return $this->newHeight; |
1527 | 1527 | } |
1528 | 1528 | |
1529 | - /** |
|
1530 | - * Calculates the average color value used in |
|
1531 | - * the image. Returns an associative array |
|
1532 | - * with the red, green, blue and alpha components, |
|
1533 | - * or a HEX color string depending on the selected |
|
1534 | - * format. |
|
1535 | - * |
|
1536 | - * NOTE: Use the calcAverageColorXXX methods for |
|
1537 | - * strict return types. |
|
1538 | - * |
|
1539 | - * @param int $format The format in which to return the color value. |
|
1540 | - * @return array|string |
|
1541 | - * |
|
1542 | - * @see ImageHelper::calcAverageColorRGB() |
|
1543 | - * @see ImageHelper::calcAverageColorHEX() |
|
1544 | - */ |
|
1529 | + /** |
|
1530 | + * Calculates the average color value used in |
|
1531 | + * the image. Returns an associative array |
|
1532 | + * with the red, green, blue and alpha components, |
|
1533 | + * or a HEX color string depending on the selected |
|
1534 | + * format. |
|
1535 | + * |
|
1536 | + * NOTE: Use the calcAverageColorXXX methods for |
|
1537 | + * strict return types. |
|
1538 | + * |
|
1539 | + * @param int $format The format in which to return the color value. |
|
1540 | + * @return array|string |
|
1541 | + * |
|
1542 | + * @see ImageHelper::calcAverageColorRGB() |
|
1543 | + * @see ImageHelper::calcAverageColorHEX() |
|
1544 | + */ |
|
1545 | 1545 | public function calcAverageColor(int $format=self::COLORFORMAT_RGB) |
1546 | 1546 | { |
1547 | 1547 | $image = $this->duplicate(); |
@@ -1550,35 +1550,35 @@ discard block |
||
1550 | 1550 | return $image->getColorAt(0, 0, $format); |
1551 | 1551 | } |
1552 | 1552 | |
1553 | - /** |
|
1554 | - * Calculates the image's average color value, and |
|
1555 | - * returns an associative array with red, green, |
|
1556 | - * blue and alpha keys. |
|
1557 | - * |
|
1558 | - * @throws ImageHelper_Exception |
|
1559 | - * @return array |
|
1560 | - */ |
|
1553 | + /** |
|
1554 | + * Calculates the image's average color value, and |
|
1555 | + * returns an associative array with red, green, |
|
1556 | + * blue and alpha keys. |
|
1557 | + * |
|
1558 | + * @throws ImageHelper_Exception |
|
1559 | + * @return array |
|
1560 | + */ |
|
1561 | 1561 | public function calcAverageColorRGB() : array |
1562 | 1562 | { |
1563 | - $result = $this->calcAverageColor(self::COLORFORMAT_RGB); |
|
1564 | - if(is_array($result)) { |
|
1565 | - return $result; |
|
1566 | - } |
|
1563 | + $result = $this->calcAverageColor(self::COLORFORMAT_RGB); |
|
1564 | + if(is_array($result)) { |
|
1565 | + return $result; |
|
1566 | + } |
|
1567 | 1567 | |
1568 | - throw new ImageHelper_Exception( |
|
1569 | - 'Unexpected color value', |
|
1570 | - sprintf('Expected an array, got [%s].', gettype($result)), |
|
1571 | - self::ERROR_UNEXPECTED_COLOR_VALUE |
|
1572 | - ); |
|
1568 | + throw new ImageHelper_Exception( |
|
1569 | + 'Unexpected color value', |
|
1570 | + sprintf('Expected an array, got [%s].', gettype($result)), |
|
1571 | + self::ERROR_UNEXPECTED_COLOR_VALUE |
|
1572 | + ); |
|
1573 | 1573 | } |
1574 | 1574 | |
1575 | - /** |
|
1576 | - * Calculates the image's average color value, and |
|
1577 | - * returns a hex color string (without the #). |
|
1578 | - * |
|
1579 | - * @throws ImageHelper_Exception |
|
1580 | - * @return string |
|
1581 | - */ |
|
1575 | + /** |
|
1576 | + * Calculates the image's average color value, and |
|
1577 | + * returns a hex color string (without the #). |
|
1578 | + * |
|
1579 | + * @throws ImageHelper_Exception |
|
1580 | + * @return string |
|
1581 | + */ |
|
1582 | 1582 | public function calcAverageColorHex() : string |
1583 | 1583 | { |
1584 | 1584 | $result = $this->calcAverageColor(self::COLORFORMAT_HEX); |
@@ -1645,12 +1645,12 @@ discard block |
||
1645 | 1645 | return $rgb; |
1646 | 1646 | } |
1647 | 1647 | |
1648 | - /** |
|
1649 | - * Converts an RGB value to its luminance equivalent. |
|
1650 | - * |
|
1651 | - * @param array<string,int> $rgb |
|
1652 | - * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
1653 | - */ |
|
1648 | + /** |
|
1649 | + * Converts an RGB value to its luminance equivalent. |
|
1650 | + * |
|
1651 | + * @param array<string,int> $rgb |
|
1652 | + * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
1653 | + */ |
|
1654 | 1654 | public static function rgb2luma(array $rgb) : int |
1655 | 1655 | { |
1656 | 1656 | return (int)floor((($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6); |
@@ -1670,15 +1670,15 @@ discard block |
||
1670 | 1670 | return $luma * 100 / 255; |
1671 | 1671 | } |
1672 | 1672 | |
1673 | - /** |
|
1674 | - * Retrieves an md5 hash of the source image file. |
|
1675 | - * |
|
1676 | - * NOTE: Only works when the helper has been created |
|
1677 | - * from a file. Otherwise, an exception is thrown. |
|
1678 | - * |
|
1679 | - * @return string |
|
1680 | - * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
1681 | - */ |
|
1673 | + /** |
|
1674 | + * Retrieves an md5 hash of the source image file. |
|
1675 | + * |
|
1676 | + * NOTE: Only works when the helper has been created |
|
1677 | + * from a file. Otherwise, an exception is thrown. |
|
1678 | + * |
|
1679 | + * @return string |
|
1680 | + * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
1681 | + */ |
|
1682 | 1682 | public function getHash() : string |
1683 | 1683 | { |
1684 | 1684 | if($this->newImage === null) |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | * @throws ImageHelper_Exception |
135 | 135 | * @see ImageHelper::ERROR_GD_LIBRARY_NOT_INSTALLED |
136 | 136 | */ |
137 | - public function __construct(?string $sourceFile=null, $resource=null, ?string $type=null) |
|
137 | + public function __construct(?string $sourceFile = null, $resource = null, ?string $type = null) |
|
138 | 138 | { |
139 | 139 | // ensure that the GD library is installed |
140 | - if(!function_exists('imagecreate')) |
|
140 | + if (!function_exists('imagecreate')) |
|
141 | 141 | { |
142 | 142 | throw new ImageHelper_Exception( |
143 | 143 | 'The PHP GD extension is not installed or not enabled.', |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
149 | - if(is_resource($resource)) |
|
149 | + if (is_resource($resource)) |
|
150 | 150 | { |
151 | 151 | $this->sourceImage = $resource; |
152 | 152 | $this->type = $type; |
@@ -170,21 +170,21 @@ discard block |
||
170 | 170 | if (is_null($this->type)) { |
171 | 171 | throw new ImageHelper_Exception( |
172 | 172 | 'Error opening image', |
173 | - 'Not a valid supported image type for image ' . $this->file, |
|
173 | + 'Not a valid supported image type for image '.$this->file, |
|
174 | 174 | self::ERROR_UNSUPPORTED_IMAGE_TYPE |
175 | 175 | ); |
176 | 176 | } |
177 | 177 | |
178 | 178 | $this->info = self::getImageSize($this->file); |
179 | 179 | |
180 | - if(!$this->isVector()) |
|
180 | + if (!$this->isVector()) |
|
181 | 181 | { |
182 | - $method = 'imagecreatefrom' . $this->type; |
|
182 | + $method = 'imagecreatefrom'.$this->type; |
|
183 | 183 | $this->sourceImage = $method($this->file); |
184 | 184 | if (!$this->sourceImage) { |
185 | 185 | throw new ImageHelper_Exception( |
186 | 186 | 'Error creating new image', |
187 | - $method . ' failed', |
|
187 | + $method.' failed', |
|
188 | 188 | self::ERROR_FAILED_TO_CREATE_NEW_IMAGE |
189 | 189 | ); |
190 | 190 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $this->width = $this->info->getWidth(); |
197 | 197 | $this->height = $this->info->getHeight(); |
198 | 198 | |
199 | - if(!$this->isVector()) { |
|
199 | + if (!$this->isVector()) { |
|
200 | 200 | $this->setNewImage($this->duplicateImage($this->sourceImage)); |
201 | 201 | } |
202 | 202 | } |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
214 | 214 | */ |
215 | - public static function createNew($width, $height, $type='png') |
|
215 | + public static function createNew($width, $height, $type = 'png') |
|
216 | 216 | { |
217 | 217 | $img = imagecreatetruecolor($width, $height); |
218 | - if($img !== false) { |
|
218 | + if ($img !== false) { |
|
219 | 219 | return self::createFromResource($img, 'png'); |
220 | 220 | } |
221 | 221 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param string $type The target image type, e.g. "jpeg", "png", etc. |
239 | 239 | * @return ImageHelper |
240 | 240 | */ |
241 | - public static function createFromResource($resource, ?string $type=null) |
|
241 | + public static function createFromResource($resource, ?string $type = null) |
|
242 | 242 | { |
243 | 243 | self::requireResource($resource); |
244 | 244 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | */ |
271 | 271 | public static function setConfig($name, $value) |
272 | 272 | { |
273 | - if(isset(self::$config[$name])) { |
|
273 | + if (isset(self::$config[$name])) { |
|
274 | 274 | self::$config[$name] = $value; |
275 | 275 | } |
276 | 276 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param bool $enabled |
283 | 283 | */ |
284 | - public static function setAutoMemoryAdjustment($enabled=true) |
|
284 | + public static function setAutoMemoryAdjustment($enabled = true) |
|
285 | 285 | { |
286 | 286 | self::setConfig('auto-memory-adjustment', $enabled); |
287 | 287 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | |
316 | 316 | public function enableAlpha() |
317 | 317 | { |
318 | - if(!$this->alpha) |
|
318 | + if (!$this->alpha) |
|
319 | 319 | { |
320 | 320 | self::addAlphaSupport($this->newImage, false); |
321 | 321 | $this->alpha = true; |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * @param number $percent |
347 | 347 | * @return ImageHelper |
348 | 348 | */ |
349 | - public function sharpen($percent=0) |
|
349 | + public function sharpen($percent = 0) |
|
350 | 350 | { |
351 | - if($percent <= 0) { |
|
351 | + if ($percent <= 0) { |
|
352 | 352 | return $this; |
353 | 353 | } |
354 | 354 | |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | return $this->convolute($factor); |
358 | 358 | } |
359 | 359 | |
360 | - public function blur($percent=0) |
|
360 | + public function blur($percent = 0) |
|
361 | 361 | { |
362 | - if($percent <= 0) { |
|
362 | + if ($percent <= 0) { |
|
363 | 363 | return $this; |
364 | 364 | } |
365 | 365 | |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | { |
373 | 373 | // get a value thats equal to 64 - abs( factor ) |
374 | 374 | // ( using min/max to limited the factor to 0 - 64 to not get out of range values ) |
375 | - $val1Adjustment = 64 - min( 64, max( 0, abs( $factor ) ) ); |
|
375 | + $val1Adjustment = 64 - min(64, max(0, abs($factor))); |
|
376 | 376 | |
377 | 377 | // the base factor for the "current" pixel depends on if we are blurring or sharpening. |
378 | 378 | // If we are blurring use 1, if sharpening use 9. |
379 | 379 | $val1Base = 9; |
380 | - if( abs( $factor ) != $factor ) { |
|
380 | + if (abs($factor) != $factor) { |
|
381 | 381 | $val1Base = 1; |
382 | 382 | } |
383 | 383 | |
@@ -390,24 +390,24 @@ discard block |
||
390 | 390 | |
391 | 391 | // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening. |
392 | 392 | $val2 = -1; |
393 | - if( abs( $factor ) != $factor ) { |
|
393 | + if (abs($factor) != $factor) { |
|
394 | 394 | $val2 = 1; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // setup matrix .. |
398 | 398 | $matrix = array( |
399 | - array( $val2, $val2, $val2 ), |
|
400 | - array( $val2, $val1, $val2 ), |
|
401 | - array( $val2, $val2, $val2 ) |
|
399 | + array($val2, $val2, $val2), |
|
400 | + array($val2, $val1, $val2), |
|
401 | + array($val2, $val2, $val2) |
|
402 | 402 | ); |
403 | 403 | |
404 | 404 | // calculate the correct divisor |
405 | 405 | // actual divisor is equal to "$divisor = $val1 + $val2 * 8;" |
406 | 406 | // but the following line is more generic |
407 | - $divisor = array_sum( array_map( 'array_sum', $matrix ) ); |
|
407 | + $divisor = array_sum(array_map('array_sum', $matrix)); |
|
408 | 408 | |
409 | 409 | // apply the matrix |
410 | - imageconvolution( $this->newImage, $matrix, $divisor, 0 ); |
|
410 | + imageconvolution($this->newImage, $matrix, $divisor, 0); |
|
411 | 411 | |
412 | 412 | return $this; |
413 | 413 | } |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | */ |
534 | 534 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
535 | 535 | { |
536 | - if($this->isVector()) { |
|
536 | + if ($this->isVector()) { |
|
537 | 537 | return $this; |
538 | 538 | } |
539 | 539 | |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | |
555 | 555 | public function resampleAndCrop($width, $height) : ImageHelper |
556 | 556 | { |
557 | - if($this->isVector()) { |
|
557 | + if ($this->isVector()) { |
|
558 | 558 | return $this; |
559 | 559 | } |
560 | 560 | |
@@ -601,14 +601,14 @@ discard block |
||
601 | 601 | * @param resource $canvas |
602 | 602 | * @param bool $fill Whether to fill the whole canvas with the transparency |
603 | 603 | */ |
604 | - public static function addAlphaSupport($canvas, $fill=true) |
|
604 | + public static function addAlphaSupport($canvas, $fill = true) |
|
605 | 605 | { |
606 | 606 | self::requireResource($canvas); |
607 | 607 | |
608 | - imagealphablending($canvas,true); |
|
608 | + imagealphablending($canvas, true); |
|
609 | 609 | imagesavealpha($canvas, true); |
610 | 610 | |
611 | - if($fill) { |
|
611 | + if ($fill) { |
|
612 | 612 | self::fillImageTransparent($canvas); |
613 | 613 | } |
614 | 614 | } |
@@ -618,13 +618,13 @@ discard block |
||
618 | 618 | return $this->alpha; |
619 | 619 | } |
620 | 620 | |
621 | - public function save(string $targetFile, $dispose=true) |
|
621 | + public function save(string $targetFile, $dispose = true) |
|
622 | 622 | { |
623 | - if($this->isVector()) { |
|
623 | + if ($this->isVector()) { |
|
624 | 624 | return true; |
625 | 625 | } |
626 | 626 | |
627 | - if(!is_resource($this->newImage)) { |
|
627 | + if (!is_resource($this->newImage)) { |
|
628 | 628 | throw new ImageHelper_Exception( |
629 | 629 | 'Error creating new image', |
630 | 630 | 'Cannot save an image, no valid image resource was created. You have to call one of the resample methods to create a new image.', |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | unlink($targetFile); |
637 | 637 | } |
638 | 638 | |
639 | - $method = 'image' . $this->type; |
|
639 | + $method = 'image'.$this->type; |
|
640 | 640 | if (!$method($this->newImage, $targetFile, $this->resolveQuality())) { |
641 | 641 | throw new ImageHelper_Exception( |
642 | 642 | 'Error creating new image', |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | ); |
658 | 658 | } |
659 | 659 | |
660 | - if($dispose) { |
|
660 | + if ($dispose) { |
|
661 | 661 | $this->dispose(); |
662 | 662 | } |
663 | 663 | |
@@ -666,11 +666,11 @@ discard block |
||
666 | 666 | |
667 | 667 | public function dispose() |
668 | 668 | { |
669 | - if(is_resource($this->sourceImage)) { |
|
669 | + if (is_resource($this->sourceImage)) { |
|
670 | 670 | imagedestroy($this->sourceImage); |
671 | 671 | } |
672 | 672 | |
673 | - if(is_resource($this->newImage)) { |
|
673 | + if (is_resource($this->newImage)) { |
|
674 | 674 | imagedestroy($this->newImage); |
675 | 675 | } |
676 | 676 | } |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | */ |
724 | 724 | protected function adjustMemory() : bool |
725 | 725 | { |
726 | - if(!self::$config['auto-memory-adjustment']) { |
|
726 | + if (!self::$config['auto-memory-adjustment']) { |
|
727 | 727 | return true; |
728 | 728 | } |
729 | 729 | |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { |
753 | 753 | $newLimit = ($memoryLimit + (memory_get_usage() + $memoryNeeded)) / $MB; |
754 | 754 | $newLimit = ceil($newLimit); |
755 | - ini_set('memory_limit', $newLimit . 'M'); |
|
755 | + ini_set('memory_limit', $newLimit.'M'); |
|
756 | 756 | |
757 | 757 | return true; |
758 | 758 | } |
@@ -783,16 +783,16 @@ discard block |
||
783 | 783 | */ |
784 | 784 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
785 | 785 | { |
786 | - if($this->isVector()) { |
|
786 | + if ($this->isVector()) { |
|
787 | 787 | return $this; |
788 | 788 | } |
789 | 789 | |
790 | - if($this->newWidth==$newWidth && $this->newHeight==$newHeight) { |
|
790 | + if ($this->newWidth == $newWidth && $this->newHeight == $newHeight) { |
|
791 | 791 | return $this; |
792 | 792 | } |
793 | 793 | |
794 | - if($newWidth < 1) { $newWidth = 1; } |
|
795 | - if($newHeight < 1) { $newHeight = 1; } |
|
794 | + if ($newWidth < 1) { $newWidth = 1; } |
|
795 | + if ($newHeight < 1) { $newHeight = 1; } |
|
796 | 796 | |
797 | 797 | $this->adjustMemory(); |
798 | 798 | |
@@ -860,15 +860,15 @@ discard block |
||
860 | 860 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
861 | 861 | * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
862 | 862 | */ |
863 | - public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
|
863 | + public static function displayImageStream($resource, string $imageType, int $quality = -1) : void |
|
864 | 864 | { |
865 | 865 | self::requireResource($resource); |
866 | 866 | |
867 | 867 | $imageType = self::requireValidStreamType($imageType); |
868 | 868 | |
869 | - header('Content-type:image/' . $imageType); |
|
869 | + header('Content-type:image/'.$imageType); |
|
870 | 870 | |
871 | - $function = 'image' . $imageType; |
|
871 | + $function = 'image'.$imageType; |
|
872 | 872 | |
873 | 873 | $function($resource, null, $quality); |
874 | 874 | } |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | { |
886 | 886 | $imageType = strtolower($imageType); |
887 | 887 | |
888 | - if(in_array($imageType, self::$streamTypes)) |
|
888 | + if (in_array($imageType, self::$streamTypes)) |
|
889 | 889 | { |
890 | 890 | return $imageType; |
891 | 891 | } |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | if (headers_sent($file, $line)) { |
912 | 912 | throw new ImageHelper_Exception( |
913 | 913 | 'Error displaying image', |
914 | - 'Headers have already been sent: in file ' . $file . ':' . $line, |
|
914 | + 'Headers have already been sent: in file '.$file.':'.$line, |
|
915 | 915 | self::ERROR_HEADERS_ALREADY_SENT |
916 | 916 | ); |
917 | 917 | } |
@@ -928,16 +928,16 @@ discard block |
||
928 | 928 | } |
929 | 929 | |
930 | 930 | $format = self::getFileImageType($imageFile); |
931 | - if($format == 'svg') { |
|
931 | + if ($format == 'svg') { |
|
932 | 932 | $format = 'svg+xml'; |
933 | 933 | } |
934 | 934 | |
935 | - $contentType = 'image/' . $format; |
|
935 | + $contentType = 'image/'.$format; |
|
936 | 936 | |
937 | 937 | header('Content-Type: '.$contentType); |
938 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($imageFile)) . " GMT"); |
|
938 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($imageFile))." GMT"); |
|
939 | 939 | header('Cache-Control: public'); |
940 | - header('Content-Length: ' . filesize($imageFile)); |
|
940 | + header('Content-Length: '.filesize($imageFile)); |
|
941 | 941 | |
942 | 942 | readfile($imageFile); |
943 | 943 | } |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
966 | 966 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
967 | 967 | */ |
968 | - public function trim(?array $color=null) : ImageHelper |
|
968 | + public function trim(?array $color = null) : ImageHelper |
|
969 | 969 | { |
970 | 970 | return $this->trimImage($this->newImage, $color); |
971 | 971 | } |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | $color = imagecolorsforindex($img, $colorIndex); |
988 | 988 | |
989 | 989 | // it seems imagecolorsforindex may return false (undocumented, unproven) |
990 | - if(is_array($color)) { |
|
990 | + if (is_array($color)) { |
|
991 | 991 | return $color; |
992 | 992 | } |
993 | 993 | |
@@ -1011,15 +1011,15 @@ discard block |
||
1011 | 1011 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
1012 | 1012 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
1013 | 1013 | */ |
1014 | - protected function trimImage($img, ?array $color=null) : ImageHelper |
|
1014 | + protected function trimImage($img, ?array $color = null) : ImageHelper |
|
1015 | 1015 | { |
1016 | - if($this->isVector()) { |
|
1016 | + if ($this->isVector()) { |
|
1017 | 1017 | return $this; |
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | self::requireResource($img); |
1021 | 1021 | |
1022 | - if(empty($color)) |
|
1022 | + if (empty($color)) |
|
1023 | 1023 | { |
1024 | 1024 | $color = imagecolorat($img, 0, 0); |
1025 | 1025 | $color = $this->getIndexedColors($img, $color); |
@@ -1036,16 +1036,16 @@ discard block |
||
1036 | 1036 | $ymax = null; |
1037 | 1037 | |
1038 | 1038 | // Start scanning for the edges. |
1039 | - for ($iy=0; $iy<$imh; $iy++) |
|
1039 | + for ($iy = 0; $iy < $imh; $iy++) |
|
1040 | 1040 | { |
1041 | 1041 | $first = true; |
1042 | 1042 | |
1043 | - for ($ix=0; $ix<$imw; $ix++) |
|
1043 | + for ($ix = 0; $ix < $imw; $ix++) |
|
1044 | 1044 | { |
1045 | 1045 | $ndx = imagecolorat($img, $ix, $iy); |
1046 | 1046 | $colors = $this->getIndexedColors($img, $ndx); |
1047 | 1047 | |
1048 | - if(!$this->colorsMatch($colors, $color)) |
|
1048 | + if (!$this->colorsMatch($colors, $color)) |
|
1049 | 1049 | { |
1050 | 1050 | if ($xmin > $ix) { $xmin = $ix; } |
1051 | 1051 | if ($xmax < $ix) { $xmax = $ix; } |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | |
1054 | 1054 | $ymax = $iy; |
1055 | 1055 | |
1056 | - if($first) |
|
1056 | + if ($first) |
|
1057 | 1057 | { |
1058 | 1058 | $ix = $xmax; |
1059 | 1059 | $first = false; |
@@ -1063,18 +1063,18 @@ discard block |
||
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | // no trimming border found |
1066 | - if($ymax === null) { |
|
1066 | + if ($ymax === null) { |
|
1067 | 1067 | return $this; |
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | // The new width and height of the image. |
1071 | - $imw = 1+$xmax-$xmin; // Image width in pixels |
|
1072 | - $imh = 1+$ymax-$ymin; // Image height in pixels |
|
1071 | + $imw = 1 + $xmax - $xmin; // Image width in pixels |
|
1072 | + $imh = 1 + $ymax - $ymin; // Image height in pixels |
|
1073 | 1073 | |
1074 | 1074 | // Make another image to place the trimmed version in. |
1075 | 1075 | $im2 = $this->createNewImage($imw, $imh); |
1076 | 1076 | |
1077 | - if($color['alpha'] > 0) |
|
1077 | + if ($color['alpha'] > 0) |
|
1078 | 1078 | { |
1079 | 1079 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
1080 | 1080 | imagecolortransparent($im2, $bg2); |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | |
1114 | 1114 | $this->newImage = $image; |
1115 | 1115 | $this->newWidth = imagesx($image); |
1116 | - $this->newHeight= imagesy($image); |
|
1116 | + $this->newHeight = imagesy($image); |
|
1117 | 1117 | |
1118 | 1118 | return $this; |
1119 | 1119 | } |
@@ -1128,7 +1128,7 @@ discard block |
||
1128 | 1128 | */ |
1129 | 1129 | protected static function requireResource($subject) : void |
1130 | 1130 | { |
1131 | - if(is_resource($subject)) { |
|
1131 | + if (is_resource($subject)) { |
|
1132 | 1132 | return; |
1133 | 1133 | } |
1134 | 1134 | |
@@ -1154,7 +1154,7 @@ discard block |
||
1154 | 1154 | { |
1155 | 1155 | $img = imagecreatetruecolor($width, $height); |
1156 | 1156 | |
1157 | - if($img === false) |
|
1157 | + if ($img === false) |
|
1158 | 1158 | { |
1159 | 1159 | throw new ImageHelper_Exception( |
1160 | 1160 | 'Error creating new image', |
@@ -1178,8 +1178,8 @@ discard block |
||
1178 | 1178 | protected function colorsMatch(array $a, array $b) : bool |
1179 | 1179 | { |
1180 | 1180 | $parts = array('red', 'green', 'blue'); |
1181 | - foreach($parts as $part) { |
|
1182 | - if($a[$part] != $b[$part]) { |
|
1181 | + foreach ($parts as $part) { |
|
1182 | + if ($a[$part] != $b[$part]) { |
|
1183 | 1183 | return false; |
1184 | 1184 | } |
1185 | 1185 | } |
@@ -1187,7 +1187,7 @@ discard block |
||
1187 | 1187 | return true; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - public function fillWhite($x=0, $y=0) |
|
1190 | + public function fillWhite($x = 0, $y = 0) |
|
1191 | 1191 | { |
1192 | 1192 | $this->addRGBColor('white', 255, 255, 255); |
1193 | 1193 | return $this->fill('white', $x, $y); |
@@ -1207,11 +1207,11 @@ discard block |
||
1207 | 1207 | self::requireResource($resource); |
1208 | 1208 | |
1209 | 1209 | $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
1210 | - imagecolortransparent ($resource, $transparent); |
|
1210 | + imagecolortransparent($resource, $transparent); |
|
1211 | 1211 | imagefill($resource, 0, 0, $transparent); |
1212 | 1212 | } |
1213 | 1213 | |
1214 | - public function fill($colorName, $x=0, $y=0) |
|
1214 | + public function fill($colorName, $x = 0, $y = 0) |
|
1215 | 1215 | { |
1216 | 1216 | imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
1217 | 1217 | return $this; |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | return $this; |
1226 | 1226 | } |
1227 | 1227 | |
1228 | - public function textTTF($text, $size, $colorName, $x=0, $y=0, $angle=0) |
|
1228 | + public function textTTF($text, $size, $colorName, $x = 0, $y = 0, $angle = 0) |
|
1229 | 1229 | { |
1230 | 1230 | imagealphablending($this->newImage, true); |
1231 | 1231 | |
@@ -1244,11 +1244,11 @@ discard block |
||
1244 | 1244 | return $this->newImage; |
1245 | 1245 | } |
1246 | 1246 | |
1247 | - public function paste(ImageHelper $target, $xpos=0, $ypos=0, $sourceX=0, $sourceY=0) |
|
1247 | + public function paste(ImageHelper $target, $xpos = 0, $ypos = 0, $sourceX = 0, $sourceY = 0) |
|
1248 | 1248 | { |
1249 | 1249 | $img = $target->getImage(); |
1250 | 1250 | |
1251 | - if($target->isAlpha()) { |
|
1251 | + if ($target->isAlpha()) { |
|
1252 | 1252 | $this->enableAlpha(); |
1253 | 1253 | } |
1254 | 1254 | |
@@ -1293,10 +1293,10 @@ discard block |
||
1293 | 1293 | public function fitText($text, $matchWidth) |
1294 | 1294 | { |
1295 | 1295 | $sizes = array(); |
1296 | - for($i=1; $i<=1000; $i=$i+0.1) { |
|
1296 | + for ($i = 1; $i <= 1000; $i = $i + 0.1) { |
|
1297 | 1297 | $size = $this->calcTextSize($text, $i); |
1298 | 1298 | $sizes[] = $size; |
1299 | - if($size['width'] >= $matchWidth) { |
|
1299 | + if ($size['width'] >= $matchWidth) { |
|
1300 | 1300 | break; |
1301 | 1301 | } |
1302 | 1302 | } |
@@ -1308,7 +1308,7 @@ discard block |
||
1308 | 1308 | $diffLast = $last['width'] - $matchWidth; |
1309 | 1309 | $diffPrev = $matchWidth - $prev['width']; |
1310 | 1310 | |
1311 | - if($diffLast <= $diffPrev) { |
|
1311 | + if ($diffLast <= $diffPrev) { |
|
1312 | 1312 | return $last; |
1313 | 1313 | } |
1314 | 1314 | |
@@ -1336,14 +1336,14 @@ discard block |
||
1336 | 1336 | 'bottom_left_y' => $box[1], |
1337 | 1337 | 'bottom_right_x' => $box[2], |
1338 | 1338 | 'bottom_right_y' => $box[3], |
1339 | - 'width' => $right-$left, |
|
1340 | - 'height' => $bottom-$top |
|
1339 | + 'width' => $right - $left, |
|
1340 | + 'height' => $bottom - $top |
|
1341 | 1341 | ); |
1342 | 1342 | } |
1343 | 1343 | |
1344 | 1344 | protected function requireTTFFont() |
1345 | 1345 | { |
1346 | - if(isset($this->TTFFile)) { |
|
1346 | + if (isset($this->TTFFile)) { |
|
1347 | 1347 | return; |
1348 | 1348 | } |
1349 | 1349 | |
@@ -1378,7 +1378,7 @@ discard block |
||
1378 | 1378 | */ |
1379 | 1379 | public static function getImageSize($pathOrResource) : ImageHelper_Size |
1380 | 1380 | { |
1381 | - if(is_resource($pathOrResource)) |
|
1381 | + if (is_resource($pathOrResource)) |
|
1382 | 1382 | { |
1383 | 1383 | return new ImageHelper_Size(array( |
1384 | 1384 | 'width' => imagesx($pathOrResource), |
@@ -1392,7 +1392,7 @@ discard block |
||
1392 | 1392 | |
1393 | 1393 | $info = false; |
1394 | 1394 | $method = 'getImageSize_'.$type; |
1395 | - if(method_exists(__CLASS__, $method)) |
|
1395 | + if (method_exists(__CLASS__, $method)) |
|
1396 | 1396 | { |
1397 | 1397 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
1398 | 1398 | } |
@@ -1401,7 +1401,7 @@ discard block |
||
1401 | 1401 | $info = getimagesize($pathOrResource); |
1402 | 1402 | } |
1403 | 1403 | |
1404 | - if($info !== false) { |
|
1404 | + if ($info !== false) { |
|
1405 | 1405 | return new ImageHelper_Size($info); |
1406 | 1406 | } |
1407 | 1407 | |
@@ -1427,7 +1427,7 @@ discard block |
||
1427 | 1427 | $xml = XMLHelper::createSimplexml(); |
1428 | 1428 | $xml->loadFile($imagePath); |
1429 | 1429 | |
1430 | - if($xml->hasErrors()) { |
|
1430 | + if ($xml->hasErrors()) { |
|
1431 | 1431 | throw new ImageHelper_Exception( |
1432 | 1432 | 'Error opening SVG image', |
1433 | 1433 | sprintf( |
@@ -1442,7 +1442,7 @@ discard block |
||
1442 | 1442 | $xml->dispose(); |
1443 | 1443 | unset($xml); |
1444 | 1444 | |
1445 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1445 | + if (!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1446 | 1446 | throw new ImageHelper_Exception( |
1447 | 1447 | 'SVG Image is corrupted', |
1448 | 1448 | sprintf( |
@@ -1459,7 +1459,7 @@ discard block |
||
1459 | 1459 | $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
1460 | 1460 | $size = explode(',', $viewBox); |
1461 | 1461 | |
1462 | - if(count($size) != 4) |
|
1462 | + if (count($size) != 4) |
|
1463 | 1463 | { |
1464 | 1464 | throw new ImageHelper_Exception( |
1465 | 1465 | 'SVG image has an invalid viewBox attribute', |
@@ -1505,7 +1505,7 @@ discard block |
||
1505 | 1505 | * @param integer $y |
1506 | 1506 | * @return ImageHelper |
1507 | 1507 | */ |
1508 | - public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
|
1508 | + public function crop(int $width, int $height, int $x = 0, int $y = 0) : ImageHelper |
|
1509 | 1509 | { |
1510 | 1510 | $new = $this->createNewImage($width, $height); |
1511 | 1511 | |
@@ -1542,7 +1542,7 @@ discard block |
||
1542 | 1542 | * @see ImageHelper::calcAverageColorRGB() |
1543 | 1543 | * @see ImageHelper::calcAverageColorHEX() |
1544 | 1544 | */ |
1545 | - public function calcAverageColor(int $format=self::COLORFORMAT_RGB) |
|
1545 | + public function calcAverageColor(int $format = self::COLORFORMAT_RGB) |
|
1546 | 1546 | { |
1547 | 1547 | $image = $this->duplicate(); |
1548 | 1548 | $image->resample(1, 1); |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | public function calcAverageColorRGB() : array |
1562 | 1562 | { |
1563 | 1563 | $result = $this->calcAverageColor(self::COLORFORMAT_RGB); |
1564 | - if(is_array($result)) { |
|
1564 | + if (is_array($result)) { |
|
1565 | 1565 | return $result; |
1566 | 1566 | } |
1567 | 1567 | |
@@ -1582,7 +1582,7 @@ discard block |
||
1582 | 1582 | public function calcAverageColorHex() : string |
1583 | 1583 | { |
1584 | 1584 | $result = $this->calcAverageColor(self::COLORFORMAT_HEX); |
1585 | - if(is_string($result)) { |
|
1585 | + if (is_string($result)) { |
|
1586 | 1586 | return $result; |
1587 | 1587 | } |
1588 | 1588 | |
@@ -1618,9 +1618,9 @@ discard block |
||
1618 | 1618 | * @throws ImageHelper_Exception |
1619 | 1619 | * @see ImageHelper::ERROR_POSITION_OUT_OF_BOUNDS |
1620 | 1620 | */ |
1621 | - public function getColorAt(int $x, int $y, int $format=self::COLORFORMAT_RGB) |
|
1621 | + public function getColorAt(int $x, int $y, int $format = self::COLORFORMAT_RGB) |
|
1622 | 1622 | { |
1623 | - if($x > $this->getWidth() || $y > $this->getHeight()) |
|
1623 | + if ($x > $this->getWidth() || $y > $this->getHeight()) |
|
1624 | 1624 | { |
1625 | 1625 | throw new ImageHelper_Exception( |
1626 | 1626 | 'Position out of bounds', |
@@ -1638,7 +1638,7 @@ discard block |
||
1638 | 1638 | $idx = imagecolorat($this->newImage, $x, $y); |
1639 | 1639 | $rgb = $this->getIndexedColors($this->newImage, $idx); |
1640 | 1640 | |
1641 | - if($format == self::COLORFORMAT_HEX) { |
|
1641 | + if ($format == self::COLORFORMAT_HEX) { |
|
1642 | 1642 | return self::rgb2hex($rgb); |
1643 | 1643 | } |
1644 | 1644 | |
@@ -1653,7 +1653,7 @@ discard block |
||
1653 | 1653 | */ |
1654 | 1654 | public static function rgb2luma(array $rgb) : int |
1655 | 1655 | { |
1656 | - return (int)floor((($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6); |
|
1656 | + return (int)floor((($rgb['red'] * 2) + $rgb['blue'] + ($rgb['green'] * 3)) / 6); |
|
1657 | 1657 | } |
1658 | 1658 | |
1659 | 1659 | /** |
@@ -1681,7 +1681,7 @@ discard block |
||
1681 | 1681 | */ |
1682 | 1682 | public function getHash() : string |
1683 | 1683 | { |
1684 | - if($this->newImage === null) |
|
1684 | + if ($this->newImage === null) |
|
1685 | 1685 | { |
1686 | 1686 | throw new ImageHelper_Exception( |
1687 | 1687 | 'No image loaded to create a hash for.', |
@@ -63,7 +63,7 @@ |
||
63 | 63 | return $this->getBoolOption('cut'); |
64 | 64 | } |
65 | 65 | |
66 | - public function setCuttingEnabled(bool $enabled=true) : ConvertHelper_WordWrapper |
|
66 | + public function setCuttingEnabled(bool $enabled = true) : ConvertHelper_WordWrapper |
|
67 | 67 | { |
68 | 68 | $this->setOption('cut', $enabled); |
69 | 69 | return $this; |
@@ -92,8 +92,7 @@ |
||
92 | 92 | if (mb_strlen($actual.$word) <= $width) |
93 | 93 | { |
94 | 94 | $actual .= $word.' '; |
95 | - } |
|
96 | - else |
|
95 | + } else |
|
97 | 96 | { |
98 | 97 | if ($actual != '') { |
99 | 98 | $line .= rtrim($actual).$break; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function __construct() |
38 | 38 | { |
39 | - if(class_exists('\AppLocalize\Localization')) { |
|
39 | + if (class_exists('\AppLocalize\Localization')) { |
|
40 | 40 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
41 | 41 | } |
42 | 42 | } |
@@ -69,17 +69,17 @@ discard block |
||
69 | 69 | $keep = $this->resolveTokens($interval); |
70 | 70 | |
71 | 71 | $parts = array(); |
72 | - foreach($keep as $token) |
|
72 | + foreach ($keep as $token) |
|
73 | 73 | { |
74 | 74 | $value = $interval->getToken($token); |
75 | - if($value === 0) { |
|
75 | + if ($value === 0) { |
|
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | |
79 | 79 | $parts[] = $this->translateToken($token, $interval); |
80 | 80 | } |
81 | 81 | |
82 | - if(count($parts) == 1) { |
|
82 | + if (count($parts) == 1) { |
|
83 | 83 | return $parts[0]; |
84 | 84 | } |
85 | 85 | |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | $value = $interval->getToken($token); |
102 | 102 | |
103 | 103 | $suffix = 'p'; |
104 | - if($value == 1) { $suffix = 's'; } |
|
104 | + if ($value == 1) { $suffix = 's'; } |
|
105 | 105 | $token .= $suffix; |
106 | 106 | |
107 | - if(!isset(self::$texts[$token])) |
|
107 | + if (!isset(self::$texts[$token])) |
|
108 | 108 | { |
109 | 109 | throw new ConvertHelper_Exception( |
110 | 110 | 'Missing interval translation', |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | { |
135 | 135 | $offset = 0; |
136 | 136 | |
137 | - foreach($this->tokens as $token) |
|
137 | + foreach ($this->tokens as $token) |
|
138 | 138 | { |
139 | - if($interval->getToken($token) > 0) |
|
139 | + if ($interval->getToken($token) > 0) |
|
140 | 140 | { |
141 | 141 | return array_slice($this->tokens, $offset); |
142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function initTexts() : void |
154 | 154 | { |
155 | - if(isset(self::$texts)) { |
|
155 | + if (isset(self::$texts)) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 |
@@ -17,21 +17,20 @@ discard block |
||
17 | 17 | * @package Application Utils |
18 | 18 | * @subpackage ConvertHelper |
19 | 19 | * @author Sebastian Mordziol <[email protected]> |
20 | - |
|
21 | 20 | * @see ConvertHelper::interval2string() |
22 | 21 | */ |
23 | 22 | class ConvertHelper_IntervalConverter |
24 | 23 | { |
25 | 24 | const ERROR_MISSING_TRANSLATION = 43501; |
26 | 25 | |
27 | - /** |
|
28 | - * @var array|NULL |
|
29 | - */ |
|
26 | + /** |
|
27 | + * @var array|NULL |
|
28 | + */ |
|
30 | 29 | protected static $texts = null; |
31 | 30 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
35 | 34 | protected $tokens = array('y', 'm', 'd', 'h', 'i', 's'); |
36 | 35 | |
37 | 36 | public function __construct() |
@@ -41,25 +40,25 @@ discard block |
||
41 | 40 | } |
42 | 41 | } |
43 | 42 | |
44 | - /** |
|
45 | - * Called whenever the application locale has changed, |
|
46 | - * to reset the internal translation cache. |
|
47 | - */ |
|
43 | + /** |
|
44 | + * Called whenever the application locale has changed, |
|
45 | + * to reset the internal translation cache. |
|
46 | + */ |
|
48 | 47 | public function handle_localeChanged() |
49 | 48 | { |
50 | 49 | self::$texts = null; |
51 | 50 | } |
52 | 51 | |
53 | - /** |
|
54 | - * Converts the specified interval to a human readable |
|
55 | - * string, e.g. "2 hours and 4 minutes". |
|
56 | - * |
|
57 | - * @param \DateInterval $interval |
|
58 | - * @return string |
|
59 | - * @throws ConvertHelper_Exception |
|
60 | - * |
|
61 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
62 | - */ |
|
52 | + /** |
|
53 | + * Converts the specified interval to a human readable |
|
54 | + * string, e.g. "2 hours and 4 minutes". |
|
55 | + * |
|
56 | + * @param \DateInterval $interval |
|
57 | + * @return string |
|
58 | + * @throws ConvertHelper_Exception |
|
59 | + * |
|
60 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
61 | + */ |
|
63 | 62 | public function toString(\DateInterval $interval) : string |
64 | 63 | { |
65 | 64 | $this->initTexts(); |
@@ -88,14 +87,14 @@ discard block |
||
88 | 87 | return t('%1$s and %2$s', implode(', ', $parts), $last); |
89 | 88 | } |
90 | 89 | |
91 | - /** |
|
92 | - * Translates the selected time token, e.g. "y" (for year). |
|
93 | - * |
|
94 | - * @param string $token |
|
95 | - * @param ConvertHelper_DateInterval $interval |
|
96 | - * @throws ConvertHelper_Exception |
|
97 | - * @return string |
|
98 | - */ |
|
90 | + /** |
|
91 | + * Translates the selected time token, e.g. "y" (for year). |
|
92 | + * |
|
93 | + * @param string $token |
|
94 | + * @param ConvertHelper_DateInterval $interval |
|
95 | + * @throws ConvertHelper_Exception |
|
96 | + * @return string |
|
97 | + */ |
|
99 | 98 | protected function translateToken(string $token, ConvertHelper_DateInterval $interval) : string |
100 | 99 | { |
101 | 100 | $value = $interval->getToken($token); |
@@ -123,13 +122,13 @@ discard block |
||
123 | 122 | ); |
124 | 123 | } |
125 | 124 | |
126 | - /** |
|
127 | - * Resolves all time tokens that need to be translated in |
|
128 | - * the subject interval, depending on its length. |
|
129 | - * |
|
130 | - * @param ConvertHelper_DateInterval $interval |
|
131 | - * @return array |
|
132 | - */ |
|
125 | + /** |
|
126 | + * Resolves all time tokens that need to be translated in |
|
127 | + * the subject interval, depending on its length. |
|
128 | + * |
|
129 | + * @param ConvertHelper_DateInterval $interval |
|
130 | + * @return array |
|
131 | + */ |
|
133 | 132 | protected function resolveTokens(ConvertHelper_DateInterval $interval) : array |
134 | 133 | { |
135 | 134 | $offset = 0; |
@@ -147,9 +146,9 @@ discard block |
||
147 | 146 | return array(); |
148 | 147 | } |
149 | 148 | |
150 | - /** |
|
151 | - * Initializes the translateable strings. |
|
152 | - */ |
|
149 | + /** |
|
150 | + * Initializes the translateable strings. |
|
151 | + */ |
|
153 | 152 | protected function initTexts() : void |
154 | 153 | { |
155 | 154 | if(isset(self::$texts)) { |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | 'WriteThreshold' => 100 |
37 | 37 | ); |
38 | 38 | |
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | 42 | protected $file; |
43 | 43 | |
44 | - /** |
|
45 | - * @var \ZipArchive |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var \ZipArchive |
|
46 | + */ |
|
47 | 47 | protected $zip; |
48 | 48 | |
49 | 49 | public function __construct(string $targetFile) |
@@ -51,35 +51,35 @@ discard block |
||
51 | 51 | $this->file = $targetFile; |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Sets an option, among the available options: |
|
56 | - * |
|
57 | - * <ul> |
|
58 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
59 | - * </ul> |
|
60 | - * |
|
61 | - * @param string $name |
|
62 | - * @param mixed $value |
|
63 | - * @return ZIPHelper |
|
64 | - */ |
|
54 | + /** |
|
55 | + * Sets an option, among the available options: |
|
56 | + * |
|
57 | + * <ul> |
|
58 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
59 | + * </ul> |
|
60 | + * |
|
61 | + * @param string $name |
|
62 | + * @param mixed $value |
|
63 | + * @return ZIPHelper |
|
64 | + */ |
|
65 | 65 | public function setOption(string $name, $value) : ZIPHelper |
66 | 66 | { |
67 | 67 | $this->options[$name] = $value; |
68 | 68 | return $this; |
69 | 69 | } |
70 | 70 | |
71 | - /** |
|
72 | - * Adds a file to the zip. By default, the file is stored |
|
73 | - * with the same name in the root of the zip. Use the optional |
|
74 | - * parameter to change the location in the zip. |
|
75 | - * |
|
76 | - * @param string $filePath |
|
77 | - * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
78 | - * @throws ZIPHelper_Exception |
|
79 | - * @return bool |
|
80 | - * |
|
81 | - * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
82 | - */ |
|
71 | + /** |
|
72 | + * Adds a file to the zip. By default, the file is stored |
|
73 | + * with the same name in the root of the zip. Use the optional |
|
74 | + * parameter to change the location in the zip. |
|
75 | + * |
|
76 | + * @param string $filePath |
|
77 | + * @param string|null $zipPath If no path is specified, file will be added with the same name in the ZIP's root. |
|
78 | + * @throws ZIPHelper_Exception |
|
79 | + * @return bool |
|
80 | + * |
|
81 | + * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
|
82 | + */ |
|
83 | 83 | public function addFile(string $filePath, ?string $zipPath=null) : bool |
84 | 84 | { |
85 | 85 | $this->open(); |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | return $fileName; |
256 | 256 | } |
257 | 257 | |
258 | - /** |
|
259 | - * Like {@link ZIPHelper::download()}, but deletes the |
|
260 | - * file after sending it to the browser. |
|
261 | - * |
|
262 | - * @param string|NULL $fileName Override the ZIP's file name for the download |
|
263 | - * @see ZIPHelper::download() |
|
264 | - */ |
|
258 | + /** |
|
259 | + * Like {@link ZIPHelper::download()}, but deletes the |
|
260 | + * file after sending it to the browser. |
|
261 | + * |
|
262 | + * @param string|NULL $fileName Override the ZIP's file name for the download |
|
263 | + * @see ZIPHelper::download() |
|
264 | + */ |
|
265 | 265 | public function downloadAndDelete(?string $fileName=null) |
266 | 266 | { |
267 | 267 | $this->download($fileName); |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | FileHelper::deleteFile($this->file); |
270 | 270 | } |
271 | 271 | |
272 | - /** |
|
273 | - * Extracts all files and folders from the zip to the |
|
274 | - * target folder. If no folder is specified, the files |
|
275 | - * are extracted into the same folder as the zip itself. |
|
276 | - * |
|
277 | - * @param string|NULL $outputFolder If no folder is specified, uses the target file's folder. |
|
278 | - * @return boolean |
|
279 | - */ |
|
272 | + /** |
|
273 | + * Extracts all files and folders from the zip to the |
|
274 | + * target folder. If no folder is specified, the files |
|
275 | + * are extracted into the same folder as the zip itself. |
|
276 | + * |
|
277 | + * @param string|NULL $outputFolder If no folder is specified, uses the target file's folder. |
|
278 | + * @return boolean |
|
279 | + */ |
|
280 | 280 | public function extractAll(?string $outputFolder=null) : bool |
281 | 281 | { |
282 | 282 | if(empty($outputFolder)) { |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | |
292 | - /** |
|
293 | - * @return \ZipArchive |
|
294 | - */ |
|
292 | + /** |
|
293 | + * @return \ZipArchive |
|
294 | + */ |
|
295 | 295 | public function getArchive() : \ZipArchive |
296 | 296 | { |
297 | 297 | $this->open(); |
@@ -299,14 +299,14 @@ discard block |
||
299 | 299 | return $this->zip; |
300 | 300 | } |
301 | 301 | |
302 | - /** |
|
303 | - * JSON encodes the specified data and adds the json as |
|
304 | - * a file in the ZIP archive. |
|
305 | - * |
|
306 | - * @param mixed $data |
|
307 | - * @param string $zipPath |
|
308 | - * @return boolean |
|
309 | - */ |
|
302 | + /** |
|
303 | + * JSON encodes the specified data and adds the json as |
|
304 | + * a file in the ZIP archive. |
|
305 | + * |
|
306 | + * @param mixed $data |
|
307 | + * @param string $zipPath |
|
308 | + * @return boolean |
|
309 | + */ |
|
310 | 310 | public function addJSON($data, $zipPath) |
311 | 311 | { |
312 | 312 | return $this->addString( |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | const ERROR_OPENING_ZIP_FILE = 338003; |
32 | 32 | |
33 | - const ERROR_CANNOT_SAVE_FILE_TO_DISK =338004; |
|
33 | + const ERROR_CANNOT_SAVE_FILE_TO_DISK = 338004; |
|
34 | 34 | |
35 | 35 | protected $options = array( |
36 | 36 | 'WriteThreshold' => 100 |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @see FileHelper::ERROR_SOURCE_FILE_DOES_NOT_EXIST |
82 | 82 | */ |
83 | - public function addFile(string $filePath, ?string $zipPath=null) : bool |
|
83 | + public function addFile(string $filePath, ?string $zipPath = null) : bool |
|
84 | 84 | { |
85 | 85 | $this->open(); |
86 | 86 | |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | |
127 | 127 | protected function open() |
128 | 128 | { |
129 | - if($this->open) { |
|
129 | + if ($this->open) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if(!isset($this->zip)) { |
|
133 | + if (!isset($this->zip)) { |
|
134 | 134 | $this->zip = new \ZipArchive(); |
135 | 135 | } |
136 | 136 | |
137 | 137 | $flag = null; |
138 | - if(!file_exists($this->file)) { |
|
138 | + if (!file_exists($this->file)) { |
|
139 | 139 | $flag = \ZipArchive::CREATE; |
140 | 140 | } |
141 | 141 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | { |
176 | 176 | $this->fileTracker++; |
177 | 177 | |
178 | - if($this->options['WriteThreshold'] < 1) { |
|
178 | + if ($this->options['WriteThreshold'] < 1) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | protected function close() |
190 | 190 | { |
191 | - if(!$this->open) { |
|
191 | + if (!$this->open) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | throw new ZIPHelper_Exception( |
198 | 198 | 'Could not save ZIP file to disk', |
199 | 199 | sprintf( |
200 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
201 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
200 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
201 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
202 | 202 | 'or trying to save to a directory that does not exist.', |
203 | 203 | $this->file |
204 | 204 | ), |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | { |
214 | 214 | $this->open(); |
215 | 215 | |
216 | - if($this->countFiles() < 1) |
|
216 | + if ($this->countFiles() < 1) |
|
217 | 217 | { |
218 | 218 | throw new ZIPHelper_Exception( |
219 | 219 | 'No files in the zip file', |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | * @throws ZIPHelper_Exception |
238 | 238 | * @return string The file name that was sent (useful in case none was specified). |
239 | 239 | */ |
240 | - public function download(?string $fileName=null) : string |
|
240 | + public function download(?string $fileName = null) : string |
|
241 | 241 | { |
242 | 242 | $this->save(); |
243 | 243 | |
244 | - if(empty($fileName)) { |
|
244 | + if (empty($fileName)) { |
|
245 | 245 | $fileName = basename($this->file); |
246 | 246 | } |
247 | 247 | |
248 | 248 | header('Content-type: application/zip'); |
249 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
250 | - header('Content-length: ' . filesize($this->file)); |
|
249 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
250 | + header('Content-length: '.filesize($this->file)); |
|
251 | 251 | header('Pragma: no-cache'); |
252 | 252 | header('Expires: 0'); |
253 | 253 | readfile($this->file); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param string|NULL $fileName Override the ZIP's file name for the download |
263 | 263 | * @see ZIPHelper::download() |
264 | 264 | */ |
265 | - public function downloadAndDelete(?string $fileName=null) |
|
265 | + public function downloadAndDelete(?string $fileName = null) |
|
266 | 266 | { |
267 | 267 | $this->download($fileName); |
268 | 268 | |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * @param string|NULL $outputFolder If no folder is specified, uses the target file's folder. |
278 | 278 | * @return boolean |
279 | 279 | */ |
280 | - public function extractAll(?string $outputFolder=null) : bool |
|
280 | + public function extractAll(?string $outputFolder = null) : bool |
|
281 | 281 | { |
282 | - if(empty($outputFolder)) { |
|
282 | + if (empty($outputFolder)) { |
|
283 | 283 | $outputFolder = dirname($this->file); |
284 | 284 | } |
285 | 285 |
@@ -4,37 +4,37 @@ discard block |
||
4 | 4 | |
5 | 5 | class SVNHelper_CommandResult |
6 | 6 | { |
7 | - /** |
|
8 | - * @var SVNHelper_Command |
|
9 | - */ |
|
7 | + /** |
|
8 | + * @var SVNHelper_Command |
|
9 | + */ |
|
10 | 10 | protected $command; |
11 | 11 | |
12 | - /** |
|
13 | - * @var string[] |
|
14 | - */ |
|
12 | + /** |
|
13 | + * @var string[] |
|
14 | + */ |
|
15 | 15 | protected $output; |
16 | 16 | |
17 | - /** |
|
18 | - * @var SVNHelper_CommandError[] |
|
19 | - */ |
|
17 | + /** |
|
18 | + * @var SVNHelper_CommandError[] |
|
19 | + */ |
|
20 | 20 | protected $errors = array(); |
21 | 21 | |
22 | - /** |
|
23 | - * @var SVNHelper_CommandError[] |
|
24 | - */ |
|
22 | + /** |
|
23 | + * @var SVNHelper_CommandError[] |
|
24 | + */ |
|
25 | 25 | protected $warnings = array(); |
26 | 26 | |
27 | - /** |
|
28 | - * The actual command that has been executed |
|
29 | - * @var string |
|
30 | - */ |
|
27 | + /** |
|
28 | + * The actual command that has been executed |
|
29 | + * @var string |
|
30 | + */ |
|
31 | 31 | protected $commandLine; |
32 | 32 | |
33 | - /** |
|
34 | - * @param SVNHelper_Command $command |
|
35 | - * @param string[] $output |
|
36 | - * @param SVNHelper_CommandError[] $errors |
|
37 | - */ |
|
33 | + /** |
|
34 | + * @param SVNHelper_Command $command |
|
35 | + * @param string[] $output |
|
36 | + * @param SVNHelper_CommandError[] $errors |
|
37 | + */ |
|
38 | 38 | public function __construct(SVNHelper_Command $command, $commandLine, $output, $errors) |
39 | 39 | { |
40 | 40 | $this->command = $command; |
@@ -86,12 +86,12 @@ discard block |
||
86 | 86 | return $this->command; |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * Retrieves all error messages. |
|
91 | - * |
|
92 | - * @param bool $asString |
|
93 | - * @return string|string[] |
|
94 | - */ |
|
89 | + /** |
|
90 | + * Retrieves all error messages. |
|
91 | + * |
|
92 | + * @param bool $asString |
|
93 | + * @return string|string[] |
|
94 | + */ |
|
95 | 95 | public function getErrorMessages(bool $asString=false) |
96 | 96 | { |
97 | 97 | if($asString) { |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | $this->commandLine = $commandLine; |
42 | 42 | $this->output = $output; |
43 | 43 | |
44 | - foreach($errors as $error) { |
|
45 | - if($error->isError()) { |
|
44 | + foreach ($errors as $error) { |
|
45 | + if ($error->isError()) { |
|
46 | 46 | $this->errors[] = $error; |
47 | 47 | } else { |
48 | 48 | $this->warnings[] = $error; |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | |
63 | 63 | public function hasErrorCode($code) |
64 | 64 | { |
65 | - foreach($this->errors as $error) { |
|
66 | - if($error->getCode() == $code) { |
|
65 | + foreach ($this->errors as $error) { |
|
66 | + if ($error->getCode() == $code) { |
|
67 | 67 | return true; |
68 | 68 | } |
69 | 69 | } |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | * @param bool $asString |
93 | 93 | * @return string|string[] |
94 | 94 | */ |
95 | - public function getErrorMessages(bool $asString=false) |
|
95 | + public function getErrorMessages(bool $asString = false) |
|
96 | 96 | { |
97 | - if($asString) { |
|
97 | + if ($asString) { |
|
98 | 98 | $lines = array(); |
99 | - foreach($this->errors as $error) { |
|
99 | + foreach ($this->errors as $error) { |
|
100 | 100 | $lines[] = (string)$error; |
101 | 101 | } |
102 | 102 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | $messages = array(); |
107 | - foreach($this->errors as $error) { |
|
107 | + foreach ($this->errors as $error) { |
|
108 | 108 | $messages[] = (string)$error; |
109 | 109 | } |
110 | 110 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | |
124 | 124 | public function getLastLine() |
125 | 125 | { |
126 | - return $this->output[count($this->output)-1]; |
|
126 | + return $this->output[count($this->output) - 1]; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | public function getFirstLine() |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | |
139 | 139 | public function isConnectionFailed() |
140 | 140 | { |
141 | - foreach($this->errors as $error) { |
|
142 | - if($error->isConnectionFailed()) { |
|
141 | + foreach ($this->errors as $error) { |
|
142 | + if ($error->isConnectionFailed()) { |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | |
150 | 150 | public function hasConflicts() |
151 | 151 | { |
152 | - foreach($this->errors as $error) { |
|
153 | - if($error->isConflict()) { |
|
152 | + foreach ($this->errors as $error) { |
|
153 | + if ($error->isConflict()) { |
|
154 | 154 | return true; |
155 | 155 | } |
156 | 156 | } |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | |
161 | 161 | public function hasLocks() |
162 | 162 | { |
163 | - foreach($this->errors as $error) { |
|
164 | - if($error->isLock()) { |
|
163 | + foreach ($this->errors as $error) { |
|
164 | + if ($error->isLock()) { |
|
165 | 165 | return true; |
166 | 166 | } |
167 | 167 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * The converted string will be all lowercase. |
61 | 61 | * @return Transliteration |
62 | 62 | */ |
63 | - public function setLowercase(bool $lowercase=true) : Transliteration |
|
63 | + public function setLowercase(bool $lowercase = true) : Transliteration |
|
64 | 64 | { |
65 | 65 | $this->setOption('lowercase', $lowercase); |
66 | 66 | |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | |
98 | 98 | $result = implode('', $keep); |
99 | 99 | |
100 | - while (strstr($result, $space . $space)) { |
|
101 | - $result = str_replace($space . $space, $space, $result); |
|
100 | + while (strstr($result, $space.$space)) { |
|
101 | + $result = str_replace($space.$space, $space, $result); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $result = trim($result, $space); |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class ConvertHelper_ByteConverter |
25 | 25 | { |
26 | - /** |
|
27 | - * @var int |
|
28 | - */ |
|
26 | + /** |
|
27 | + * @var int |
|
28 | + */ |
|
29 | 29 | protected $bytes; |
30 | 30 | |
31 | 31 | public function __construct(int $bytes) |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | - /** |
|
43 | - * Detects the size matching the byte value for the specified base. |
|
44 | - * |
|
45 | - * @param int $base |
|
46 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
47 | - */ |
|
42 | + /** |
|
43 | + * Detects the size matching the byte value for the specified base. |
|
44 | + * |
|
45 | + * @param int $base |
|
46 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
47 | + */ |
|
48 | 48 | protected function detectSize(int $base) : ConvertHelper_StorageSizeEnum_Size |
49 | 49 | { |
50 | 50 | $sizes = $this->getSizesSorted($base); |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | return ConvertHelper_StorageSizeEnum::getSizeByName('b'); |
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * Retrieves all storage sizes for the specified base, |
|
75 | - * sorted from smallest byte size to highest. |
|
76 | - * |
|
77 | - * @param int $base |
|
78 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
79 | - */ |
|
73 | + /** |
|
74 | + * Retrieves all storage sizes for the specified base, |
|
75 | + * sorted from smallest byte size to highest. |
|
76 | + * |
|
77 | + * @param int $base |
|
78 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
79 | + */ |
|
80 | 80 | protected function getSizesSorted(int $base) |
81 | 81 | { |
82 | 82 | $sizes = ConvertHelper_StorageSizeEnum::getSizesByBase($base); |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | return $sizes; |
90 | 90 | } |
91 | 91 | |
92 | - /** |
|
93 | - * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
94 | - * |
|
95 | - * @param int $precision The amount of decimals (rounded up) |
|
96 | - * @param int $base The base to calculate bytes with. |
|
97 | - * @return string |
|
98 | - * |
|
99 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
100 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
101 | - */ |
|
92 | + /** |
|
93 | + * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
94 | + * |
|
95 | + * @param int $precision The amount of decimals (rounded up) |
|
96 | + * @param int $base The base to calculate bytes with. |
|
97 | + * @return string |
|
98 | + * |
|
99 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
100 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
101 | + */ |
|
102 | 102 | public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
103 | 103 | { |
104 | 104 | $size = $this->detectSize($base); |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
111 | - * |
|
112 | - * @param int $precision The amount of decimals (rounded up) |
|
113 | - * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
114 | - * @return float |
|
115 | - */ |
|
109 | + /** |
|
110 | + * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
111 | + * |
|
112 | + * @param int $precision The amount of decimals (rounded up) |
|
113 | + * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
114 | + * @return float |
|
115 | + */ |
|
116 | 116 | public function toNumber(int $precision, string $sizeName) : float |
117 | 117 | { |
118 | 118 | $size = ConvertHelper_StorageSizeEnum::getSizeByName($sizeName); |
@@ -120,56 +120,56 @@ discard block |
||
120 | 120 | return round($this->bytes / $size->getBytes(), $precision); |
121 | 121 | } |
122 | 122 | |
123 | - /** |
|
124 | - * Converts the bytes to Kilobytes. |
|
125 | - * |
|
126 | - * @param int $precision Amount of decimals (rounded up) |
|
127 | - * @return float |
|
128 | - */ |
|
123 | + /** |
|
124 | + * Converts the bytes to Kilobytes. |
|
125 | + * |
|
126 | + * @param int $precision Amount of decimals (rounded up) |
|
127 | + * @return float |
|
128 | + */ |
|
129 | 129 | public function toKilobytes(int $precision=1) : float |
130 | 130 | { |
131 | 131 | return $this->toNumber($precision, 'kb'); |
132 | 132 | } |
133 | 133 | |
134 | - /** |
|
135 | - * Converts the bytes to Megabytes. |
|
136 | - * |
|
137 | - * @param int $precision Amount of decimals (rounded up) |
|
138 | - * @return float |
|
139 | - */ |
|
134 | + /** |
|
135 | + * Converts the bytes to Megabytes. |
|
136 | + * |
|
137 | + * @param int $precision Amount of decimals (rounded up) |
|
138 | + * @return float |
|
139 | + */ |
|
140 | 140 | public function toMegabytes(int $precision=1) : float |
141 | 141 | { |
142 | 142 | return $this->toNumber($precision, 'mb'); |
143 | 143 | } |
144 | 144 | |
145 | - /** |
|
146 | - * Converts the bytes to Gigabytes. |
|
147 | - * |
|
148 | - * @param int $precision Amount of decimals (rounded up) |
|
149 | - * @return float |
|
150 | - */ |
|
145 | + /** |
|
146 | + * Converts the bytes to Gigabytes. |
|
147 | + * |
|
148 | + * @param int $precision Amount of decimals (rounded up) |
|
149 | + * @return float |
|
150 | + */ |
|
151 | 151 | public function toGigabytes(int $precision=1) : float |
152 | 152 | { |
153 | 153 | return $this->toNumber($precision, 'gb'); |
154 | 154 | } |
155 | 155 | |
156 | - /** |
|
157 | - * Converts the bytes to Terabytes. |
|
158 | - * |
|
159 | - * @param int $precision Amount of decimals (rounded up) |
|
160 | - * @return float |
|
161 | - */ |
|
156 | + /** |
|
157 | + * Converts the bytes to Terabytes. |
|
158 | + * |
|
159 | + * @param int $precision Amount of decimals (rounded up) |
|
160 | + * @return float |
|
161 | + */ |
|
162 | 162 | public function toTerabytes(int $precision=1) : float |
163 | 163 | { |
164 | 164 | return $this->toNumber($precision, 'tb'); |
165 | 165 | } |
166 | 166 | |
167 | - /** |
|
168 | - * Converts the bytes to Petabytes. |
|
169 | - * |
|
170 | - * @param int $precision Amount of decimals (rounded up) |
|
171 | - * @return float |
|
172 | - */ |
|
167 | + /** |
|
168 | + * Converts the bytes to Petabytes. |
|
169 | + * |
|
170 | + * @param int $precision Amount of decimals (rounded up) |
|
171 | + * @return float |
|
172 | + */ |
|
173 | 173 | public function toPetabytes(int $precision=1) : float |
174 | 174 | { |
175 | 175 | return $this->toNumber($precision, 'pb'); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->bytes = $bytes; |
34 | 34 | |
35 | 35 | // correct negative values |
36 | - if($this->bytes < 0) |
|
36 | + if ($this->bytes < 0) |
|
37 | 37 | { |
38 | 38 | $this->bytes = 0; |
39 | 39 | } |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | { |
50 | 50 | $sizes = $this->getSizesSorted($base); |
51 | 51 | |
52 | - if($this->bytes >= $sizes[0]->getBytes()) |
|
52 | + if ($this->bytes >= $sizes[0]->getBytes()) |
|
53 | 53 | { |
54 | 54 | $total = count($sizes); |
55 | 55 | |
56 | - for($i=0; $i < $total; $i++) |
|
56 | + for ($i = 0; $i < $total; $i++) |
|
57 | 57 | { |
58 | 58 | $size = $sizes[$i]; |
59 | 59 | |
60 | - if(!isset($sizes[($i+1)])) { |
|
60 | + if (!isset($sizes[($i + 1)])) { |
|
61 | 61 | return $size; |
62 | 62 | } |
63 | 63 | |
64 | - if($this->bytes >= $size->getBytes() && $this->bytes < $sizes[($i+1)]->getBytes()) { |
|
64 | + if ($this->bytes >= $size->getBytes() && $this->bytes < $sizes[($i + 1)]->getBytes()) { |
|
65 | 65 | return $size; |
66 | 66 | } |
67 | 67 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | * @see ConvertHelper_StorageSizeEnum::BASE_10 |
100 | 100 | * @see ConvertHelper_StorageSizeEnum::BASE_2 |
101 | 101 | */ |
102 | - public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
|
102 | + public function toString(int $precision, int $base = ConvertHelper_StorageSizeEnum::BASE_10) : string |
|
103 | 103 | { |
104 | 104 | $size = $this->detectSize($base); |
105 | 105 | |
106 | - return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
|
106 | + return round($this->bytes / $size->getBytes(), $precision).' '.$size->getSuffix(); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param int $precision Amount of decimals (rounded up) |
127 | 127 | * @return float |
128 | 128 | */ |
129 | - public function toKilobytes(int $precision=1) : float |
|
129 | + public function toKilobytes(int $precision = 1) : float |
|
130 | 130 | { |
131 | 131 | return $this->toNumber($precision, 'kb'); |
132 | 132 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param int $precision Amount of decimals (rounded up) |
138 | 138 | * @return float |
139 | 139 | */ |
140 | - public function toMegabytes(int $precision=1) : float |
|
140 | + public function toMegabytes(int $precision = 1) : float |
|
141 | 141 | { |
142 | 142 | return $this->toNumber($precision, 'mb'); |
143 | 143 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param int $precision Amount of decimals (rounded up) |
149 | 149 | * @return float |
150 | 150 | */ |
151 | - public function toGigabytes(int $precision=1) : float |
|
151 | + public function toGigabytes(int $precision = 1) : float |
|
152 | 152 | { |
153 | 153 | return $this->toNumber($precision, 'gb'); |
154 | 154 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param int $precision Amount of decimals (rounded up) |
160 | 160 | * @return float |
161 | 161 | */ |
162 | - public function toTerabytes(int $precision=1) : float |
|
162 | + public function toTerabytes(int $precision = 1) : float |
|
163 | 163 | { |
164 | 164 | return $this->toNumber($precision, 'tb'); |
165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param int $precision Amount of decimals (rounded up) |
171 | 171 | * @return float |
172 | 172 | */ |
173 | - public function toPetabytes(int $precision=1) : float |
|
173 | + public function toPetabytes(int $precision = 1) : float |
|
174 | 174 | { |
175 | 175 | return $this->toNumber($precision, 'pb'); |
176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param int $precision Amount of decimals (rounded up) |
182 | 182 | * @return float |
183 | 183 | */ |
184 | - public function toKibibytes(int $precision=1) : float |
|
184 | + public function toKibibytes(int $precision = 1) : float |
|
185 | 185 | { |
186 | 186 | return $this->toNumber($precision, 'kib'); |
187 | 187 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param int $precision Amount of decimals (rounded up) |
193 | 193 | * @return float |
194 | 194 | */ |
195 | - public function toMebibytes(int $precision=1) : float |
|
195 | + public function toMebibytes(int $precision = 1) : float |
|
196 | 196 | { |
197 | 197 | return $this->toNumber($precision, 'mib'); |
198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param int $precision Amount of decimals (rounded up) |
204 | 204 | * @return float |
205 | 205 | */ |
206 | - public function toGibibytes(int $precision=1) : float |
|
206 | + public function toGibibytes(int $precision = 1) : float |
|
207 | 207 | { |
208 | 208 | return $this->toNumber($precision, 'gib'); |
209 | 209 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param int $precision Amount of decimals (rounded up) |
215 | 215 | * @return float |
216 | 216 | */ |
217 | - public function toTebibytes(int $precision=1) : float |
|
217 | + public function toTebibytes(int $precision = 1) : float |
|
218 | 218 | { |
219 | 219 | return $this->toNumber($precision, 'tib'); |
220 | 220 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param int $precision Amount of decimals (rounded up) |
226 | 226 | * @return float |
227 | 227 | */ |
228 | - public function toPebibytes(int $precision=1) : float |
|
228 | + public function toPebibytes(int $precision = 1) : float |
|
229 | 229 | { |
230 | 230 | return $this->toNumber($precision, 'pib'); |
231 | 231 | } |
@@ -25,34 +25,34 @@ |
||
25 | 25 | */ |
26 | 26 | class ConvertHelper_StorageSizeEnum_Size |
27 | 27 | { |
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | 31 | protected $name; |
32 | 32 | |
33 | - /** |
|
34 | - * @var int |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var int |
|
35 | + */ |
|
36 | 36 | protected $base; |
37 | 37 | |
38 | - /** |
|
39 | - * @var int |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @var int |
|
40 | + */ |
|
41 | 41 | protected $exponent; |
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | protected $singular; |
47 | 47 | |
48 | - /** |
|
49 | - * @var string |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var string |
|
50 | + */ |
|
51 | 51 | protected $plural; |
52 | 52 | |
53 | - /** |
|
54 | - * @var string |
|
55 | - */ |
|
53 | + /** |
|
54 | + * @var string |
|
55 | + */ |
|
56 | 56 | protected $suffix; |
57 | 57 | |
58 | 58 | public function __construct(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | const VALIDATION_ERROR_NEGATIVE_VALUE = 43803; |
33 | 33 | |
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | 37 | protected $sizeString; |
38 | 38 | |
39 | 39 | /** |
@@ -41,41 +41,41 @@ discard block |
||
41 | 41 | */ |
42 | 42 | protected $sizeDefinition; |
43 | 43 | |
44 | - /** |
|
45 | - * @var integer |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var integer |
|
46 | + */ |
|
47 | 47 | protected $bytes = 0; |
48 | 48 | |
49 | - /** |
|
50 | - * @var bool |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var bool |
|
51 | + */ |
|
52 | 52 | protected $valid = true; |
53 | 53 | |
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $units = null; |
58 | 58 | |
59 | - /** |
|
60 | - * @var string |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | protected $number = ''; |
63 | 63 | |
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | 67 | protected $errorMessage = ''; |
68 | 68 | |
69 | - /** |
|
70 | - * @var int |
|
71 | - */ |
|
69 | + /** |
|
70 | + * @var int |
|
71 | + */ |
|
72 | 72 | protected $errorCode = 0; |
73 | 73 | |
74 | - /** |
|
75 | - * Create a new instance for the specified size string. |
|
76 | - * |
|
77 | - * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
78 | - */ |
|
74 | + /** |
|
75 | + * Create a new instance for the specified size string. |
|
76 | + * |
|
77 | + * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
78 | + */ |
|
79 | 79 | public function __construct(string $sizeString) |
80 | 80 | { |
81 | 81 | $this->sizeString = $this->cleanString($sizeString); |
@@ -83,31 +83,31 @@ discard block |
||
83 | 83 | $this->convert(); |
84 | 84 | } |
85 | 85 | |
86 | - /** |
|
87 | - * Gets the amount of bytes contained in the size notation. |
|
88 | - * @return int |
|
89 | - */ |
|
86 | + /** |
|
87 | + * Gets the amount of bytes contained in the size notation. |
|
88 | + * @return int |
|
89 | + */ |
|
90 | 90 | public function toBytes() : int |
91 | 91 | { |
92 | 92 | return $this->bytes; |
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Converts the size notation to a human readable string, e.g. "50 MB". |
|
97 | - * |
|
98 | - * @param int $precision |
|
99 | - * @return string |
|
100 | - * @see ConvertHelper::bytes2readable() |
|
101 | - */ |
|
95 | + /** |
|
96 | + * Converts the size notation to a human readable string, e.g. "50 MB". |
|
97 | + * |
|
98 | + * @param int $precision |
|
99 | + * @return string |
|
100 | + * @see ConvertHelper::bytes2readable() |
|
101 | + */ |
|
102 | 102 | public function toString(int $precision=1) : string |
103 | 103 | { |
104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
105 | 105 | } |
106 | 106 | |
107 | - /** |
|
108 | - * Retrieves the detected number's base. |
|
109 | - * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
110 | - */ |
|
107 | + /** |
|
108 | + * Retrieves the detected number's base. |
|
109 | + * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
110 | + */ |
|
111 | 111 | public function getBase() : int |
112 | 112 | { |
113 | 113 | if($this->isValid()) { |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | return 0; |
118 | 118 | } |
119 | 119 | |
120 | - /** |
|
121 | - * Retrieves the detected storage size instance, if |
|
122 | - * the size string is valid. |
|
123 | - * |
|
124 | - * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
125 | - * @see ConvertHelper_StorageSizeEnum_Size |
|
126 | - */ |
|
120 | + /** |
|
121 | + * Retrieves the detected storage size instance, if |
|
122 | + * the size string is valid. |
|
123 | + * |
|
124 | + * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
125 | + * @see ConvertHelper_StorageSizeEnum_Size |
|
126 | + */ |
|
127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
128 | 128 | { |
129 | 129 | if($this->isValid()) { |
@@ -133,27 +133,27 @@ discard block |
||
133 | 133 | return null; |
134 | 134 | } |
135 | 135 | |
136 | - /** |
|
137 | - * Checks whether the size notation was valid and could be parsed |
|
138 | - * into a meaningful byte value. If this returns `false`, it is |
|
139 | - * possible to use the `getErrorXXX` methods to retrieve information |
|
140 | - * on what went wrong. |
|
141 | - * |
|
142 | - * @return bool |
|
143 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
144 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
145 | - */ |
|
136 | + /** |
|
137 | + * Checks whether the size notation was valid and could be parsed |
|
138 | + * into a meaningful byte value. If this returns `false`, it is |
|
139 | + * possible to use the `getErrorXXX` methods to retrieve information |
|
140 | + * on what went wrong. |
|
141 | + * |
|
142 | + * @return bool |
|
143 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
144 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
145 | + */ |
|
146 | 146 | public function isValid() : bool |
147 | 147 | { |
148 | 148 | return $this->valid; |
149 | 149 | } |
150 | 150 | |
151 | - /** |
|
152 | - * Retrieves the error message if the size notation validation failed. |
|
153 | - * |
|
154 | - * @return string |
|
155 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
156 | - */ |
|
151 | + /** |
|
152 | + * Retrieves the error message if the size notation validation failed. |
|
153 | + * |
|
154 | + * @return string |
|
155 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
156 | + */ |
|
157 | 157 | public function getErrorMessage() : string |
158 | 158 | { |
159 | 159 | return $this->errorMessage; |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
203 | - /** |
|
204 | - * Detects the units and the number in the size notation string. |
|
205 | - * Populates the `units` and `number` properties. |
|
206 | - * |
|
207 | - * @return bool Whether the string could be parsed successfully. |
|
208 | - */ |
|
203 | + /** |
|
204 | + * Detects the units and the number in the size notation string. |
|
205 | + * Populates the `units` and `number` properties. |
|
206 | + * |
|
207 | + * @return bool Whether the string could be parsed successfully. |
|
208 | + */ |
|
209 | 209 | protected function detectParts() : bool |
210 | 210 | { |
211 | 211 | $units = ConvertHelper_StorageSizeEnum::getSizeNames(); |
@@ -241,16 +241,16 @@ discard block |
||
241 | 241 | return true; |
242 | 242 | } |
243 | 243 | |
244 | - /** |
|
245 | - * If the validation fails, this is used to store the reason for retrieval later. |
|
246 | - * |
|
247 | - * @param string $message |
|
248 | - * @param int $code |
|
249 | - * |
|
250 | - * @see ConvertHelper_SizeNotation::isValid() |
|
251 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
252 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
253 | - */ |
|
244 | + /** |
|
245 | + * If the validation fails, this is used to store the reason for retrieval later. |
|
246 | + * |
|
247 | + * @param string $message |
|
248 | + * @param int $code |
|
249 | + * |
|
250 | + * @see ConvertHelper_SizeNotation::isValid() |
|
251 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
252 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
253 | + */ |
|
254 | 254 | protected function setError(string $message, int $code) : void |
255 | 255 | { |
256 | 256 | $this->valid = false; |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | $this->errorCode = $code; |
259 | 259 | } |
260 | 260 | |
261 | - /** |
|
262 | - * Retrieves the error code, if the size notation validation failed. |
|
263 | - * |
|
264 | - * @return int |
|
265 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
266 | - */ |
|
261 | + /** |
|
262 | + * Retrieves the error code, if the size notation validation failed. |
|
263 | + * |
|
264 | + * @return int |
|
265 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
266 | + */ |
|
267 | 267 | public function getErrorCode() : int |
268 | 268 | { |
269 | 269 | return $this->errorCode; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return string |
100 | 100 | * @see ConvertHelper::bytes2readable() |
101 | 101 | */ |
102 | - public function toString(int $precision=1) : string |
|
102 | + public function toString(int $precision = 1) : string |
|
103 | 103 | { |
104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getBase() : int |
112 | 112 | { |
113 | - if($this->isValid()) { |
|
113 | + if ($this->isValid()) { |
|
114 | 114 | return $this->sizeDefinition->getBase(); |
115 | 115 | } |
116 | 116 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
128 | 128 | { |
129 | - if($this->isValid()) { |
|
129 | + if ($this->isValid()) { |
|
130 | 130 | return $this->sizeDefinition; |
131 | 131 | } |
132 | 132 | |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | |
176 | 176 | protected function parseSize() : void |
177 | 177 | { |
178 | - if(!$this->detectParts()) { |
|
178 | + if (!$this->detectParts()) { |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // we detected units in the string: all good. |
183 | - if($this->units !== null) |
|
183 | + if ($this->units !== null) |
|
184 | 184 | { |
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // just a numeric value: we assume this means we're dealing with bytes. |
189 | - if(is_numeric($this->number)) |
|
189 | + if (is_numeric($this->number)) |
|
190 | 190 | { |
191 | 191 | $this->units = 'b'; |
192 | 192 | return; |
@@ -212,12 +212,12 @@ discard block |
||
212 | 212 | |
213 | 213 | $number = $this->sizeString; |
214 | 214 | |
215 | - foreach($units as $unit) |
|
215 | + foreach ($units as $unit) |
|
216 | 216 | { |
217 | - if(stristr($number, $unit)) |
|
217 | + if (stristr($number, $unit)) |
|
218 | 218 | { |
219 | 219 | // there are more than 1 unit defined in the string |
220 | - if($this->units !== null) |
|
220 | + if ($this->units !== null) |
|
221 | 221 | { |
222 | 222 | $this->setError( |
223 | 223 | t( |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | { |
274 | 274 | $this->parseSize(); |
275 | 275 | |
276 | - if(!$this->valid) { |
|
276 | + if (!$this->valid) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | |
280 | 280 | $int = intval($this->number); |
281 | 281 | |
282 | 282 | // negative values |
283 | - if($int < 0) |
|
283 | + if ($int < 0) |
|
284 | 284 | { |
285 | 285 | $this->setError( |
286 | 286 | t('Negative values cannot be used as size.'), |