1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 02:12:37 +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:
missingCheckedExceptionInThrows: true
uncheckedExceptionClasses:
- Intervention\Image\Exceptions\ColorException
- Intervention\Image\Exceptions\NotSupportedException
- ImagickException
- ImagickDrawException
- ImagickPixelException

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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
{

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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,

View File

@@ -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,

View File

@@ -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

View File

@@ -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
*/

View File

@@ -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()

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

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