From 56b9f50594165189bf64298458e04d640714c4ce Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 1 Mar 2024 19:08:52 +0100 Subject: [PATCH] Add more exception annotation (#1308) --- phpstan.dist.neon | 2 -- src/Colors/Cmyk/Color.php | 5 +++++ src/Colors/Hsl/Color.php | 4 ++++ src/Colors/Hsv/Color.php | 4 ++++ src/Colors/Rgb/Color.php | 5 +++++ src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php | 2 ++ src/Drivers/Gd/Cloner.php | 4 ++++ src/Drivers/Gd/Frame.php | 2 ++ src/Drivers/Gd/Modifiers/ContainModifier.php | 4 ++++ src/Drivers/Gd/Modifiers/CoverModifier.php | 4 ++++ src/Drivers/Gd/Modifiers/CropModifier.php | 4 ++++ src/Drivers/Gd/Modifiers/ResizeCanvasModifier.php | 4 ++++ src/Drivers/Gd/Modifiers/ResizeModifier.php | 4 ++++ src/Drivers/Gd/Modifiers/RotateModifier.php | 2 ++ src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php | 4 ++++ src/Drivers/Imagick/Modifiers/ColorspaceModifier.php | 3 +++ src/Interfaces/ColorChannelInterface.php | 4 ++++ src/Interfaces/ColorInterface.php | 2 ++ src/Interfaces/ColorProcessorInterface.php | 4 ++++ src/Interfaces/DriverInterface.php | 2 ++ src/Modifiers/ColorspaceModifier.php | 3 +++ 21 files changed, 70 insertions(+), 2 deletions(-) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 9a6d4ace..0b689b56 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -6,8 +6,6 @@ parameters: check: missingCheckedExceptionInThrows: true uncheckedExceptionClasses: - - Intervention\Image\Exceptions\ColorException - - Intervention\Image\Exceptions\NotSupportedException - ImagickException - ImagickDrawException - ImagickPixelException diff --git a/src/Colors/Cmyk/Color.php b/src/Colors/Cmyk/Color.php index b3afe377..6510493a 100644 --- a/src/Colors/Cmyk/Color.php +++ b/src/Colors/Cmyk/Color.php @@ -19,6 +19,7 @@ class Color extends AbstractColor { public function __construct(int $c, int $m, int $y, int $k) { + /** @throws void */ $this->channels = [ new Cyan($c), new Magenta($m), @@ -48,21 +49,25 @@ class Color extends AbstractColor public function cyan(): ColorChannelInterface { + /** @throws void */ return $this->channel(Cyan::class); } public function magenta(): ColorChannelInterface { + /** @throws void */ return $this->channel(Magenta::class); } public function yellow(): ColorChannelInterface { + /** @throws void */ return $this->channel(Yellow::class); } public function key(): ColorChannelInterface { + /** @throws void */ return $this->channel(Key::class); } diff --git a/src/Colors/Hsl/Color.php b/src/Colors/Hsl/Color.php index b0bb6147..136b11b8 100644 --- a/src/Colors/Hsl/Color.php +++ b/src/Colors/Hsl/Color.php @@ -18,6 +18,7 @@ class Color extends AbstractColor { public function __construct(int $h, int $s, int $l) { + /** @throws void */ $this->channels = [ new Hue($h), new Saturation($s), @@ -51,6 +52,7 @@ class Color extends AbstractColor */ public function hue(): ColorChannelInterface { + /** @throws void */ return $this->channel(Hue::class); } @@ -61,6 +63,7 @@ class Color extends AbstractColor */ public function saturation(): ColorChannelInterface { + /** @throws void */ return $this->channel(Saturation::class); } @@ -71,6 +74,7 @@ class Color extends AbstractColor */ public function luminance(): ColorChannelInterface { + /** @throws void */ return $this->channel(Luminance::class); } diff --git a/src/Colors/Hsv/Color.php b/src/Colors/Hsv/Color.php index 01d2bbba..da4f7251 100644 --- a/src/Colors/Hsv/Color.php +++ b/src/Colors/Hsv/Color.php @@ -18,6 +18,7 @@ class Color extends AbstractColor { public function __construct(int $h, int $s, int $v) { + /** @throws void */ $this->channels = [ new Hue($h), new Saturation($s), @@ -51,6 +52,7 @@ class Color extends AbstractColor */ public function hue(): ColorChannelInterface { + /** @throws void */ return $this->channel(Hue::class); } @@ -61,6 +63,7 @@ class Color extends AbstractColor */ public function saturation(): ColorChannelInterface { + /** @throws void */ return $this->channel(Saturation::class); } @@ -71,6 +74,7 @@ class Color extends AbstractColor */ public function value(): ColorChannelInterface { + /** @throws void */ return $this->channel(Value::class); } diff --git a/src/Colors/Rgb/Color.php b/src/Colors/Rgb/Color.php index 207031e1..1f500c66 100644 --- a/src/Colors/Rgb/Color.php +++ b/src/Colors/Rgb/Color.php @@ -27,6 +27,7 @@ class Color extends AbstractColor */ public function __construct(int $r, int $g, int $b, int $a = 255) { + /** @throws void */ $this->channels = [ new Red($r), new Green($g), @@ -64,6 +65,7 @@ class Color extends AbstractColor */ public function red(): ColorChannelInterface { + /** @throws void */ return $this->channel(Red::class); } @@ -74,6 +76,7 @@ class Color extends AbstractColor */ public function green(): ColorChannelInterface { + /** @throws void */ return $this->channel(Green::class); } @@ -84,6 +87,7 @@ class Color extends AbstractColor */ public function blue(): ColorChannelInterface { + /** @throws void */ return $this->channel(Blue::class); } @@ -94,6 +98,7 @@ class Color extends AbstractColor */ public function alpha(): ColorChannelInterface { + /** @throws void */ return $this->channel(Alpha::class); } diff --git a/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php b/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php index fe1d8cd2..05a5874d 100644 --- a/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php +++ b/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Analyzers; use GdImage; use Intervention\Image\Drivers\DriverSpecialized; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\GeometryException; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\ColorInterface; @@ -29,6 +30,7 @@ class PixelColorAnalyzer extends DriverSpecialized implements AnalyzerInterface /** * @throws GeometryException + * @throws ColorException */ protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorInterface { diff --git a/src/Drivers/Gd/Cloner.php b/src/Drivers/Gd/Cloner.php index ca668d50..3813a1be 100644 --- a/src/Drivers/Gd/Cloner.php +++ b/src/Drivers/Gd/Cloner.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd; use GdImage; use Intervention\Image\Colors\Rgb\Color; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\SizeInterface; @@ -16,6 +17,7 @@ class Cloner * Create a clone of the given GdImage * * @param GdImage $gd + * @throws ColorException * @return GdImage */ public static function clone(GdImage $gd): GdImage @@ -39,6 +41,7 @@ class Cloner * @param GdImage $gd * @param null|SizeInterface $size * @param ColorInterface $background + * @throws ColorException * @return GdImage */ public static function cloneEmpty( @@ -76,6 +79,7 @@ class Cloner * * @param GdImage $gd * @param ColorInterface $background + * @throws ColorException * @return GdImage */ public static function cloneBlended(GdImage $gd, ColorInterface $background): GdImage diff --git a/src/Drivers/Gd/Frame.php b/src/Drivers/Gd/Frame.php index 122500c0..690f7f8f 100644 --- a/src/Drivers/Gd/Frame.php +++ b/src/Drivers/Gd/Frame.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Intervention\Image\Drivers\Gd; use GdImage; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Image; use Intervention\Image\Interfaces\DriverInterface; @@ -180,6 +181,7 @@ class Frame implements FrameInterface /** * This workaround helps cloning GdImages which is currently not possible. * + * @throws ColorException * @return void */ public function __clone(): void diff --git a/src/Drivers/Gd/Modifiers/ContainModifier.php b/src/Drivers/Gd/Modifiers/ContainModifier.php index f404973e..053269b2 100644 --- a/src/Drivers/Gd/Modifiers/ContainModifier.php +++ b/src/Drivers/Gd/Modifiers/ContainModifier.php @@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\Gd\Cloner; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; @@ -39,6 +40,9 @@ class ContainModifier extends DriverSpecialized implements ModifierInterface return $image; } + /** + * @throws ColorException + */ protected function modify( FrameInterface $frame, SizeInterface $crop, diff --git a/src/Drivers/Gd/Modifiers/CoverModifier.php b/src/Drivers/Gd/Modifiers/CoverModifier.php index 99eaaca8..7067d05f 100644 --- a/src/Drivers/Gd/Modifiers/CoverModifier.php +++ b/src/Drivers/Gd/Modifiers/CoverModifier.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Modifiers; use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\Gd\Cloner; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; @@ -29,6 +30,9 @@ class CoverModifier extends DriverSpecialized implements ModifierInterface return $image; } + /** + * @throws ColorException + */ protected function modifyFrame(FrameInterface $frame, SizeInterface $crop, SizeInterface $resize): void { // create new image diff --git a/src/Drivers/Gd/Modifiers/CropModifier.php b/src/Drivers/Gd/Modifiers/CropModifier.php index ab8a54b2..63637ec8 100644 --- a/src/Drivers/Gd/Modifiers/CropModifier.php +++ b/src/Drivers/Gd/Modifiers/CropModifier.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Modifiers; use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\Gd\Cloner; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; @@ -34,6 +35,9 @@ class CropModifier extends DriverSpecialized implements ModifierInterface return $image; } + /** + * @throws ColorException + */ protected function cropFrame( FrameInterface $frame, SizeInterface $originalSize, diff --git a/src/Drivers/Gd/Modifiers/ResizeCanvasModifier.php b/src/Drivers/Gd/Modifiers/ResizeCanvasModifier.php index 5536da55..5559f760 100644 --- a/src/Drivers/Gd/Modifiers/ResizeCanvasModifier.php +++ b/src/Drivers/Gd/Modifiers/ResizeCanvasModifier.php @@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\Gd\Cloner; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; @@ -33,6 +34,9 @@ class ResizeCanvasModifier extends DriverSpecialized implements ModifierInterfac return $image; } + /** + * @throws ColorException + */ protected function modify( FrameInterface $frame, SizeInterface $resize, diff --git a/src/Drivers/Gd/Modifiers/ResizeModifier.php b/src/Drivers/Gd/Modifiers/ResizeModifier.php index 2f33767b..18a387a8 100644 --- a/src/Drivers/Gd/Modifiers/ResizeModifier.php +++ b/src/Drivers/Gd/Modifiers/ResizeModifier.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Modifiers; use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\Gd\Cloner; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; @@ -28,6 +29,9 @@ class ResizeModifier extends DriverSpecialized implements ModifierInterface return $image; } + /** + * @throws ColorException + */ private function resizeFrame(FrameInterface $frame, SizeInterface $resizeTo): void { // create empty canvas in target size diff --git a/src/Drivers/Gd/Modifiers/RotateModifier.php b/src/Drivers/Gd/Modifiers/RotateModifier.php index 7e8019ea..34b055f3 100644 --- a/src/Drivers/Gd/Modifiers/RotateModifier.php +++ b/src/Drivers/Gd/Modifiers/RotateModifier.php @@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green; use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\Gd\Cloner; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\FrameInterface; @@ -37,6 +38,7 @@ class RotateModifier extends DriverSpecialized implements ModifierInterface * color is used for newly create image areas * * @param FrameInterface $frame + * @throws ColorException * @param ColorInterface $background * @return void */ diff --git a/src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php b/src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php index f7825ae2..7264608e 100644 --- a/src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php +++ b/src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php @@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Imagick\Analyzers; use Imagick; use Intervention\Image\Drivers\DriverSpecialized; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -26,6 +27,9 @@ class PixelColorAnalyzer extends DriverSpecialized implements AnalyzerInterface ); } + /** + * @throws ColorException + */ protected function colorAt(ColorspaceInterface $colorspace, Imagick $imagick): ColorInterface { return $this->driver() diff --git a/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php b/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php index 77f34138..c1e9d8f2 100644 --- a/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php +++ b/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php @@ -35,6 +35,9 @@ class ColorspaceModifier extends DriverSpecialized implements ModifierInterface return $image; } + /** + * @throws NotSupportedException + */ private function getImagickColorspace(ColorspaceInterface $colorspace): int { if (!array_key_exists($colorspace::class, self::$mapping)) { diff --git a/src/Interfaces/ColorChannelInterface.php b/src/Interfaces/ColorChannelInterface.php index da358d8f..f7509f63 100644 --- a/src/Interfaces/ColorChannelInterface.php +++ b/src/Interfaces/ColorChannelInterface.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; +use Intervention\Image\Exceptions\ColorException; + interface ColorChannelInterface { /** @@ -11,6 +13,7 @@ interface ColorChannelInterface * * @param int|null $value * @param float|null $normalized + * @throws ColorException */ public function __construct(?int $value = null, ?float $normalized = null); @@ -32,6 +35,7 @@ interface ColorChannelInterface * Throw exception if the given value is not applicable for channel * otherwise the value is returned unchanged. * + * @throws ColorException * @return mixed */ public function validate(mixed $value): mixed; diff --git a/src/Interfaces/ColorInterface.php b/src/Interfaces/ColorInterface.php index 1ece89f3..acdfdae7 100644 --- a/src/Interfaces/ColorInterface.php +++ b/src/Interfaces/ColorInterface.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; +use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\RuntimeException; interface ColorInterface @@ -64,6 +65,7 @@ interface ColorInterface * Retrieve the color channel by its classname * * @param string $classname + * @throws ColorException * @return ColorChannelInterface */ public function channel(string $classname): ColorChannelInterface; diff --git a/src/Interfaces/ColorProcessorInterface.php b/src/Interfaces/ColorProcessorInterface.php index a1aba983..a5ee9092 100644 --- a/src/Interfaces/ColorProcessorInterface.php +++ b/src/Interfaces/ColorProcessorInterface.php @@ -4,12 +4,15 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; +use Intervention\Image\Exceptions\ColorException; + interface ColorProcessorInterface { /** * Turn given color in the driver's color implementation * * @param ColorInterface $color + * @throws ColorException * @return mixed */ public function colorToNative(ColorInterface $color); @@ -18,6 +21,7 @@ interface ColorProcessorInterface * Turn the given driver's definition of a color into a color object * * @param mixed $native + * @throws ColorException * @return ColorInterface */ public function nativeToColor(mixed $native): ColorInterface; diff --git a/src/Interfaces/DriverInterface.php b/src/Interfaces/DriverInterface.php index ba827381..c4c39001 100644 --- a/src/Interfaces/DriverInterface.php +++ b/src/Interfaces/DriverInterface.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; use Intervention\Image\Exceptions\DriverException; +use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Exceptions\RuntimeException; interface DriverInterface @@ -20,6 +21,7 @@ interface DriverInterface * Resolve given object into a specialized version for the current driver * * @param object $object + * @throws NotSupportedException * @return ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface */ public function specialize(object $object): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface; diff --git a/src/Modifiers/ColorspaceModifier.php b/src/Modifiers/ColorspaceModifier.php index bd4bc69b..bd9eb98f 100644 --- a/src/Modifiers/ColorspaceModifier.php +++ b/src/Modifiers/ColorspaceModifier.php @@ -15,6 +15,9 @@ class ColorspaceModifier extends SpecializableModifier { } + /** + * @throws NotSupportedException + */ public function targetColorspace(): ColorspaceInterface { if (is_object($this->target)) {