1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-03 10:53:01 +02:00

Add more exception annotation (#1308)

This commit is contained in:
Vincent Langlet
2024-03-01 19:08:52 +01:00
committed by GitHub
parent 97aa207b25
commit 56b9f50594
21 changed files with 70 additions and 2 deletions

View File

@@ -6,8 +6,6 @@ parameters:
check: check:
missingCheckedExceptionInThrows: true missingCheckedExceptionInThrows: true
uncheckedExceptionClasses: uncheckedExceptionClasses:
- Intervention\Image\Exceptions\ColorException
- Intervention\Image\Exceptions\NotSupportedException
- ImagickException - ImagickException
- ImagickDrawException - ImagickDrawException
- ImagickPixelException - ImagickPixelException

View File

@@ -19,6 +19,7 @@ class Color extends AbstractColor
{ {
public function __construct(int $c, int $m, int $y, int $k) public function __construct(int $c, int $m, int $y, int $k)
{ {
/** @throws void */
$this->channels = [ $this->channels = [
new Cyan($c), new Cyan($c),
new Magenta($m), new Magenta($m),
@@ -48,21 +49,25 @@ class Color extends AbstractColor
public function cyan(): ColorChannelInterface public function cyan(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Cyan::class); return $this->channel(Cyan::class);
} }
public function magenta(): ColorChannelInterface public function magenta(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Magenta::class); return $this->channel(Magenta::class);
} }
public function yellow(): ColorChannelInterface public function yellow(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Yellow::class); return $this->channel(Yellow::class);
} }
public function key(): ColorChannelInterface public function key(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Key::class); return $this->channel(Key::class);
} }

View File

@@ -18,6 +18,7 @@ class Color extends AbstractColor
{ {
public function __construct(int $h, int $s, int $l) public function __construct(int $h, int $s, int $l)
{ {
/** @throws void */
$this->channels = [ $this->channels = [
new Hue($h), new Hue($h),
new Saturation($s), new Saturation($s),
@@ -51,6 +52,7 @@ class Color extends AbstractColor
*/ */
public function hue(): ColorChannelInterface public function hue(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Hue::class); return $this->channel(Hue::class);
} }
@@ -61,6 +63,7 @@ class Color extends AbstractColor
*/ */
public function saturation(): ColorChannelInterface public function saturation(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Saturation::class); return $this->channel(Saturation::class);
} }
@@ -71,6 +74,7 @@ class Color extends AbstractColor
*/ */
public function luminance(): ColorChannelInterface public function luminance(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Luminance::class); return $this->channel(Luminance::class);
} }

View File

@@ -18,6 +18,7 @@ class Color extends AbstractColor
{ {
public function __construct(int $h, int $s, int $v) public function __construct(int $h, int $s, int $v)
{ {
/** @throws void */
$this->channels = [ $this->channels = [
new Hue($h), new Hue($h),
new Saturation($s), new Saturation($s),
@@ -51,6 +52,7 @@ class Color extends AbstractColor
*/ */
public function hue(): ColorChannelInterface public function hue(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Hue::class); return $this->channel(Hue::class);
} }
@@ -61,6 +63,7 @@ class Color extends AbstractColor
*/ */
public function saturation(): ColorChannelInterface public function saturation(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Saturation::class); return $this->channel(Saturation::class);
} }
@@ -71,6 +74,7 @@ class Color extends AbstractColor
*/ */
public function value(): ColorChannelInterface public function value(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Value::class); return $this->channel(Value::class);
} }

View File

