From 2dbfb53bf8909257e710cf6091d10a9ca7500742 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 2 May 2024 11:03:18 +0200 Subject: [PATCH] Update code for phpstan level 6 (#1342) * Update phpstan checks to level 6 * Add more details doc blocks to meet phpstan level 6 * Fix bug in building decoder chain * Fix type hints --- phpstan.dist.neon | 2 +- src/Collection.php | 35 ++++++++++++++++--- src/Colors/AbstractColor.php | 17 +++++++++ src/Colors/Cmyk/Colorspace.php | 5 +++ src/Colors/Hsl/Colorspace.php | 5 +++ src/Colors/Hsv/Colorspace.php | 5 +++ src/Colors/Rgb/Colorspace.php | 5 +++ .../Rgb/Decoders/HtmlColornameDecoder.php | 5 +++ src/Drivers/AbstractDecoder.php | 10 +++++- src/Drivers/AbstractDriver.php | 4 --- src/Drivers/AbstractFontProcessor.php | 2 +- src/Drivers/AbstractInputHandler.php | 27 +++++++++++--- src/Drivers/Gd/Driver.php | 2 +- src/Drivers/Gd/InputHandler.php | 5 +++ src/Drivers/Gd/Modifiers/FillModifier.php | 6 ++-- src/Drivers/Gd/Modifiers/SharpenModifier.php | 5 +++ src/Drivers/Imagick/Core.php | 3 ++ src/Drivers/Imagick/Driver.php | 2 +- src/Drivers/Imagick/InputHandler.php | 5 +++ .../Imagick/Modifiers/ColorspaceModifier.php | 5 +++ .../Imagick/Modifiers/DrawPolygonModifier.php | 5 +++ .../Imagick/Modifiers/FillModifier.php | 6 ++-- .../Imagick/Modifiers/PixelateModifier.php | 4 +-- .../Imagick/Modifiers/TextModifier.php | 6 ++-- src/Encoders/FileExtensionEncoder.php | 5 +++ src/Encoders/MediaTypeEncoder.php | 5 +++ src/Format.php | 4 +-- src/Geometry/Polygon.php | 10 ++++-- src/Image.php | 3 +- src/Interfaces/CollectionInterface.php | 11 +++--- src/Interfaces/ColorInterface.php | 11 ++++-- src/Interfaces/ColorspaceInterface.php | 2 +- src/Interfaces/CoreInterface.php | 6 ++-- src/Interfaces/DriverInterface.php | 6 ++-- src/Interfaces/ImageInterface.php | 3 ++ src/Interfaces/ImageManagerInterface.php | 2 +- src/Interfaces/SpecializableInterface.php | 2 +- src/ModifierStack.php | 2 +- src/Modifiers/TextModifier.php | 2 +- src/Typography/Line.php | 7 +++- src/Typography/TextBlock.php | 4 +-- 41 files changed, 205 insertions(+), 56 deletions(-) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index a2a6f826..4bf57db2 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,5 +1,5 @@ parameters: - level: 5 + level: 6 paths: - src exceptions: diff --git a/src/Collection.php b/src/Collection.php index 3cb3e334..b2b9e18a 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -10,8 +10,17 @@ use Traversable; use IteratorAggregate; +/** + * @implements IteratorAggregate + */ class Collection implements CollectionInterface, IteratorAggregate, Countable { + /** + * Create new collection object + * + * @param array $items + * @return void + */ public function __construct(protected array $items = []) { } @@ -19,14 +28,19 @@ public function __construct(protected array $items = []) /** * Static constructor * - * @param array $items - * @return self + * @param array $items + * @return self */ public static function create(array $items = []): self { return new self($items); } + /** + * {@inheritdoc} + * + * @see CollectionInterface::has() + */ public function has(int|string $key): bool { return array_key_exists($key, $this->items); @@ -35,13 +49,18 @@ public function has(int|string $key): bool /** * Returns Iterator * - * @return Traversable + * @return Traversable */ public function getIterator(): Traversable { return new ArrayIterator($this->items); } + /** + * {@inheritdoc} + * + * @see CollectionInterface::toArray() + */ public function toArray(): array { return $this->items; @@ -61,7 +80,7 @@ public function count(): int * Append new item to collection * * @param mixed $item - * @return CollectionInterface + * @return CollectionInterface */ public function push($item): CollectionInterface { @@ -154,6 +173,12 @@ public function get(int|string $query, $default = null): mixed return $result; } + /** + * Map each item of collection by given callback + * + * @param callable $callback + * @return self + */ public function map(callable $callback): self { $items = array_map(function ($item) use ($callback) { @@ -167,7 +192,7 @@ public function map(callable $callback): self * Run callback on each item of the collection an remove it if it does not return true * * @param callable $callback - * @return Collection + * @return self */ public function filter(callable $callback): self { diff --git a/src/Colors/AbstractColor.php b/src/Colors/AbstractColor.php index 51e5f40f..e6927885 100644 --- a/src/Colors/AbstractColor.php +++ b/src/Colors/AbstractColor.php @@ -13,14 +13,26 @@ abstract class AbstractColor implements ColorInterface { /** * Color channels + * + * @var array */ protected array $channels; + /** + * {@inheritdoc} + * + * @see ColorInterface::channels() + */ public function channels(): array { return $this->channels; } + /** + * {@inheritdoc} + * + * @see ColorInterface::channel() + */ public function channel(string $classname): ColorChannelInterface { $channels = array_filter($this->channels(), function (ColorChannelInterface $channel) use ($classname) { @@ -34,6 +46,11 @@ public function channel(string $classname): ColorChannelInterface return reset($channels); } + /** + * {@inheritdoc} + * + * @see ColorInterface::normalize() + */ public function normalize(): array { return array_map(function (ColorChannelInterface $channel) { diff --git a/src/Colors/Cmyk/Colorspace.php b/src/Colors/Cmyk/Colorspace.php index 42a3edd2..66b9b496 100644 --- a/src/Colors/Cmyk/Colorspace.php +++ b/src/Colors/Cmyk/Colorspace.php @@ -15,6 +15,11 @@ class Colorspace implements ColorspaceInterface { + /** + * Channel class names of colorspace + * + * @var array + */ public static array $channels = [ Channels\Cyan::class, Channels\Magenta::class, diff --git a/src/Colors/Hsl/Colorspace.php b/src/Colors/Hsl/Colorspace.php index 7d333f8a..2192bc11 100644 --- a/src/Colors/Hsl/Colorspace.php +++ b/src/Colors/Hsl/Colorspace.php @@ -14,6 +14,11 @@ class Colorspace implements ColorspaceInterface { + /** + * Channel class names of colorspace + * + * @var array + */ public static array $channels = [ Channels\Hue::class, Channels\Saturation::class, diff --git a/src/Colors/Hsv/Colorspace.php b/src/Colors/Hsv/Colorspace.php index dd660cf0..d0211052 100644 --- a/src/Colors/Hsv/Colorspace.php +++ b/src/Colors/Hsv/Colorspace.php @@ -14,6 +14,11 @@ class Colorspace implements ColorspaceInterface { + /** + * Channel class names of colorspace + * + * @var array + */ public static array $channels = [ Channels\Hue::class, Channels\Saturation::class, diff --git a/src/Colors/Rgb/Colorspace.php b/src/Colors/Rgb/Colorspace.php index b7e4d4d3..35deb756 100644 --- a/src/Colors/Rgb/Colorspace.php +++ b/src/Colors/Rgb/Colorspace.php @@ -13,6 +13,11 @@ class Colorspace implements ColorspaceInterface { + /** + * Channel class names of colorspace + * + * @var array + */ public static array $channels = [ Channels\Red::class, Channels\Green::class, diff --git a/src/Colors/Rgb/Decoders/HtmlColornameDecoder.php b/src/Colors/Rgb/Decoders/HtmlColornameDecoder.php index 3dc75655..2c64f2ba 100644 --- a/src/Colors/Rgb/Decoders/HtmlColornameDecoder.php +++ b/src/Colors/Rgb/Decoders/HtmlColornameDecoder.php @@ -11,6 +11,11 @@ class HtmlColornameDecoder extends HexColorDecoder implements DecoderInterface { + /** + * Available color names and their corresponding hex codes + * + * @var array + */ protected static array $names = [ 'lightsalmon' => '#ffa07a', 'salmon' => '#fa8072', diff --git a/src/Drivers/AbstractDecoder.php b/src/Drivers/AbstractDecoder.php index 5f5ad47b..4d736663 100644 --- a/src/Drivers/AbstractDecoder.php +++ b/src/Drivers/AbstractDecoder.php @@ -100,7 +100,7 @@ protected function isFile(mixed $input): bool * data or a file path. * * @param string $path_or_data - * @return CollectionInterface + * @return CollectionInterface */ protected function extractExifData(string $path_or_data): CollectionInterface { @@ -156,9 +156,17 @@ protected function parseDataUri(mixed $input): object return new class ($matches, $result) { + /** + * @var array + */ private array $matches; private int|false $result; + /** + * @param array $matches + * @param int|false $result + * @return void + */ public function __construct(array $matches, int|false $result) { $this->matches = $matches; diff --git a/src/Drivers/AbstractDriver.php b/src/Drivers/AbstractDriver.php index df8d8e64..bbef4608 100644 --- a/src/Drivers/AbstractDriver.php +++ b/src/Drivers/AbstractDriver.php @@ -6,7 +6,6 @@ use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\NotSupportedException; -use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DriverInterface; @@ -74,9 +73,6 @@ public function specializeMultiple(array $objects): array match (true) { is_string($object) => new $object(), is_object($object) => $object, - default => throw new RuntimeException( - 'Specializable item must be either a class name or an object.' - ) } ); }, $objects); diff --git a/src/Drivers/AbstractFontProcessor.php b/src/Drivers/AbstractFontProcessor.php index 625d86fb..e7817af8 100644 --- a/src/Drivers/AbstractFontProcessor.php +++ b/src/Drivers/AbstractFontProcessor.php @@ -114,7 +114,7 @@ protected function wrapTextBlock(TextBlock $block, FontInterface $font): TextBlo * @param Line $line * @param FontInterface $font * @throws FontException - * @return array + * @return array */ protected function wrapLine(Line $line, FontInterface $font): array { diff --git a/src/Drivers/AbstractInputHandler.php b/src/Drivers/AbstractInputHandler.php index b4701c50..bb079546 100644 --- a/src/Drivers/AbstractInputHandler.php +++ b/src/Drivers/AbstractInputHandler.php @@ -6,13 +6,25 @@ use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Interfaces\ColorInterface; +use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\InputHandlerInterface; abstract class AbstractInputHandler implements InputHandlerInterface { + /** + * Decoder classnames in hierarchical order + * + * @var array + */ protected array $decoders = []; + /** + * Create new input handler instance with given decoder classnames + * + * @param array $decoders + * @return void + */ public function __construct(array $decoders = []) { $this->decoders = count($decoders) ? $decoders : $this->decoders; @@ -40,13 +52,18 @@ protected function chain(): AbstractDecoder throw new DecoderException('No decoders found in ' . $this::class); } - // get instance of last decoder in stack - list($classname) = array_slice(array_reverse($this->decoders), 0, 1); - $chain = new $classname(); + // get last decoder in stack + list($decoder) = array_slice(array_reverse($this->decoders), 0, 1); + $chain = ($decoder instanceof DecoderInterface) ? $decoder : new $decoder(); + + // only accept DecoderInterface + if (!($chain instanceof DecoderInterface)) { + throw new DecoderException('Decoder must implement in ' . DecoderInterface::class); + } // build decoder chain - foreach (array_slice(array_reverse($this->decoders), 1) as $classname) { - $chain = new $classname($chain); + foreach (array_slice(array_reverse($this->decoders), 1) as $decoder) { + $chain = ($decoder instanceof DecoderInterface) ? new ($decoder::class)($chain) : new $decoder($chain); } return $chain; diff --git a/src/Drivers/Gd/Driver.php b/src/Drivers/Gd/Driver.php index a2d917f6..090faebd 100644 --- a/src/Drivers/Gd/Driver.php +++ b/src/Drivers/Gd/Driver.php @@ -87,7 +87,7 @@ public function __construct( /** * @throws RuntimeException */ - public function add($source, float $delay = 1): self + public function add(mixed $source, float $delay = 1): self { $this->core->add( $this->driver->handleInput($source)->core()->first()->setDelay($delay) diff --git a/src/Drivers/Gd/InputHandler.php b/src/Drivers/Gd/InputHandler.php index 62eec6a4..d1628935 100644 --- a/src/Drivers/Gd/InputHandler.php +++ b/src/Drivers/Gd/InputHandler.php @@ -24,6 +24,11 @@ class InputHandler extends AbstractInputHandler { + /** + * Decoders in hierarchical order + * + * @var array + */ protected array $decoders = [ NativeObjectDecoder::class, ImageObjectDecoder::class, diff --git a/src/Drivers/Gd/Modifiers/FillModifier.php b/src/Drivers/Gd/Modifiers/FillModifier.php index 84f7ca6d..0fe860fa 100644 --- a/src/Drivers/Gd/Modifiers/FillModifier.php +++ b/src/Drivers/Gd/Modifiers/FillModifier.php @@ -4,8 +4,8 @@ namespace Intervention\Image\Drivers\Gd\Modifiers; -use Intervention\Image\Drivers\Gd\Frame; use Intervention\Image\Exceptions\RuntimeException; +use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SpecializedInterface; use Intervention\Image\Modifiers\FillModifier as GenericFillModifier; @@ -37,7 +37,7 @@ private function color(ImageInterface $image): int ); } - private function floodFillWithColor(Frame $frame, int $color): void + private function floodFillWithColor(FrameInterface $frame, int $color): void { imagefill( $frame->native(), @@ -47,7 +47,7 @@ private function floodFillWithColor(Frame $frame, int $color): void ); } - private function fillAllWithColor(Frame $frame, int $color): void + private function fillAllWithColor(FrameInterface $frame, int $color): void { imagealphablending($frame->native(), true); imagefilledrectangle( diff --git a/src/Drivers/Gd/Modifiers/SharpenModifier.php b/src/Drivers/Gd/Modifiers/SharpenModifier.php index decb6d75..a1c59397 100644 --- a/src/Drivers/Gd/Modifiers/SharpenModifier.php +++ b/src/Drivers/Gd/Modifiers/SharpenModifier.php @@ -20,6 +20,11 @@ public function apply(ImageInterface $image): ImageInterface return $image; } + /** + * Create matrix to be used by imageconvolution() + * + * @return array> + */ private function matrix(): array { $min = $this->amount >= 10 ? $this->amount * -0.01 : 0; diff --git a/src/Drivers/Imagick/Core.php b/src/Drivers/Imagick/Core.php index 67a78b9c..e0bc94e9 100644 --- a/src/Drivers/Imagick/Core.php +++ b/src/Drivers/Imagick/Core.php @@ -12,6 +12,9 @@ use Intervention\Image\Interfaces\CollectionInterface; use Intervention\Image\Interfaces\FrameInterface; +/** + * @implements Iterator + */ class Core implements CoreInterface, Iterator { protected int $iteratorIndex = 0; diff --git a/src/Drivers/Imagick/Driver.php b/src/Drivers/Imagick/Driver.php index 65b3686f..2c01f83b 100644 --- a/src/Drivers/Imagick/Driver.php +++ b/src/Drivers/Imagick/Driver.php @@ -89,7 +89,7 @@ public function __construct( /** * @throws RuntimeException */ - public function add($source, float $delay = 1): self + public function add(mixed $source, float $delay = 1): self { $native = $this->driver->handleInput($source)->core()->native(); $native->setImageDelay(intval(round($delay * 100))); diff --git a/src/Drivers/Imagick/InputHandler.php b/src/Drivers/Imagick/InputHandler.php index de590ff9..5c7b748b 100644 --- a/src/Drivers/Imagick/InputHandler.php +++ b/src/Drivers/Imagick/InputHandler.php @@ -24,6 +24,11 @@ class InputHandler extends AbstractInputHandler { + /** + * Decoders in hierarchical order + * + * @var array + */ protected array $decoders = [ NativeObjectDecoder::class, ImageObjectDecoder::class, diff --git a/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php b/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php index 9ca66a8b..37e10200 100644 --- a/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php +++ b/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php @@ -15,6 +15,11 @@ class ColorspaceModifier extends GenericColorspaceModifier implements SpecializedInterface { + /** + * Map own colorspace classname to Imagick classnames + * + * @var array + */ protected static array $mapping = [ RgbColorspace::class => Imagick::COLORSPACE_SRGB, CmykColorspace::class => Imagick::COLORSPACE_CMYK, diff --git a/src/Drivers/Imagick/Modifiers/DrawPolygonModifier.php b/src/Drivers/Imagick/Modifiers/DrawPolygonModifier.php index 443722e9..1d66b9e4 100644 --- a/src/Drivers/Imagick/Modifiers/DrawPolygonModifier.php +++ b/src/Drivers/Imagick/Modifiers/DrawPolygonModifier.php @@ -45,6 +45,11 @@ public function apply(ImageInterface $image): ImageInterface return $image; } + /** + * Return points of drawable in processable form for ImagickDraw + * + * @return array> + */ private function points(): array { $points = []; diff --git a/src/Drivers/Imagick/Modifiers/FillModifier.php b/src/Drivers/Imagick/Modifiers/FillModifier.php index eb515e4e..0eee743d 100644 --- a/src/Drivers/Imagick/Modifiers/FillModifier.php +++ b/src/Drivers/Imagick/Modifiers/FillModifier.php @@ -7,7 +7,7 @@ use Imagick; use ImagickDraw; use ImagickPixel; -use Intervention\Image\Drivers\Imagick\Frame; +use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SpecializedInterface; use Intervention\Image\Modifiers\FillModifier as ModifiersFillModifier; @@ -32,7 +32,7 @@ public function apply(ImageInterface $image): ImageInterface return $image; } - private function floodFillWithColor(Frame $frame, ImagickPixel $pixel): void + private function floodFillWithColor(FrameInterface $frame, ImagickPixel $pixel): void { $target = $frame->native()->getImagePixelColor( $this->position->x(), @@ -50,7 +50,7 @@ private function floodFillWithColor(Frame $frame, ImagickPixel $pixel): void ); } - private function fillAllWithColor(Frame $frame, ImagickPixel $pixel): void + private function fillAllWithColor(FrameInterface $frame, ImagickPixel $pixel): void { $draw = new ImagickDraw(); $draw->setFillColor($pixel); diff --git a/src/Drivers/Imagick/Modifiers/PixelateModifier.php b/src/Drivers/Imagick/Modifiers/PixelateModifier.php index 02b5d068..e79eb420 100644 --- a/src/Drivers/Imagick/Modifiers/PixelateModifier.php +++ b/src/Drivers/Imagick/Modifiers/PixelateModifier.php @@ -4,7 +4,7 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers; -use Intervention\Image\Drivers\Imagick\Frame; +use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SpecializedInterface; use Intervention\Image\Modifiers\PixelateModifier as GenericPixelateModifier; @@ -20,7 +20,7 @@ public function apply(ImageInterface $image): ImageInterface return $image; } - protected function pixelateFrame(Frame $frame): void + protected function pixelateFrame(FrameInterface $frame): void { $size = $frame->size(); diff --git a/src/Drivers/Imagick/Modifiers/TextModifier.php b/src/Drivers/Imagick/Modifiers/TextModifier.php index 60b85189..51f30bf7 100644 --- a/src/Drivers/Imagick/Modifiers/TextModifier.php +++ b/src/Drivers/Imagick/Modifiers/TextModifier.php @@ -8,12 +8,12 @@ use ImagickDrawException; use ImagickException; use Intervention\Image\Drivers\Imagick\FontProcessor; -use Intervention\Image\Drivers\Imagick\Frame; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\FontException; use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Geometry\Point; use Intervention\Image\Interfaces\FontInterface; +use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SpecializedInterface; use Intervention\Image\Modifiers\TextModifier as GenericTextModifier; @@ -109,14 +109,14 @@ private function imagickDrawStroke(ImageInterface $image, FontInterface $font): * Maybe draw given line of text on frame instance depending on given * ImageDraw instance. Optionally move line position by given offset. * - * @param Frame $frame + * @param FrameInterface $frame * @param Line $textline * @param null|ImagickDraw $draw * @param Point $offset * @return void */ private function maybeDrawTextline( - Frame $frame, + FrameInterface $frame, Line $textline, ?ImagickDraw $draw = null, Point $offset = new Point(), diff --git a/src/Encoders/FileExtensionEncoder.php b/src/Encoders/FileExtensionEncoder.php index 828caced..9db37ed5 100644 --- a/src/Encoders/FileExtensionEncoder.php +++ b/src/Encoders/FileExtensionEncoder.php @@ -13,6 +13,11 @@ class FileExtensionEncoder extends AutoEncoder { + /** + * Encoder options + * + * @var array + */ protected array $options = []; /** diff --git a/src/Encoders/MediaTypeEncoder.php b/src/Encoders/MediaTypeEncoder.php index 28022743..005e09d6 100644 --- a/src/Encoders/MediaTypeEncoder.php +++ b/src/Encoders/MediaTypeEncoder.php @@ -14,6 +14,11 @@ class MediaTypeEncoder extends AbstractEncoder { + /** + * Encoder options + * + * @var array + */ protected array $options = []; /** diff --git a/src/Format.php b/src/Format.php index da48a116..1d28296c 100644 --- a/src/Format.php +++ b/src/Format.php @@ -67,7 +67,7 @@ public static function create(string|self|MediaType|FileExtension $identifier): /** * Return the possible media (MIME) types for the current format * - * @return array + * @return array */ public function mediaTypes(): array { @@ -79,7 +79,7 @@ public function mediaTypes(): array /** * Return the possible file extension for the current format * - * @return array + * @return array */ public function fileExtensions(): array { diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index 6ecb8c9b..3f5e6d3e 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -14,6 +14,10 @@ use Intervention\Image\Interfaces\DrawableInterface; use Intervention\Image\Interfaces\PointInterface; +/** + * @implements IteratorAggregate + * @implements ArrayAccess + */ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface { use HasBorder; @@ -22,7 +26,7 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte /** * Create new polygon instance * - * @param array $points + * @param array $points * @param PointInterface $pivot * @return void */ @@ -45,7 +49,7 @@ public function position(): PointInterface /** * Implement iteration through all points of polygon * - * @return Traversable + * @return Traversable */ public function getIterator(): Traversable { @@ -427,7 +431,7 @@ public function movePointsY(int $amount): self /** * Return array of all x/y values of all points of polygon * - * @return array + * @return array */ public function toArray(): array { diff --git a/src/Image.php b/src/Image.php index e261f731..0c1731c7 100644 --- a/src/Image.php +++ b/src/Image.php @@ -44,6 +44,7 @@ use Intervention\Image\Interfaces\EncodedImageInterface; use Intervention\Image\Interfaces\EncoderInterface; use Intervention\Image\Interfaces\FontInterface; +use Intervention\Image\Interfaces\FrameInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\ProfileInterface; @@ -183,7 +184,7 @@ public function count(): int /** * Implementation of IteratorAggregate * - * @return Traversable + * @return Traversable */ public function getIterator(): Traversable { diff --git a/src/Interfaces/CollectionInterface.php b/src/Interfaces/CollectionInterface.php index b8576424..376072f4 100644 --- a/src/Interfaces/CollectionInterface.php +++ b/src/Interfaces/CollectionInterface.php @@ -6,6 +6,9 @@ use Traversable; +/** + * @extends Traversable + */ interface CollectionInterface extends Traversable { /** @@ -20,7 +23,7 @@ public function has(int|string $key): bool; * Add item to collection * * @param mixed $item - * @return CollectionInterface + * @return CollectionInterface */ public function push($item): self; @@ -66,14 +69,14 @@ public function count(): int; /** * Empty collection * - * @return CollectionInterface + * @return CollectionInterface */ public function empty(): self; /** * Transform collection as array * - * @return array + * @return array */ public function toArray(): array; @@ -82,7 +85,7 @@ public function toArray(): array; * * @param int $offset * @param null|int $length - * @return CollectionInterface + * @return CollectionInterface */ public function slice(int $offset, ?int $length = 0): self; } diff --git a/src/Interfaces/ColorInterface.php b/src/Interfaces/ColorInterface.php index 9f66ed24..33c44bc7 100644 --- a/src/Interfaces/ColorInterface.php +++ b/src/Interfaces/ColorInterface.php @@ -43,7 +43,7 @@ public function toString(): string; /** * Cast color object to array * - * @return array + * @return array */ public function toArray(): array; @@ -57,10 +57,17 @@ public function toHex(string $prefix = ''): string; /** * Return array of all color channels * - * @return array + * @return array */ public function channels(): array; + /** + * Return array of normalized color channel values + * + * @return array + */ + public function normalize(): array; + /** * Retrieve the color channel by its classname * diff --git a/src/Interfaces/ColorspaceInterface.php b/src/Interfaces/ColorspaceInterface.php index 21885d59..f7fc0a7c 100644 --- a/src/Interfaces/ColorspaceInterface.php +++ b/src/Interfaces/ColorspaceInterface.php @@ -17,7 +17,7 @@ public function importColor(ColorInterface $color): ColorInterface; /** * Create new color in colorspace from given normalized channel values * - * @param array $normalized + * @param array $normalized * @return ColorInterface */ public function colorFromNormalized(array $normalized): ColorInterface; diff --git a/src/Interfaces/CoreInterface.php b/src/Interfaces/CoreInterface.php index f8ac19f6..5374f736 100644 --- a/src/Interfaces/CoreInterface.php +++ b/src/Interfaces/CoreInterface.php @@ -20,7 +20,7 @@ public function native(): mixed; * Set driver's representation of the image core. * * @param mixed $native - * @return CoreInterface + * @return CoreInterface */ public function setNative(mixed $native): self; @@ -44,7 +44,7 @@ public function frame(int $position): FrameInterface; * Add new frame to core * * @param FrameInterface $frame - * @return CoreInterface + * @return CoreInterface */ public function add(FrameInterface $frame): self; @@ -60,7 +60,7 @@ public function loops(): int; * value of 0 means infinite repetition. * * @param int $loops - * @return CoreInterface + * @return CoreInterface */ public function setLoops(int $loops): self; diff --git a/src/Interfaces/DriverInterface.php b/src/Interfaces/DriverInterface.php index cbf68cc5..9ddabb2c 100644 --- a/src/Interfaces/DriverInterface.php +++ b/src/Interfaces/DriverInterface.php @@ -34,8 +34,8 @@ public function specialize( /** * Resolve array of classnames or objects into their specialized version for the current driver * - * @param array $objects - * @return array + * @param array $objects + * @return array */ public function specializeMultiple(array $objects): array; @@ -61,7 +61,7 @@ public function createAnimation(callable $init): ImageInterface; * Handle given input by decoding it to ImageInterface or ColorInterface * * @param mixed $input - * @param array $decoders + * @param array $decoders * @throws RuntimeException * @return ImageInterface|ColorInterface */ diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index 9ce7484c..4315ac8d 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -13,6 +13,9 @@ use Intervention\Image\Origin; use IteratorAggregate; +/** + * @extends IteratorAggregate + */ interface ImageInterface extends IteratorAggregate, Countable { /** diff --git a/src/Interfaces/ImageManagerInterface.php b/src/Interfaces/ImageManagerInterface.php index 140b895d..33278194 100644 --- a/src/Interfaces/ImageManagerInterface.php +++ b/src/Interfaces/ImageManagerInterface.php @@ -44,7 +44,7 @@ public function create(int $width, int $height): ImageInterface; * * @link https://image.intervention.io/v3/basics/instantiation#reading-images * @param mixed $input - * @param string|array|DecoderInterface $decoders + * @param string|array|DecoderInterface $decoders * @throws RuntimeException * @return ImageInterface */ diff --git a/src/Interfaces/SpecializableInterface.php b/src/Interfaces/SpecializableInterface.php index ef71ffc7..e04ee6dc 100644 --- a/src/Interfaces/SpecializableInterface.php +++ b/src/Interfaces/SpecializableInterface.php @@ -10,7 +10,7 @@ interface SpecializableInterface * Return an array of constructor parameters, which is usually passed from * the generic object to the specialized object * - * @return array + * @return array */ public function specializable(): array; diff --git a/src/ModifierStack.php b/src/ModifierStack.php index 97705dc4..8e58cb3a 100644 --- a/src/ModifierStack.php +++ b/src/ModifierStack.php @@ -12,7 +12,7 @@ class ModifierStack implements ModifierInterface /** * Create new modifier stack object with an array of modifier objects * - * @param array $modifiers + * @param array $modifiers * @return void */ public function __construct(protected array $modifiers) diff --git a/src/Modifiers/TextModifier.php b/src/Modifiers/TextModifier.php index 98f7e94e..3a72dcfc 100644 --- a/src/Modifiers/TextModifier.php +++ b/src/Modifiers/TextModifier.php @@ -69,7 +69,7 @@ protected function strokeColor(): ColorInterface * Return array of offset points to draw text stroke effect below the actual text * * @param FontInterface $font - * @return array + * @return array */ protected function strokeOffsets(FontInterface $font): array { diff --git a/src/Typography/Line.php b/src/Typography/Line.php index 52e2724a..21493e32 100644 --- a/src/Typography/Line.php +++ b/src/Typography/Line.php @@ -11,10 +11,15 @@ use IteratorAggregate; use Traversable; +/** + * @implements IteratorAggregate + */ class Line implements IteratorAggregate, Countable { /** * Segments (usually individual words including punctuation marks) of the line + * + * @var array */ protected array $segments = []; @@ -50,7 +55,7 @@ public function add(string $word): self /** * Returns Iterator * - * @return Traversable + * @return Traversable */ public function getIterator(): Traversable { diff --git a/src/Typography/TextBlock.php b/src/Typography/TextBlock.php index 46252d64..d95be4f8 100644 --- a/src/Typography/TextBlock.php +++ b/src/Typography/TextBlock.php @@ -18,7 +18,7 @@ public function __construct(string $text) /** * Return array of lines in text block * - * @return array + * @return array */ public function lines(): array { @@ -28,7 +28,7 @@ public function lines(): array /** * Set lines of the text block * - * @param array $lines + * @param array $lines * @return self */ public function setLines(array $lines): self