@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | 'gif' |
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | - public function __construct($sourceFile=null, $resource=null, $type=null) |
|
| 139 | + public function __construct($sourceFile = null, $resource = null, $type = null) |
|
| 140 | 140 | { |
| 141 | 141 | // ensure that the GD library is installed |
| 142 | - if(!function_exists('imagecreate')) |
|
| 142 | + if (!function_exists('imagecreate')) |
|
| 143 | 143 | { |
| 144 | 144 | throw new ImageHelper_Exception( |
| 145 | 145 | 'The PHP GD extension is not installed or not enabled.', |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if(is_resource($resource)) |
|
| 151 | + if (is_resource($resource)) |
|
| 152 | 152 | { |
| 153 | 153 | $this->sourceImage = $resource; |
| 154 | 154 | $this->type = $type; |
@@ -172,21 +172,21 @@ discard block |
||
| 172 | 172 | if (is_null($this->type)) { |
| 173 | 173 | throw new ImageHelper_Exception( |
| 174 | 174 | 'Error opening image', |
| 175 | - 'Not a valid supported image type for image ' . $this->file, |
|
| 175 | + 'Not a valid supported image type for image '.$this->file, |
|
| 176 | 176 | self::ERROR_UNSUPPORTED_IMAGE_TYPE |
| 177 | 177 | ); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | $this->info = self::getImageSize($this->file); |
| 181 | 181 | |
| 182 | - if(!$this->isVector()) |
|
| 182 | + if (!$this->isVector()) |
|
| 183 | 183 | { |
| 184 | - $method = 'imagecreatefrom' . $this->type; |
|
| 184 | + $method = 'imagecreatefrom'.$this->type; |
|
| 185 | 185 | $this->sourceImage = $method($this->file); |
| 186 | 186 | if (!$this->sourceImage) { |
| 187 | 187 | throw new ImageHelper_Exception( |
| 188 | 188 | 'Error creating new image', |
| 189 | - $method . ' failed', |
|
| 189 | + $method.' failed', |
|
| 190 | 190 | self::ERROR_FAILED_TO_CREATE_NEW_IMAGE |
| 191 | 191 | ); |
| 192 | 192 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $this->width = $this->info->getWidth(); |
| 199 | 199 | $this->height = $this->info->getHeight(); |
| 200 | 200 | |
| 201 | - if(!$this->isVector()) { |
|
| 201 | + if (!$this->isVector()) { |
|
| 202 | 202 | $this->setNewImage($this->duplicateImage($this->sourceImage)); |
| 203 | 203 | } |
| 204 | 204 | } |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
| 216 | 216 | */ |
| 217 | - public static function createNew($width, $height, $type='png') |
|
| 217 | + public static function createNew($width, $height, $type = 'png') |
|
| 218 | 218 | { |
| 219 | 219 | $img = imagecreatetruecolor($width, $height); |
| 220 | - if($img !== false) { |
|
| 220 | + if ($img !== false) { |
|
| 221 | 221 | return self::createFromResource($img, 'png'); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @param string $type The target image type, e.g. "jpeg", "png", etc. |
| 241 | 241 | * @return ImageHelper |
| 242 | 242 | */ |
| 243 | - public static function createFromResource($resource, ?string $type=null) |
|
| 243 | + public static function createFromResource($resource, ?string $type = null) |
|
| 244 | 244 | { |
| 245 | 245 | self::requireResource($resource); |
| 246 | 246 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public static function setConfig($name, $value) |
| 274 | 274 | { |
| 275 | - if(isset(self::$config[$name])) { |
|
| 275 | + if (isset(self::$config[$name])) { |
|
| 276 | 276 | self::$config[$name] = $value; |
| 277 | 277 | } |
| 278 | 278 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * |
| 284 | 284 | * @param bool $enabled |
| 285 | 285 | */ |
| 286 | - public static function setAutoMemoryAdjustment($enabled=true) |
|
| 286 | + public static function setAutoMemoryAdjustment($enabled = true) |
|
| 287 | 287 | { |
| 288 | 288 | self::setConfig('auto-memory-adjustment', $enabled); |
| 289 | 289 | } |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | public function enableAlpha() |
| 319 | 319 | { |
| 320 | - if(!$this->alpha) |
|
| 320 | + if (!$this->alpha) |
|
| 321 | 321 | { |
| 322 | 322 | self::addAlphaSupport($this->newImage, false); |
| 323 | 323 | $this->alpha = true; |
@@ -348,9 +348,9 @@ discard block |
||
| 348 | 348 | * @param number $percent |
| 349 | 349 | * @return ImageHelper |
| 350 | 350 | */ |
| 351 | - public function sharpen($percent=0) |
|
| 351 | + public function sharpen($percent = 0) |
|
| 352 | 352 | { |
| 353 | - if($percent <= 0) { |
|
| 353 | + if ($percent <= 0) { |
|
| 354 | 354 | return $this; |
| 355 | 355 | } |
| 356 | 356 | |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | return $this->convolute($factor); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - public function blur($percent=0) |
|
| 362 | + public function blur($percent = 0) |
|
| 363 | 363 | { |
| 364 | - if($percent <= 0) { |
|
| 364 | + if ($percent <= 0) { |
|
| 365 | 365 | return $this; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -374,12 +374,12 @@ discard block |
||
| 374 | 374 | { |
| 375 | 375 | // get a value thats equal to 64 - abs( factor ) |
| 376 | 376 | // ( using min/max to limited the factor to 0 - 64 to not get out of range values ) |
| 377 | - $val1Adjustment = 64 - min( 64, max( 0, abs( $factor ) ) ); |
|
| 377 | + $val1Adjustment = 64 - min(64, max(0, abs($factor))); |
|
| 378 | 378 | |
| 379 | 379 | // the base factor for the "current" pixel depends on if we are blurring or sharpening. |
| 380 | 380 | // If we are blurring use 1, if sharpening use 9. |
| 381 | 381 | $val1Base = 9; |
| 382 | - if( abs( $factor ) != $factor ) { |
|
| 382 | + if (abs($factor) != $factor) { |
|
| 383 | 383 | $val1Base = 1; |
| 384 | 384 | } |
| 385 | 385 | |
@@ -392,24 +392,24 @@ discard block |
||
| 392 | 392 | |
| 393 | 393 | // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening. |
| 394 | 394 | $val2 = -1; |
| 395 | - if( abs( $factor ) != $factor ) { |
|
| 395 | + if (abs($factor) != $factor) { |
|
| 396 | 396 | $val2 = 1; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // setup matrix .. |
| 400 | 400 | $matrix = array( |
| 401 | - array( $val2, $val2, $val2 ), |
|
| 402 | - array( $val2, $val1, $val2 ), |
|
| 403 | - array( $val2, $val2, $val2 ) |
|
| 401 | + array($val2, $val2, $val2), |
|
| 402 | + array($val2, $val1, $val2), |
|
| 403 | + array($val2, $val2, $val2) |
|
| 404 | 404 | ); |
| 405 | 405 | |
| 406 | 406 | // calculate the correct divisor |
| 407 | 407 | // actual divisor is equal to "$divisor = $val1 + $val2 * 8;" |
| 408 | 408 | // but the following line is more generic |
| 409 | - $divisor = array_sum( array_map( 'array_sum', $matrix ) ); |
|
| 409 | + $divisor = array_sum(array_map('array_sum', $matrix)); |
|
| 410 | 410 | |
| 411 | 411 | // apply the matrix |
| 412 | - imageconvolution( $this->newImage, $matrix, $divisor, 0 ); |
|
| 412 | + imageconvolution($this->newImage, $matrix, $divisor, 0); |
|
| 413 | 413 | |
| 414 | 414 | return $this; |
| 415 | 415 | } |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | */ |
| 536 | 536 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
| 537 | 537 | { |
| 538 | - if($this->isVector()) { |
|
| 538 | + if ($this->isVector()) { |
|
| 539 | 539 | return $this; |
| 540 | 540 | } |
| 541 | 541 | |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | |
| 557 | 557 | public function resampleAndCrop($width, $height) : ImageHelper |
| 558 | 558 | { |
| 559 | - if($this->isVector()) { |
|
| 559 | + if ($this->isVector()) { |
|
| 560 | 560 | return $this; |
| 561 | 561 | } |
| 562 | 562 | |
@@ -603,14 +603,14 @@ discard block |
||
| 603 | 603 | * @param resource $canvas |
| 604 | 604 | * @param bool $fill Whether to fill the whole canvas with the transparency |
| 605 | 605 | */ |
| 606 | - public static function addAlphaSupport($canvas, $fill=true) |
|
| 606 | + public static function addAlphaSupport($canvas, $fill = true) |
|
| 607 | 607 | { |
| 608 | 608 | self::requireResource($canvas); |
| 609 | 609 | |
| 610 | - imagealphablending($canvas,true); |
|
| 610 | + imagealphablending($canvas, true); |
|
| 611 | 611 | imagesavealpha($canvas, true); |
| 612 | 612 | |
| 613 | - if($fill) { |
|
| 613 | + if ($fill) { |
|
| 614 | 614 | self::fillImageTransparent($canvas); |
| 615 | 615 | } |
| 616 | 616 | } |
@@ -620,13 +620,13 @@ discard block |
||
| 620 | 620 | return $this->alpha; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - public function save(string $targetFile, $dispose=true) |
|
| 623 | + public function save(string $targetFile, $dispose = true) |
|
| 624 | 624 | { |
| 625 | - if($this->isVector()) { |
|
| 625 | + if ($this->isVector()) { |
|
| 626 | 626 | return true; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if(!is_resource($this->newImage)) { |
|
| 629 | + if (!is_resource($this->newImage)) { |
|
| 630 | 630 | throw new ImageHelper_Exception( |
| 631 | 631 | 'Error creating new image', |
| 632 | 632 | 'Cannot save an image, no valid image resource was created. You have to call one of the resample methods to create a new image.', |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | unlink($targetFile); |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - $method = 'image' . $this->type; |
|
| 641 | + $method = 'image'.$this->type; |
|
| 642 | 642 | if (!$method($this->newImage, $targetFile, $this->resolveQuality())) { |
| 643 | 643 | throw new ImageHelper_Exception( |
| 644 | 644 | 'Error creating new image', |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | ); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - if($dispose) { |
|
| 662 | + if ($dispose) { |
|
| 663 | 663 | $this->dispose(); |
| 664 | 664 | } |
| 665 | 665 | |
@@ -668,11 +668,11 @@ discard block |
||
| 668 | 668 | |
| 669 | 669 | public function dispose() |
| 670 | 670 | { |
| 671 | - if(is_resource($this->sourceImage)) { |
|
| 671 | + if (is_resource($this->sourceImage)) { |
|
| 672 | 672 | imagedestroy($this->sourceImage); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - if(is_resource($this->newImage)) { |
|
| 675 | + if (is_resource($this->newImage)) { |
|
| 676 | 676 | imagedestroy($this->newImage); |
| 677 | 677 | } |
| 678 | 678 | } |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | */ |
| 726 | 726 | protected function adjustMemory() : bool |
| 727 | 727 | { |
| 728 | - if(!self::$config['auto-memory-adjustment']) { |
|
| 728 | + if (!self::$config['auto-memory-adjustment']) { |
|
| 729 | 729 | return true; |
| 730 | 730 | } |
| 731 | 731 | |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { |
| 755 | 755 | $newLimit = ($memoryLimit + (memory_get_usage() + $memoryNeeded)) / $MB; |
| 756 | 756 | $newLimit = ceil($newLimit); |
| 757 | - ini_set('memory_limit', $newLimit . 'M'); |
|
| 757 | + ini_set('memory_limit', $newLimit.'M'); |
|
| 758 | 758 | |
| 759 | 759 | return true; |
| 760 | 760 | } |
@@ -785,16 +785,16 @@ discard block |
||
| 785 | 785 | */ |
| 786 | 786 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
| 787 | 787 | { |
| 788 | - if($this->isVector()) { |
|
| 788 | + if ($this->isVector()) { |
|
| 789 | 789 | return $this; |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | - if($this->newWidth==$newWidth && $this->newHeight==$newHeight) { |
|
| 792 | + if ($this->newWidth == $newWidth && $this->newHeight == $newHeight) { |
|
| 793 | 793 | return $this; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - if($newWidth < 1) { $newWidth = 1; } |
|
| 797 | - if($newHeight < 1) { $newHeight = 1; } |
|
| 796 | + if ($newWidth < 1) { $newWidth = 1; } |
|
| 797 | + if ($newHeight < 1) { $newHeight = 1; } |
|
| 798 | 798 | |
| 799 | 799 | $this->adjustMemory(); |
| 800 | 800 | |
@@ -858,11 +858,11 @@ discard block |
||
| 858 | 858 | * @param string $imageType The image format to send, i.e. "jpeg", "png" |
| 859 | 859 | * @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 |
| 860 | 860 | */ |
| 861 | - public static function displayImageStream($resource, $imageType, $quality=-1) |
|
| 861 | + public static function displayImageStream($resource, $imageType, $quality = -1) |
|
| 862 | 862 | { |
| 863 | 863 | $imageType = strtolower($imageType); |
| 864 | 864 | |
| 865 | - if(!in_array($imageType, self::$streamTypes)) |
|
| 865 | + if (!in_array($imageType, self::$streamTypes)) |
|
| 866 | 866 | { |
| 867 | 867 | throw new ImageHelper_Exception( |
| 868 | 868 | 'Invalid image stream type', |
@@ -874,9 +874,9 @@ discard block |
||
| 874 | 874 | ); |
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - header('Content-type:image/' . $imageType); |
|
| 877 | + header('Content-type:image/'.$imageType); |
|
| 878 | 878 | |
| 879 | - $function = 'image' . $imageType; |
|
| 879 | + $function = 'image'.$imageType; |
|
| 880 | 880 | |
| 881 | 881 | $function($resource, null, $quality); |
| 882 | 882 | } |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | if (headers_sent($file, $line)) { |
| 893 | 893 | throw new ImageHelper_Exception( |
| 894 | 894 | 'Error displaying image', |
| 895 | - 'Headers have already been sent: in file ' . $file . ':' . $line, |
|
| 895 | + 'Headers have already been sent: in file '.$file.':'.$line, |
|
| 896 | 896 | self::ERROR_HEADERS_ALREADY_SENT |
| 897 | 897 | ); |
| 898 | 898 | } |
@@ -909,16 +909,16 @@ discard block |
||
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | $format = self::getFileImageType($imageFile); |
| 912 | - if($format == 'svg') { |
|
| 912 | + if ($format == 'svg') { |
|
| 913 | 913 | $format = 'svg+xml'; |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | - $contentType = 'image/' . $format; |
|
| 916 | + $contentType = 'image/'.$format; |
|
| 917 | 917 | |
| 918 | 918 | header('Content-Type: '.$contentType); |
| 919 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($imageFile)) . " GMT"); |
|
| 919 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($imageFile))." GMT"); |
|
| 920 | 920 | header('Cache-Control: public'); |
| 921 | - header('Content-Length: ' . filesize($imageFile)); |
|
| 921 | + header('Content-Length: '.filesize($imageFile)); |
|
| 922 | 922 | |
| 923 | 923 | readfile($imageFile); |
| 924 | 924 | } |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | * |
| 937 | 937 | * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
| 938 | 938 | */ |
| 939 | - public function trim($color=null) |
|
| 939 | + public function trim($color = null) |
|
| 940 | 940 | { |
| 941 | 941 | return $this->trimImage($this->newImage, $color); |
| 942 | 942 | } |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | $color = imagecolorsforindex($img, $colorIndex); |
| 954 | 954 | |
| 955 | 955 | // it seems imagecolorsforindex may return false (undocumented, unproven) |
| 956 | - if(is_array($color)) { |
|
| 956 | + if (is_array($color)) { |
|
| 957 | 957 | return $color; |
| 958 | 958 | } |
| 959 | 959 | |
@@ -973,15 +973,15 @@ discard block |
||
| 973 | 973 | * @param array $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. |
| 974 | 974 | * @return ImageHelper |
| 975 | 975 | */ |
| 976 | - protected function trimImage($img, ?array $color=null) : ImageHelper |
|
| 976 | + protected function trimImage($img, ?array $color = null) : ImageHelper |
|
| 977 | 977 | { |
| 978 | - if($this->isVector()) { |
|
| 978 | + if ($this->isVector()) { |
|
| 979 | 979 | return $this; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | self::requireResource($img); |
| 983 | 983 | |
| 984 | - if(empty($color)) |
|
| 984 | + if (empty($color)) |
|
| 985 | 985 | { |
| 986 | 986 | $color = imagecolorat($img, 0, 0); |
| 987 | 987 | $color = $this->getIndexedColors($img, $color); |
@@ -998,16 +998,16 @@ discard block |
||
| 998 | 998 | $ymax = null; |
| 999 | 999 | |
| 1000 | 1000 | // Start scanning for the edges. |
| 1001 | - for ($iy=0; $iy<$imh; $iy++) |
|
| 1001 | + for ($iy = 0; $iy < $imh; $iy++) |
|
| 1002 | 1002 | { |
| 1003 | 1003 | $first = true; |
| 1004 | 1004 | |
| 1005 | - for ($ix=0; $ix<$imw; $ix++) |
|
| 1005 | + for ($ix = 0; $ix < $imw; $ix++) |
|
| 1006 | 1006 | { |
| 1007 | 1007 | $ndx = imagecolorat($img, $ix, $iy); |
| 1008 | 1008 | $colors = $this->getIndexedColors($img, $ndx); |
| 1009 | 1009 | |
| 1010 | - if(!$this->colorsMatch($colors, $color)) |
|
| 1010 | + if (!$this->colorsMatch($colors, $color)) |
|
| 1011 | 1011 | { |
| 1012 | 1012 | if ($xmin > $ix) { $xmin = $ix; } |
| 1013 | 1013 | if ($xmax < $ix) { $xmax = $ix; } |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | |
| 1016 | 1016 | $ymax = $iy; |
| 1017 | 1017 | |
| 1018 | - if($first) |
|
| 1018 | + if ($first) |
|
| 1019 | 1019 | { |
| 1020 | 1020 | $ix = $xmax; |
| 1021 | 1021 | $first = false; |
@@ -1025,18 +1025,18 @@ discard block |
||
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | // no trimming border found |
| 1028 | - if($ymax === null && $ymax === null) { |
|
| 1028 | + if ($ymax === null && $ymax === null) { |
|
| 1029 | 1029 | return $this; |
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // The new width and height of the image. |
| 1033 | - $imw = 1+$xmax-$xmin; // Image width in pixels |
|
| 1034 | - $imh = 1+$ymax-$ymin; // Image height in pixels |
|
| 1033 | + $imw = 1 + $xmax - $xmin; // Image width in pixels |
|
| 1034 | + $imh = 1 + $ymax - $ymin; // Image height in pixels |
|
| 1035 | 1035 | |
| 1036 | 1036 | // Make another image to place the trimmed version in. |
| 1037 | 1037 | $im2 = $this->createNewImage($imw, $imh); |
| 1038 | 1038 | |
| 1039 | - if($color['alpha'] > 0) |
|
| 1039 | + if ($color['alpha'] > 0) |
|
| 1040 | 1040 | { |
| 1041 | 1041 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
| 1042 | 1042 | imagecolortransparent($im2, $bg2); |
@@ -1072,7 +1072,7 @@ discard block |
||
| 1072 | 1072 | |
| 1073 | 1073 | $this->newImage = $image; |
| 1074 | 1074 | $this->newWidth = imagesx($image); |
| 1075 | - $this->newHeight= imagesy($image); |
|
| 1075 | + $this->newHeight = imagesy($image); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1083,7 +1083,7 @@ discard block |
||
| 1083 | 1083 | */ |
| 1084 | 1084 | protected static function requireResource($subject) |
| 1085 | 1085 | { |
| 1086 | - if(is_resource($subject)) { |
|
| 1086 | + if (is_resource($subject)) { |
|
| 1087 | 1087 | return; |
| 1088 | 1088 | } |
| 1089 | 1089 | |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | { |
| 1110 | 1110 | $img = imagecreatetruecolor($width, $height); |
| 1111 | 1111 | |
| 1112 | - if($img === false) |
|
| 1112 | + if ($img === false) |
|
| 1113 | 1113 | { |
| 1114 | 1114 | throw new ImageHelper_Exception( |
| 1115 | 1115 | 'Error creating new image', |
@@ -1133,8 +1133,8 @@ discard block |
||
| 1133 | 1133 | protected function colorsMatch($a, $b) : bool |
| 1134 | 1134 | { |
| 1135 | 1135 | $parts = array('red', 'green', 'blue'); |
| 1136 | - foreach($parts as $part) { |
|
| 1137 | - if($a[$part] != $b[$part]) { |
|
| 1136 | + foreach ($parts as $part) { |
|
| 1137 | + if ($a[$part] != $b[$part]) { |
|
| 1138 | 1138 | return false; |
| 1139 | 1139 | } |
| 1140 | 1140 | } |
@@ -1142,7 +1142,7 @@ discard block |
||
| 1142 | 1142 | return true; |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | - public function fillWhite($x=0, $y=0) |
|
| 1145 | + public function fillWhite($x = 0, $y = 0) |
|
| 1146 | 1146 | { |
| 1147 | 1147 | $this->addRGBColor('white', 255, 255, 255); |
| 1148 | 1148 | return $this->fill('white', $x, $y); |
@@ -1162,11 +1162,11 @@ discard block |
||
| 1162 | 1162 | self::requireResource($resource); |
| 1163 | 1163 | |
| 1164 | 1164 | $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
| 1165 | - imagecolortransparent ($resource, $transparent); |
|
| 1165 | + imagecolortransparent($resource, $transparent); |
|
| 1166 | 1166 | imagefill($resource, 0, 0, $transparent); |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | - public function fill($colorName, $x=0, $y=0) |
|
| 1169 | + public function fill($colorName, $x = 0, $y = 0) |
|
| 1170 | 1170 | { |
| 1171 | 1171 | imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
| 1172 | 1172 | return $this; |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | return $this; |
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | - public function textTTF($text, $size, $colorName, $x=0, $y=0, $angle=0) |
|
| 1183 | + public function textTTF($text, $size, $colorName, $x = 0, $y = 0, $angle = 0) |
|
| 1184 | 1184 | { |
| 1185 | 1185 | imagealphablending($this->newImage, true); |
| 1186 | 1186 | |
@@ -1199,11 +1199,11 @@ discard block |
||
| 1199 | 1199 | return $this->newImage; |
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | - public function paste(ImageHelper $target, $xpos=0, $ypos=0, $sourceX=0, $sourceY=0) |
|
| 1202 | + public function paste(ImageHelper $target, $xpos = 0, $ypos = 0, $sourceX = 0, $sourceY = 0) |
|
| 1203 | 1203 | { |
| 1204 | 1204 | $img = $target->getImage(); |
| 1205 | 1205 | |
| 1206 | - if($target->isAlpha()) { |
|
| 1206 | + if ($target->isAlpha()) { |
|
| 1207 | 1207 | $this->enableAlpha(); |
| 1208 | 1208 | } |
| 1209 | 1209 | |
@@ -1248,10 +1248,10 @@ discard block |
||
| 1248 | 1248 | public function fitText($text, $matchWidth) |
| 1249 | 1249 | { |
| 1250 | 1250 | $sizes = array(); |
| 1251 | - for($i=1; $i<=1000; $i=$i+0.1) { |
|
| 1251 | + for ($i = 1; $i <= 1000; $i = $i + 0.1) { |
|
| 1252 | 1252 | $size = $this->calcTextSize($text, $i); |
| 1253 | 1253 | $sizes[] = $size; |
| 1254 | - if($size['width'] >= $matchWidth) { |
|
| 1254 | + if ($size['width'] >= $matchWidth) { |
|
| 1255 | 1255 | break; |
| 1256 | 1256 | } |
| 1257 | 1257 | } |
@@ -1263,7 +1263,7 @@ discard block |
||
| 1263 | 1263 | $diffLast = $last['width'] - $matchWidth; |
| 1264 | 1264 | $diffPrev = $matchWidth - $prev['width']; |
| 1265 | 1265 | |
| 1266 | - if($diffLast <= $diffPrev) { |
|
| 1266 | + if ($diffLast <= $diffPrev) { |
|
| 1267 | 1267 | return $last; |
| 1268 | 1268 | } |
| 1269 | 1269 | |
@@ -1291,14 +1291,14 @@ discard block |
||
| 1291 | 1291 | 'bottom_left_y' => $box[1], |
| 1292 | 1292 | 'bottom_right_x' => $box[2], |
| 1293 | 1293 | 'bottom_right_y' => $box[3], |
| 1294 | - 'width' => $right-$left, |
|
| 1295 | - 'height' => $bottom-$top |
|
| 1294 | + 'width' => $right - $left, |
|
| 1295 | + 'height' => $bottom - $top |
|
| 1296 | 1296 | ); |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | protected function requireTTFFont() |
| 1300 | 1300 | { |
| 1301 | - if(isset($this->TTFFile)) { |
|
| 1301 | + if (isset($this->TTFFile)) { |
|
| 1302 | 1302 | return; |
| 1303 | 1303 | } |
| 1304 | 1304 | |
@@ -1333,7 +1333,7 @@ discard block |
||
| 1333 | 1333 | */ |
| 1334 | 1334 | public static function getImageSize($pathOrResource) : ImageHelper_Size |
| 1335 | 1335 | { |
| 1336 | - if(is_resource($pathOrResource)) |
|
| 1336 | + if (is_resource($pathOrResource)) |
|
| 1337 | 1337 | { |
| 1338 | 1338 | return new ImageHelper_Size(array( |
| 1339 | 1339 | 'width' => imagesx($pathOrResource), |
@@ -1347,7 +1347,7 @@ discard block |
||
| 1347 | 1347 | |
| 1348 | 1348 | $info = false; |
| 1349 | 1349 | $method = 'getImageSize_'.$type; |
| 1350 | - if(method_exists(__CLASS__, $method)) |
|
| 1350 | + if (method_exists(__CLASS__, $method)) |
|
| 1351 | 1351 | { |
| 1352 | 1352 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
| 1353 | 1353 | } |
@@ -1356,7 +1356,7 @@ discard block |
||
| 1356 | 1356 | $info = getimagesize($pathOrResource); |
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | - if($info !== false) { |
|
| 1359 | + if ($info !== false) { |
|
| 1360 | 1360 | return new ImageHelper_Size($info); |
| 1361 | 1361 | } |
| 1362 | 1362 | |
@@ -1382,7 +1382,7 @@ discard block |
||
| 1382 | 1382 | $xml = XMLHelper::createSimplexml(); |
| 1383 | 1383 | $xml->loadFile($imagePath); |
| 1384 | 1384 | |
| 1385 | - if($xml->hasErrors()) { |
|
| 1385 | + if ($xml->hasErrors()) { |
|
| 1386 | 1386 | throw new ImageHelper_Exception( |
| 1387 | 1387 | 'Error opening SVG image', |
| 1388 | 1388 | sprintf( |
@@ -1397,7 +1397,7 @@ discard block |
||
| 1397 | 1397 | $xml->dispose(); |
| 1398 | 1398 | unset($xml); |
| 1399 | 1399 | |
| 1400 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
| 1400 | + if (!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
| 1401 | 1401 | throw new ImageHelper_Exception( |
| 1402 | 1402 | 'SVG Image is corrupted', |
| 1403 | 1403 | sprintf( |
@@ -1414,7 +1414,7 @@ discard block |
||
| 1414 | 1414 | $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
| 1415 | 1415 | $size = explode(',', $viewBox); |
| 1416 | 1416 | |
| 1417 | - if(count($size) != 4) |
|
| 1417 | + if (count($size) != 4) |
|
| 1418 | 1418 | { |
| 1419 | 1419 | throw new ImageHelper_Exception( |
| 1420 | 1420 | 'SVG image has an invalid viewBox attribute', |
@@ -1460,7 +1460,7 @@ discard block |
||
| 1460 | 1460 | * @param integer $y |
| 1461 | 1461 | * @return ImageHelper |
| 1462 | 1462 | */ |
| 1463 | - public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
|
| 1463 | + public function crop(int $width, int $height, int $x = 0, int $y = 0) : ImageHelper |
|
| 1464 | 1464 | { |
| 1465 | 1465 | $new = $this->createNewImage($width, $height); |
| 1466 | 1466 | |
@@ -1497,7 +1497,7 @@ discard block |
||
| 1497 | 1497 | * @see ImageHelper::calcAverageColorRGB() |
| 1498 | 1498 | * @see ImageHelper::calcAverageColorHEX() |
| 1499 | 1499 | */ |
| 1500 | - public function calcAverageColor(int $format=self::COLORFORMAT_RGB) |
|
| 1500 | + public function calcAverageColor(int $format = self::COLORFORMAT_RGB) |
|
| 1501 | 1501 | { |
| 1502 | 1502 | $image = $this->duplicate(); |
| 1503 | 1503 | $image->resample(1, 1); |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | public function calcAverageColorRGB() : array |
| 1517 | 1517 | { |
| 1518 | 1518 | $result = $this->calcAverageColor(self::COLORFORMAT_RGB); |
| 1519 | - if(is_array($result)) { |
|
| 1519 | + if (is_array($result)) { |
|
| 1520 | 1520 | return $result; |
| 1521 | 1521 | } |
| 1522 | 1522 | |
@@ -1537,7 +1537,7 @@ discard block |
||
| 1537 | 1537 | public function calcAverageColorHex() : string |
| 1538 | 1538 | { |
| 1539 | 1539 | $result = $this->calcAverageColor(self::COLORFORMAT_HEX); |
| 1540 | - if(is_string($result)) { |
|
| 1540 | + if (is_string($result)) { |
|
| 1541 | 1541 | return $result; |
| 1542 | 1542 | } |
| 1543 | 1543 | |
@@ -1574,9 +1574,9 @@ discard block |
||
| 1574 | 1574 | * @see ImageHelper::COLORFORMAT_RGB |
| 1575 | 1575 | * @see ImageHelper::COLORFORMAT_HEX |
| 1576 | 1576 | */ |
| 1577 | - public function getColorAt(int $x, int $y, int $format=self::COLORFORMAT_RGB) |
|
| 1577 | + public function getColorAt(int $x, int $y, int $format = self::COLORFORMAT_RGB) |
|
| 1578 | 1578 | { |
| 1579 | - if($x > $this->getWidth() || $y > $this->getHeight()) |
|
| 1579 | + if ($x > $this->getWidth() || $y > $this->getHeight()) |
|
| 1580 | 1580 | { |
| 1581 | 1581 | throw new ImageHelper_Exception( |
| 1582 | 1582 | 'Position out of bounds', |
@@ -1594,7 +1594,7 @@ discard block |
||
| 1594 | 1594 | $idx = imagecolorat($this->newImage, $x, $y); |
| 1595 | 1595 | $rgb = $this->getIndexedColors($this->newImage, $idx); |
| 1596 | 1596 | |
| 1597 | - if($format == self::COLORFORMAT_HEX) { |
|
| 1597 | + if ($format == self::COLORFORMAT_HEX) { |
|
| 1598 | 1598 | return self::rgb2hex($rgb); |
| 1599 | 1599 | } |
| 1600 | 1600 | |
@@ -1609,7 +1609,7 @@ discard block |
||
| 1609 | 1609 | */ |
| 1610 | 1610 | public static function rgb2luma(array $rgb) : int |
| 1611 | 1611 | { |
| 1612 | - return (int)floor((($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6); |
|
| 1612 | + return (int)floor((($rgb['red'] * 2) + $rgb['blue'] + ($rgb['green'] * 3)) / 6); |
|
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | 1615 | /** |
@@ -142,7 +142,7 @@ |
||
| 142 | 142 | |
| 143 | 143 | protected function getInfoKey(string $name) : string |
| 144 | 144 | { |
| 145 | - if(isset($this->info[$name])) { |
|
| 145 | + if (isset($this->info[$name])) { |
|
| 146 | 146 | return (string)$this->info[$name]; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function setValue($value) : NumberInfo |
| 86 | 86 | { |
| 87 | - if($value instanceof NumberInfo) { |
|
| 87 | + if ($value instanceof NumberInfo) { |
|
| 88 | 88 | $value = $value->getValue(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function isPositive() : bool |
| 119 | 119 | { |
| 120 | - if(!$this->isEmpty()) { |
|
| 120 | + if (!$this->isEmpty()) { |
|
| 121 | 121 | $number = $this->getNumber(); |
| 122 | 122 | return $number > 0; |
| 123 | 123 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function hasValue() : bool |
| 150 | 150 | { |
| 151 | - if(!$this->isEmpty() && !$this->isZero()) { |
|
| 151 | + if (!$this->isEmpty() && !$this->isZero()) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function getUnits() |
| 223 | 223 | { |
| 224 | - if(!$this->hasUnits()) { |
|
| 224 | + if (!$this->hasUnits()) { |
|
| 225 | 225 | return 'px'; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -255,15 +255,15 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function toAttribute() : string |
| 257 | 257 | { |
| 258 | - if($this->isEmpty()) { |
|
| 258 | + if ($this->isEmpty()) { |
|
| 259 | 259 | return ''; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if($this->isZero()) { |
|
| 262 | + if ($this->isZero()) { |
|
| 263 | 263 | return '0'; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($this->isPercent()) { |
|
| 266 | + if ($this->isPercent()) { |
|
| 267 | 267 | return $this->getNumber().$this->getUnits(); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function toCSS() : string |
| 278 | 278 | { |
| 279 | - if($this->isEmpty()) { |
|
| 279 | + if ($this->isEmpty()) { |
|
| 280 | 280 | return ''; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if($this->isZero()) { |
|
| 283 | + if ($this->isZero()) { |
|
| 284 | 284 | return '0'; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | public function __toString() |
| 291 | 291 | { |
| 292 | - if($this->isEmpty()) { |
|
| 292 | + if ($this->isEmpty()) { |
|
| 293 | 293 | return ''; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function isBiggerThan($number) |
| 308 | 308 | { |
| 309 | 309 | $number = parseNumber($number); |
| 310 | - if($number->getUnits() != $this->getUnits()) { |
|
| 310 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | public function isSmallerThan($number) |
| 326 | 326 | { |
| 327 | 327 | $number = parseNumber($number); |
| 328 | - if($number->getUnits() != $this->getUnits()) { |
|
| 328 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | public function isBiggerEqual($number) |
| 336 | 336 | { |
| 337 | 337 | $number = parseNumber($number); |
| 338 | - if($number->getUnits() != $this->getUnits()) { |
|
| 338 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 339 | 339 | return false; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public function add($value) |
| 354 | 354 | { |
| 355 | - if($this->isEmpty()) { |
|
| 355 | + if ($this->isEmpty()) { |
|
| 356 | 356 | $this->setValue($value); |
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $number = parseNumber($value); |
| 361 | 361 | |
| 362 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 362 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 363 | 363 | { |
| 364 | 364 | $new = $this->getNumber() + $number->getNumber(); |
| 365 | 365 | $this->setValue($new.$this->getUnits()); |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function subtract($value) |
| 380 | 380 | { |
| 381 | - if($this->isEmpty()) { |
|
| 381 | + if ($this->isEmpty()) { |
|
| 382 | 382 | $this->setValue($value); |
| 383 | 383 | return $this; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $number = parseNumber($value); |
| 387 | 387 | |
| 388 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 388 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 389 | 389 | { |
| 390 | 390 | $new = $this->getNumber() - $number->getNumber(); |
| 391 | 391 | $this->setValue($new.$this->getUnits()); |
@@ -412,25 +412,25 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | protected function percentOperation($operation, $percent) |
| 414 | 414 | { |
| 415 | - if($this->isZeroOrEmpty()) { |
|
| 415 | + if ($this->isZeroOrEmpty()) { |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | $percent = parseNumber($percent); |
| 420 | - if($percent->hasUnits() && !$percent->isPercent()) { |
|
| 420 | + if ($percent->hasUnits() && !$percent->isPercent()) { |
|
| 421 | 421 | return $this; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | $number = $this->getNumber(); |
| 425 | 425 | $value = $number * $percent->getNumber() / 100; |
| 426 | 426 | |
| 427 | - if($operation == '-') { |
|
| 427 | + if ($operation == '-') { |
|
| 428 | 428 | $number = $number - $value; |
| 429 | 429 | } else { |
| 430 | 430 | $number = $number + $value; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if($this->isUnitInteger()) { |
|
| 433 | + if ($this->isUnitInteger()) { |
|
| 434 | 434 | $number = intval($number); |
| 435 | 435 | } |
| 436 | 436 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | $key = $this->createValueKey($value); |
| 483 | 483 | |
| 484 | - if(array_key_exists($key, $cache)) { |
|
| 484 | + if (array_key_exists($key, $cache)) { |
|
| 485 | 485 | return $cache[$key]; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -491,13 +491,13 @@ discard block |
||
| 491 | 491 | 'number' => null |
| 492 | 492 | ); |
| 493 | 493 | |
| 494 | - if($key === '_EMPTY_') |
|
| 494 | + if ($key === '_EMPTY_') |
|
| 495 | 495 | { |
| 496 | 496 | $cache[$key]['empty'] = true; |
| 497 | 497 | return $cache[$key]; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - if($value === 0 || $value === '0') |
|
| 500 | + if ($value === 0 || $value === '0') |
|
| 501 | 501 | { |
| 502 | 502 | $cache[$key]['number'] = 0; |
| 503 | 503 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -506,20 +506,20 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $test = trim((string)$value); |
| 508 | 508 | |
| 509 | - if($test === '') |
|
| 509 | + if ($test === '') |
|
| 510 | 510 | { |
| 511 | 511 | $cache[$key]['empty'] = true; |
| 512 | 512 | return $cache[$key]; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // replace comma notation (which is only possible if it's a string) |
| 516 | - if(is_string($value)) |
|
| 516 | + if (is_string($value)) |
|
| 517 | 517 | { |
| 518 | 518 | $test = $this->preProcess($test, $cache, $value); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // convert to a number if it's numeric |
| 522 | - if(is_numeric($test)) |
|
| 522 | + if (is_numeric($test)) |
|
| 523 | 523 | { |
| 524 | 524 | $cache[$key]['number'] = (float)$test * 1; |
| 525 | 525 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -545,19 +545,19 @@ discard block |
||
| 545 | 545 | $empty = false; |
| 546 | 546 | |
| 547 | 547 | $found = $this->findUnits($test); |
| 548 | - if($found !== null) |
|
| 548 | + if ($found !== null) |
|
| 549 | 549 | { |
| 550 | 550 | $number = $found['number']; |
| 551 | 551 | $units = $found['units']; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | // the filters have to restore the value |
| 555 | - if($this->postProcess) |
|
| 555 | + if ($this->postProcess) |
|
| 556 | 556 | { |
| 557 | 557 | $number = $this->postProcess($number, $test); |
| 558 | 558 | } |
| 559 | 559 | // empty number |
| 560 | - else if($number === '' || $number === null || is_bool($number)) |
|
| 560 | + else if ($number === '' || $number === null || is_bool($number)) |
|
| 561 | 561 | { |
| 562 | 562 | $number = null; |
| 563 | 563 | $empty = true; |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | $number = trim($number); |
| 569 | 569 | |
| 570 | 570 | // may be an arbitrary string in some cases |
| 571 | - if(!is_numeric($number)) |
|
| 571 | + if (!is_numeric($number)) |
|
| 572 | 572 | { |
| 573 | 573 | $number = null; |
| 574 | 574 | $empty = true; |
@@ -600,17 +600,17 @@ discard block |
||
| 600 | 600 | $vlength = strlen($value); |
| 601 | 601 | $names = array_keys($this->knownUnits); |
| 602 | 602 | |
| 603 | - foreach($names as $unit) |
|
| 603 | + foreach ($names as $unit) |
|
| 604 | 604 | { |
| 605 | 605 | $ulength = strlen($unit); |
| 606 | - $start = $vlength-$ulength; |
|
| 607 | - if($start < 0) { |
|
| 606 | + $start = $vlength - $ulength; |
|
| 607 | + if ($start < 0) { |
|
| 608 | 608 | continue; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | $search = substr($value, $start, $ulength); |
| 612 | 612 | |
| 613 | - if($search==$unit) |
|
| 613 | + if ($search == $unit) |
|
| 614 | 614 | { |
| 615 | 615 | return array( |
| 616 | 616 | 'units' => $unit, |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | */ |
| 631 | 631 | private function createValueKey($value) : string |
| 632 | 632 | { |
| 633 | - if(!is_string($value) && !is_numeric($value)) |
|
| 633 | + if (!is_string($value) && !is_numeric($value)) |
|
| 634 | 634 | { |
| 635 | 635 | return '_EMPTY_'; |
| 636 | 636 | } |
@@ -696,12 +696,12 @@ discard block |
||
| 696 | 696 | protected function filterInfo(array $info) : array |
| 697 | 697 | { |
| 698 | 698 | $useUnits = 'px'; |
| 699 | - if($info['units'] !== null) { |
|
| 699 | + if ($info['units'] !== null) { |
|
| 700 | 700 | $useUnits = $info['units']; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | // the units are non-decimal: convert decimal values |
| 704 | - if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 704 | + if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 705 | 705 | { |
| 706 | 706 | $info['number'] = intval($info['number']); |
| 707 | 707 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected static function init() : void |
| 46 | 46 | { |
| 47 | - if(!empty(self::$sizes)) { |
|
| 47 | + if (!empty(self::$sizes)) { |
|
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | self::addSize('b', 1, 1, t('B'), t('Byte'), t('Bytes')); |
| 64 | 64 | |
| 65 | - if(class_exists('AppLocalize\Localization')) |
|
| 65 | + if (class_exists('AppLocalize\Localization')) |
|
| 66 | 66 | { |
| 67 | 67 | \AppLocalize\Localization::onLocaleChanged(array(self::class, 'handle_localeChanged')); |
| 68 | 68 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $name = strtolower($name); |
| 133 | 133 | |
| 134 | - if(isset(self::$sizes[$name])) { |
|
| 134 | + if (isset(self::$sizes[$name])) { |
|
| 135 | 135 | return self::$sizes[$name]; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | $result = array(); |
| 175 | 175 | |
| 176 | - foreach(self::$sizes as $size) |
|
| 176 | + foreach (self::$sizes as $size) |
|
| 177 | 177 | { |
| 178 | - if($size->getBase() === $base) { |
|
| 178 | + if ($size->getBase() === $base) { |
|
| 179 | 179 | $result[] = $size; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param bool $enable |
| 58 | 58 | * @return ConvertHelper_TabsNormalizer |
| 59 | 59 | */ |
| 60 | - public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
|
| 60 | + public function convertTabsToSpaces(bool $enable = true) : ConvertHelper_TabsNormalizer |
|
| 61 | 61 | { |
| 62 | 62 | $this->tabs2spaces = $enable; |
| 63 | 63 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $result = $this->_normalize(); |
| 96 | 96 | |
| 97 | - if($this->tabs2spaces) |
|
| 97 | + if ($this->tabs2spaces) |
|
| 98 | 98 | { |
| 99 | 99 | $result = ConvertHelper::tabs2spaces($result, $this->tabSize); |
| 100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $eol = ConvertHelper::detectEOLCharacter($string); |
| 110 | 110 | |
| 111 | - if($eol !== null) |
|
| 111 | + if ($eol !== null) |
|
| 112 | 112 | { |
| 113 | 113 | $this->eol = $eol->getCharacter(); |
| 114 | 114 | } |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $converted = array(); |
| 128 | 128 | |
| 129 | - foreach($this->lines as $line) |
|
| 129 | + foreach ($this->lines as $line) |
|
| 130 | 130 | { |
| 131 | 131 | $amount = substr_count($line, "\t") - $this->min; |
| 132 | 132 | |
| 133 | 133 | $line = trim($line, "\n\r\t"); |
| 134 | 134 | |
| 135 | - if($amount >= 1) |
|
| 135 | + if ($amount >= 1) |
|
| 136 | 136 | { |
| 137 | - $line = str_repeat("\t", $amount) . $line; |
|
| 137 | + $line = str_repeat("\t", $amount).$line; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $converted[] = $line; |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function countOccurrences() : void |
| 151 | 151 | { |
| 152 | - foreach($this->lines as $line) |
|
| 152 | + foreach ($this->lines as $line) |
|
| 153 | 153 | { |
| 154 | 154 | $amount = substr_count($line, "\t"); |
| 155 | 155 | |
| 156 | - if($amount > $this->max) |
|
| 156 | + if ($amount > $this->max) |
|
| 157 | 157 | { |
| 158 | 158 | $this->max = $amount; |
| 159 | 159 | continue; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if($amount > 0 && $amount < $this->min) |
|
| 162 | + if ($amount > 0 && $amount < $this->min) |
|
| 163 | 163 | { |
| 164 | 164 | $this->min = $amount; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if($this->min === PHP_INT_MAX) { |
|
| 168 | + if ($this->min === PHP_INT_MAX) { |
|
| 169 | 169 | $this->min = 0; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
| 95 | 95 | { |
| 96 | - if(!in_array($type, $this->selected)) { |
|
| 96 | + if (!in_array($type, $this->selected)) { |
|
| 97 | 97 | $this->selected[] = $type; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | $selected = $this->selected; |
| 111 | 111 | |
| 112 | - if(empty($this->selected)) |
|
| 112 | + if (empty($this->selected)) |
|
| 113 | 113 | { |
| 114 | 114 | $selected = array( |
| 115 | 115 | self::CHARS_WHITESPACE, |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $result = array(); |
| 121 | 121 | |
| 122 | - foreach($selected as $type) |
|
| 122 | + foreach ($selected as $type) |
|
| 123 | 123 | { |
| 124 | - if(isset($this->characters[$type])) |
|
| 124 | + if (isset($this->characters[$type])) |
|
| 125 | 125 | { |
| 126 | 126 | $result = array_merge($result, $this->characters[$type]); |
| 127 | 127 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | * @param array $args |
| 127 | 127 | * @return Request_Param |
| 128 | 128 | */ |
| 129 | - public function setCallback($callback, array $args=array()) : Request_Param |
|
| 129 | + public function setCallback($callback, array $args = array()) : Request_Param |
|
| 130 | 130 | { |
| 131 | - if(!is_callable($callback)) { |
|
| 131 | + if (!is_callable($callback)) { |
|
| 132 | 132 | throw new Request_Exception( |
| 133 | 133 | 'Not a valid callback', |
| 134 | 134 | 'The specified callback is not a valid callable entity.', |
@@ -159,22 +159,22 @@ discard block |
||
| 159 | 159 | // first off, apply filtering |
| 160 | 160 | $value = $this->filter($value); |
| 161 | 161 | |
| 162 | - if($this->valueType === self::VALUE_TYPE_LIST) |
|
| 162 | + if ($this->valueType === self::VALUE_TYPE_LIST) |
|
| 163 | 163 | { |
| 164 | - if(!is_array($value)) |
|
| 164 | + if (!is_array($value)) |
|
| 165 | 165 | { |
| 166 | 166 | $value = explode(',', $value); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $keep = array(); |
| 170 | 170 | |
| 171 | - foreach($value as $subval) |
|
| 171 | + foreach ($value as $subval) |
|
| 172 | 172 | { |
| 173 | 173 | $subval = $this->filter($subval); |
| 174 | 174 | |
| 175 | 175 | $subval = $this->applyValidations($subval, true); |
| 176 | 176 | |
| 177 | - if($subval !== null) { |
|
| 177 | + if ($subval !== null) { |
|
| 178 | 178 | $keep[] = $subval; |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -195,11 +195,11 @@ discard block |
||
| 195 | 195 | * @param mixed $value |
| 196 | 196 | * @return mixed |
| 197 | 197 | */ |
| 198 | - protected function applyValidations($value, bool $subval=false) |
|
| 198 | + protected function applyValidations($value, bool $subval = false) |
|
| 199 | 199 | { |
| 200 | 200 | // go through all enqueued validations in turn, each time |
| 201 | 201 | // replacing the value with the adjusted, validated value. |
| 202 | - foreach($this->validations as $validateDef) |
|
| 202 | + foreach ($this->validations as $validateDef) |
|
| 203 | 203 | { |
| 204 | 204 | $value = $this->validateType($value, $validateDef['type'], $validateDef['params'], $subval); |
| 205 | 205 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type); |
| 224 | 224 | |
| 225 | - if(!class_exists($class)) |
|
| 225 | + if (!class_exists($class)) |
|
| 226 | 226 | { |
| 227 | 227 | throw new Request_Exception( |
| 228 | 228 | 'Unknown validation type.', |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | { |
| 377 | 377 | $args = func_get_args(); // cannot be used as function parameter in some PHP versions |
| 378 | 378 | |
| 379 | - if(is_array($args[0])) |
|
| 379 | + if (is_array($args[0])) |
|
| 380 | 380 | { |
| 381 | 381 | $args = $args[0]; |
| 382 | 382 | } |
@@ -521,10 +521,10 @@ discard block |
||
| 521 | 521 | * @param mixed $default |
| 522 | 522 | * @return mixed |
| 523 | 523 | */ |
| 524 | - public function get($default=null) |
|
| 524 | + public function get($default = null) |
|
| 525 | 525 | { |
| 526 | 526 | $value = $this->request->getParam($this->paramName); |
| 527 | - if($value !== null && $value !== '') { |
|
| 527 | + if ($value !== null && $value !== '') { |
|
| 528 | 528 | return $value; |
| 529 | 529 | } |
| 530 | 530 | |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | { |
| 544 | 544 | $total = count($this->filters); |
| 545 | 545 | for ($i = 0; $i < $total; $i++) { |
| 546 | - $method = 'applyFilter_' . $this->filters[$i]['type']; |
|
| 546 | + $method = 'applyFilter_'.$this->filters[$i]['type']; |
|
| 547 | 547 | $value = $this->$method($value, $this->filters[$i]['params']); |
| 548 | 548 | } |
| 549 | 549 | |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | * @param bool $stripEmptyEntries Remove empty entries from the array? |
| 701 | 701 | * @return \AppUtils\Request_Param |
| 702 | 702 | */ |
| 703 | - public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
|
| 703 | + public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : Request_Param |
|
| 704 | 704 | { |
| 705 | 705 | $this->setArray(); |
| 706 | 706 | |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | ); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - protected function addClassFilter(string $name, array $params=array()) : Request_Param |
|
| 716 | + protected function addClassFilter(string $name, array $params = array()) : Request_Param |
|
| 717 | 717 | { |
| 718 | 718 | return $this->addFilter( |
| 719 | 719 | self::FILTER_TYPE_CLASS, |
@@ -28,11 +28,11 @@ |
||
| 28 | 28 | protected function _validate() |
| 29 | 29 | { |
| 30 | 30 | // subvalues cannot be arrays |
| 31 | - if($this->isSubvalue) { |
|
| 31 | + if ($this->isSubvalue) { |
|
| 32 | 32 | return $this->value; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if(is_array($this->value)) { |
|
| 35 | + if (is_array($this->value)) { |
|
| 36 | 36 | return $this->value; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -33,22 +33,22 @@ |
||
| 33 | 33 | |
| 34 | 34 | // if we are validating a subvalue, it means we are |
| 35 | 35 | // validating a single value in the existing list. |
| 36 | - if($this->isSubvalue) |
|
| 36 | + if ($this->isSubvalue) |
|
| 37 | 37 | { |
| 38 | - if(in_array($this->value, $allowed)) { |
|
| 38 | + if (in_array($this->value, $allowed)) { |
|
| 39 | 39 | return $this->value; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | return null; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if(!is_array($this->value)) { |
|
| 45 | + if (!is_array($this->value)) { |
|
| 46 | 46 | return array(); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $keep = array(); |
| 50 | - foreach($this->value as $item) { |
|
| 51 | - if(in_array($item, $allowed)) { |
|
| 50 | + foreach ($this->value as $item) { |
|
| 51 | + if (in_array($item, $allowed)) { |
|
| 52 | 52 | $keep[] = $item; |
| 53 | 53 | } |
| 54 | 54 | } |