Skip to content

Commit

Permalink
Throw an exception if a parameter is missing for FillMax.
Browse files Browse the repository at this point in the history
  • Loading branch information
timvandijck committed May 31, 2024
1 parent 17352c9 commit b8c7000
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Drivers/Imagick/ImagickDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Spatie\Image\Enums\FlipDirection;
use Spatie\Image\Enums\Orientation;
use Spatie\Image\Exceptions\InvalidFont;
use Spatie\Image\Exceptions\MissingParameter;
use Spatie\Image\Exceptions\UnsupportedImageFormat;
use Spatie\Image\Point;
use Spatie\Image\Size;
Expand Down Expand Up @@ -132,6 +133,10 @@ public function fit(
}

if ($fit === Fit::FillMax) {
if (is_null($desiredWidth) || is_null($desiredHeight)) {
throw new MissingParameter('Both desiredWidth and desiredHeight must be set when using Fit::FillMax');
}

return $this->fitFillMax($desiredWidth, $desiredHeight, $backgroundColor);

Check failure on line 140 in src/Drivers/Imagick/ImagickDriver.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #3 $backgroundColor of method Spatie\Image\Drivers\Imagick\ImagickDriver::fitFillMax() expects string, string|null given.
}

Expand All @@ -153,7 +158,7 @@ public function fit(
return $this;
}

public function fitFillMax(?int $desiredWidth = null, ?int $desiredHeight = null, ?string $backgroundColor = null, ?bool $relative = false): static
public function fitFillMax(int $desiredWidth, int $desiredHeight, string $backgroundColor, bool $relative = false): static
{
$this->resize($desiredWidth, $desiredHeight, [Constraint::PreserveAspectRatio]);
$this->resizeCanvas($desiredWidth, $desiredHeight, AlignPosition::Center, $relative, $backgroundColor);
Expand Down

0 comments on commit b8c7000

Please sign in to comment.