From 019c333b220e02565bf4084b9a7b120e9f9c1141 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 21 Oct 2023 17:47:35 +0200 Subject: [PATCH] Refactor & add docblocks --- src/Drivers/Gd/ImageFactory.php | 12 +++++++++++- src/Drivers/Imagick/ImageFactory.php | 12 +++++++++++- src/Interfaces/DecoderInterface.php | 6 ++++++ src/Interfaces/EncoderInterface.php | 6 ++++++ src/Interfaces/FactoryInterface.php | 16 +++++++++++++++- src/Interfaces/ModifierInterface.php | 6 ++++++ src/Interfaces/PointInterface.php | 11 +++++++++++ tests/Drivers/Gd/ImageFactoryTest.php | 8 -------- tests/Drivers/Imagick/ImageFactoryTest.php | 2 +- 9 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/Drivers/Gd/ImageFactory.php b/src/Drivers/Gd/ImageFactory.php index 1d92a368..f6de784d 100644 --- a/src/Drivers/Gd/ImageFactory.php +++ b/src/Drivers/Gd/ImageFactory.php @@ -13,6 +13,11 @@ class ImageFactory implements FactoryInterface { use CanHandleInput; + /** + * {@inheritdoc} + * + * @see FactoryInterface::newImage() + */ public function newImage(int $width, int $height): ImageInterface { return new Image( @@ -22,6 +27,11 @@ class ImageFactory implements FactoryInterface ); } + /** + * {@inheritdoc} + * + * @see FactoryInterface::newAnimation() + */ public function newAnimation(callable $callback): ImageInterface { $frames = new Collection(); @@ -50,7 +60,7 @@ class ImageFactory implements FactoryInterface return new Image($frames); } - public function newCore(int $width, int $height) + protected function newCore(int $width, int $height) { $core = imagecreatetruecolor($width, $height); $color = imagecolorallocatealpha($core, 0, 0, 0, 127); diff --git a/src/Drivers/Imagick/ImageFactory.php b/src/Drivers/Imagick/ImageFactory.php index 999965d9..12e5abd1 100644 --- a/src/Drivers/Imagick/ImageFactory.php +++ b/src/Drivers/Imagick/ImageFactory.php @@ -15,11 +15,21 @@ class ImageFactory implements FactoryInterface use CanHandleInput; use CanCheckType; + /** + * {@inheritdoc} + * + * @see FactoryInterface::newImage() + */ public function newImage(int $width, int $height): ImageInterface { return new Image($this->newCore($width, $height)); } + /** + * {@inheritdoc} + * + * @see FactoryInterface::newAnimation() + */ public function newAnimation(callable $callback): ImageInterface { $imagick = new Imagick(); @@ -51,7 +61,7 @@ class ImageFactory implements FactoryInterface return new Image($animation->imagick); } - public function newCore(int $width, int $height) + protected function newCore(int $width, int $height) { $imagick = new Imagick(); $imagick->newImage($width, $height, new ImagickPixel('rgba(0, 0, 0, 0)'), 'png'); diff --git a/src/Interfaces/DecoderInterface.php b/src/Interfaces/DecoderInterface.php index 04ea2660..3ec11957 100644 --- a/src/Interfaces/DecoderInterface.php +++ b/src/Interfaces/DecoderInterface.php @@ -4,5 +4,11 @@ namespace Intervention\Image\Interfaces; interface DecoderInterface { + /** + * Decode given input either to color or image + * + * @param mixed $input + * @return ImageInterface|ColorInterface + */ public function decode($input): ImageInterface|ColorInterface; } diff --git a/src/Interfaces/EncoderInterface.php b/src/Interfaces/EncoderInterface.php index c2d9c41c..adb149a0 100644 --- a/src/Interfaces/EncoderInterface.php +++ b/src/Interfaces/EncoderInterface.php @@ -6,5 +6,11 @@ use Intervention\Image\EncodedImage; interface EncoderInterface { + /** + * Encode given image + * + * @param ImageInterface $image + * @return EncodedImage + */ public function encode(ImageInterface $image): EncodedImage; } diff --git a/src/Interfaces/FactoryInterface.php b/src/Interfaces/FactoryInterface.php index 1f7e9f08..8e948a0c 100644 --- a/src/Interfaces/FactoryInterface.php +++ b/src/Interfaces/FactoryInterface.php @@ -4,6 +4,20 @@ namespace Intervention\Image\Interfaces; interface FactoryInterface { + /** + * Create new image in the given size + * + * @param int $width + * @param int $height + * @return ImageInterface + */ public function newImage(int $width, int $height): ImageInterface; - public function newCore(int $width, int $height); + + /** + * Create new animated image + * + * @param callable $callback + * @return ImageInterface + */ + public function newAnimation(callable $callback): ImageInterface; } diff --git a/src/Interfaces/ModifierInterface.php b/src/Interfaces/ModifierInterface.php index ff6b12a4..8786ae66 100644 --- a/src/Interfaces/ModifierInterface.php +++ b/src/Interfaces/ModifierInterface.php @@ -4,5 +4,11 @@ namespace Intervention\Image\Interfaces; interface ModifierInterface { + /** + * Apply modifications of the current modifier to the given image + * + * @param ImageInterface $image + * @return ImageInterface + */ public function apply(ImageInterface $image): ImageInterface; } diff --git a/src/Interfaces/PointInterface.php b/src/Interfaces/PointInterface.php index 858e2925..56934ce2 100644 --- a/src/Interfaces/PointInterface.php +++ b/src/Interfaces/PointInterface.php @@ -4,6 +4,17 @@ namespace Intervention\Image\Interfaces; interface PointInterface { + /** + * Return x position + * + * @return int + */ public function getX(): int; + + /** + * Return y position + * + * @return int + */ public function getY(): int; } diff --git a/tests/Drivers/Gd/ImageFactoryTest.php b/tests/Drivers/Gd/ImageFactoryTest.php index 38060e45..797be8ad 100644 --- a/tests/Drivers/Gd/ImageFactoryTest.php +++ b/tests/Drivers/Gd/ImageFactoryTest.php @@ -2,7 +2,6 @@ namespace Intervention\Image\Tests\Drivers\Gd; -use GdImage; use Intervention\Image\Drivers\Gd\Image; use Intervention\Image\Drivers\Gd\ImageFactory; use Intervention\Image\Tests\TestCase; @@ -30,11 +29,4 @@ class ImageFactoryTest extends TestCase $this->assertInstanceOf(Image::class, $image); $this->assertEquals(2, $image->count()); } - - public function testNewCore(): void - { - $factory = new ImageFactory(); - $core = $factory->newCore(3, 2); - $this->assertInstanceOf(GdImage::class, $core); - } } diff --git a/tests/Drivers/Imagick/ImageFactoryTest.php b/tests/Drivers/Imagick/ImageFactoryTest.php index 635139e5..feb8e131 100644 --- a/tests/Drivers/Imagick/ImageFactoryTest.php +++ b/tests/Drivers/Imagick/ImageFactoryTest.php @@ -31,7 +31,7 @@ class ImageFactoryTest extends TestCase $this->assertEquals(2, $image->count()); } - public function testNewCore(): void + protected function testNewCore(): void { $factory = new ImageFactory(); $core = $factory->newCore(3, 2);