From e013c5b2abdd035103b7734b8fc8f049df8f31b5 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:27:42 +0100 Subject: [PATCH] increase phpstan level + fixes --- phpstan.neon.dist | 2 +- src/Drivers/Concerns/CalculatesFocalCropCoordinates.php | 4 ++-- src/Drivers/Gd/GdDriver.php | 3 ++- src/Size.php | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fc8bd5e0..56bdfe60 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 6 + level: 9 paths: - src/ diff --git a/src/Drivers/Concerns/CalculatesFocalCropCoordinates.php b/src/Drivers/Concerns/CalculatesFocalCropCoordinates.php index 7aa22dd8..6451a0ef 100644 --- a/src/Drivers/Concerns/CalculatesFocalCropCoordinates.php +++ b/src/Drivers/Concerns/CalculatesFocalCropCoordinates.php @@ -5,8 +5,8 @@ /** @mixin \Spatie\Image\Drivers\ImageDriver */ trait CalculatesFocalCropCoordinates { - /** @return array */ - protected function calculateFocalCropCoordinates(int $width, int $height, int $cropCenterX, int $cropCenterY): array + /** @return array */ + protected function calculateFocalCropCoordinates(int $width, int $height, ?int $cropCenterX, ?int $cropCenterY): array { $width = min($width, $this->getWidth()); $height = min($height, $this->getHeight()); diff --git a/src/Drivers/Gd/GdDriver.php b/src/Drivers/Gd/GdDriver.php index f072fb37..61f69fc6 100644 --- a/src/Drivers/Gd/GdDriver.php +++ b/src/Drivers/Gd/GdDriver.php @@ -215,7 +215,7 @@ protected function modify( $transparentColorValue = imagecolortransparent($this->image); - if ($transparentColorValue != -1) { + if ($transparentColorValue !== -1) { $rgba = imagecolorsforindex($newImage, $transparentColorValue); $transparentColor = imagecolorallocatealpha( @@ -656,6 +656,7 @@ public function border(int $width, BorderType $type, string $color = '000000'): return $this; } + /** @param int<-1, 100> $quality */ public function quality(int $quality): self { $this->ensureNumberBetween($quality, -1, 100, 'quality'); diff --git a/src/Size.php b/src/Size.php index cf5e0de8..fc9a3b3c 100644 --- a/src/Size.php +++ b/src/Size.php @@ -9,8 +9,8 @@ class Size { public function __construct( - public int|float $width, - public int|float $height, + public int $width, + public int $height, public Point $pivot = new Point() ) { } @@ -42,6 +42,7 @@ public function resize( ->resizeWidth($desiredWidth, $constraints) ->resizeHeight($desiredHeight, $constraints); + // @todo desiredWidth and desiredHeight can still be null here, which will cause an error return $dominantHeightSize->fitsInto(new Size($desiredWidth, $desiredHeight)) ? $dominantHeightSize : $dominantWidthSize;