@@ -27,6 +27,7 @@ class Color extends AbstractColor
*/ */
public function __construct(int $r, int $g, int $b, int $a = 255) public function __construct(int $r, int $g, int $b, int $a = 255)
{ {
/** @throws void */
$this->channels = [ $this->channels = [
new Red($r), new Red($r),
new Green($g), new Green($g),
@@ -64,6 +65,7 @@ class Color extends AbstractColor
*/ */
public function red(): ColorChannelInterface public function red(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Red::class); return $this->channel(Red::class);
} }
@@ -74,6 +76,7 @@ class Color extends AbstractColor
*/ */
public function green(): ColorChannelInterface public function green(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Green::class); return $this->channel(Green::class);
} }
@@ -84,6 +87,7 @@ class Color extends AbstractColor
*/ */
public function blue(): ColorChannelInterface public function blue(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Blue::class); return $this->channel(Blue::class);
} }
@@ -94,6 +98,7 @@ class Color extends AbstractColor
*/ */
public function alpha(): ColorChannelInterface public function alpha(): ColorChannelInterface
{ {
/** @throws void */
return $this->channel(Alpha::class); return $this->channel(Alpha::class);
} }

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Analyzers;
use GdImage; use GdImage;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\GeometryException; use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
@@ -29,6 +30,7 @@ class PixelColorAnalyzer extends DriverSpecialized implements AnalyzerInterface
/** /**
* @throws GeometryException * @throws GeometryException
* @throws ColorException
*/ */
protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorInterface protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorInterface
{ {

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd;
use GdImage; use GdImage;
use Intervention\Image\Colors\Rgb\Color; use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Interfaces\SizeInterface;
@@ -16,6 +17,7 @@ class Cloner
* Create a clone of the given GdImage * Create a clone of the given GdImage
* *
* @param GdImage $gd * @param GdImage $gd
* @throws ColorException
* @return GdImage * @return GdImage
*/ */
public static function clone(GdImage $gd): GdImage public static function clone(GdImage $gd): GdImage
@@ -39,6 +41,7 @@ class Cloner
* @param GdImage $gd * @param GdImage $gd
* @param null|SizeInterface $size * @param null|SizeInterface $size
* @param ColorInterface $background * @param ColorInterface $background
* @throws ColorException
* @return GdImage * @return GdImage
*/ */
public static function cloneEmpty( public static function cloneEmpty(
@@ -76,6 +79,7 @@ class Cloner
* *
* @param GdImage $gd * @param GdImage $gd
* @param ColorInterface $background * @param ColorInterface $background
* @throws ColorException
* @return GdImage * @return GdImage
*/ */
public static function cloneBlended(GdImage $gd, ColorInterface $background): GdImage public static function cloneBlended(GdImage $gd, ColorInterface $background): GdImage

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd; namespace Intervention\Image\Drivers\Gd;
use GdImage; use GdImage;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Image; use Intervention\Image\Image;
use Intervention\Image\Interfaces\DriverInterface; use Intervention\Image\Interfaces\DriverInterface;
@@ -180,6 +181,7 @@ class Frame implements FrameInterface
/** /**
* This workaround helps cloning GdImages which is currently not possible. * This workaround helps cloning GdImages which is currently not possible.
* *
* @throws ColorException
* @return void * @return void
*/ */
public function __clone(): void public function __clone(): void

View File

@@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
@@ -39,6 +40,9 @@ class ContainModifier extends DriverSpecialized implements ModifierInterface
return $image; return $image;
} }
/**
* @throws ColorException
*/
protected function modify( protected function modify(
FrameInterface $frame, FrameInterface $frame,
SizeInterface $crop, SizeInterface $crop,

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\ModifierInterface;
@@ -29,6 +30,9 @@ class CoverModifier extends DriverSpecialized implements ModifierInterface
return $image; return $image;
} }
/**
* @throws ColorException
*/
protected function modifyFrame(FrameInterface $frame, SizeInterface $crop, SizeInterface $resize): void protected function modifyFrame(FrameInterface $frame, SizeInterface $crop, SizeInterface $resize): void
{ {
// create new image // create new image

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\ModifierInterface;
@@ -34,6 +35,9 @@ class CropModifier extends DriverSpecialized implements ModifierInterface
return $image; return $image;
} }
/**
* @throws ColorException
*/
protected function cropFrame( protected function cropFrame(
FrameInterface $frame, FrameInterface $frame,
SizeInterface $originalSize, SizeInterface $originalSize,

View File

@@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
@@ -33,6 +34,9 @@ class ResizeCanvasModifier extends DriverSpecialized implements ModifierInterfac
return $image; return $image;
} }
/**
* @throws ColorException
*/
protected function modify( protected function modify(
FrameInterface $frame, FrameInterface $frame,
SizeInterface $resize, SizeInterface $resize,

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
@@ -28,6 +29,9 @@ class ResizeModifier extends DriverSpecialized implements ModifierInterface
return $image; return $image;
} }
/**
* @throws ColorException
*/
private function resizeFrame(FrameInterface $frame, SizeInterface $resizeTo): void private function resizeFrame(FrameInterface $frame, SizeInterface $resizeTo): void
{ {
// create empty canvas in target size // create empty canvas in target size

View File

@@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Drivers\Gd\Cloner; use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\FrameInterface;
@@ -37,6 +38,7 @@ class RotateModifier extends DriverSpecialized implements ModifierInterface
* color is used for newly create image areas * color is used for newly create image areas
* *
* @param FrameInterface $frame * @param FrameInterface $frame
* @throws ColorException
* @param ColorInterface $background * @param ColorInterface $background
* @return void * @return void
*/ */

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Imagick; use Imagick;
use Intervention\Image\Drivers\DriverSpecialized; use Intervention\Image\Drivers\DriverSpecialized;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface; 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 protected function colorAt(ColorspaceInterface $colorspace, Imagick $imagick): ColorInterface
{ {
return $this->driver() return $this->driver()

View File

@@ -35,6 +35,9 @@ class ColorspaceModifier extends DriverSpecialized implements ModifierInterface
return $image; return $image;
} }
/**
* @throws NotSupportedException
*/
private function getImagickColorspace(ColorspaceInterface $colorspace): int private function getImagickColorspace(ColorspaceInterface $colorspace): int
{ {
if (!array_key_exists($colorspace::class, self::$mapping)) { if (!array_key_exists($colorspace::class, self::$mapping)) {

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
interface ColorChannelInterface interface ColorChannelInterface
{ {
/** /**
@@ -11,6 +13,7 @@ interface ColorChannelInterface
* *
* @param int|null $value * @param int|null $value
* @param float|null $normalized * @param float|null $normalized
* @throws ColorException
*/ */
public function __construct(?int $value = null, ?float $normalized = null); 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 * Throw exception if the given value is not applicable for channel
* otherwise the value is returned unchanged. * otherwise the value is returned unchanged.
* *
* @throws ColorException
* @return mixed * @return mixed
*/ */
public function validate(mixed $value): mixed; public function validate(mixed $value): mixed;

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Exceptions\RuntimeException;
interface ColorInterface interface ColorInterface
@@ -64,6 +65,7 @@ interface ColorInterface
* Retrieve the color channel by its classname * Retrieve the color channel by its classname
* *
* @param string $classname * @param string $classname
* @throws ColorException
* @return ColorChannelInterface * @return ColorChannelInterface
*/ */
public function channel(string $classname): ColorChannelInterface; public function channel(string $classname): ColorChannelInterface;

View File

@@ -4,12 +4,15 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
interface ColorProcessorInterface interface ColorProcessorInterface
{ {
/** /**
* Turn given color in the driver's color implementation * Turn given color in the driver's color implementation
* *
* @param ColorInterface $color * @param ColorInterface $color
* @throws ColorException
* @return mixed * @return mixed
*/ */
public function colorToNative(ColorInterface $color); public function colorToNative(ColorInterface $color);
@@ -18,6 +21,7 @@ interface ColorProcessorInterface
* Turn the given driver's definition of a color into a color object * Turn the given driver's definition of a color into a color object
* *
* @param mixed $native * @param mixed $native
* @throws ColorException
* @return ColorInterface * @return ColorInterface
*/ */
public function nativeToColor(mixed $native): ColorInterface; public function nativeToColor(mixed $native): ColorInterface;

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces; namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Exceptions\RuntimeException;
interface DriverInterface interface DriverInterface
@@ -20,6 +21,7 @@ interface DriverInterface
* Resolve given object into a specialized version for the current driver * Resolve given object into a specialized version for the current driver
* *
* @param object $object * @param object $object
* @throws NotSupportedException
* @return ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface * @return ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface
*/ */
public function specialize(object $object): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface; public function specialize(object $object): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface;

View File

@@ -15,6 +15,9 @@ class ColorspaceModifier extends SpecializableModifier
{ {
} }
/**
* @throws NotSupportedException
*/
public function targetColorspace(): ColorspaceInterface public function targetColorspace(): ColorspaceInterface
{ {
if (is_object($this->target)) { if (is_object($this->target)) {