From 8bfadfea5c7258f4295c2907bcc7498b4825d1c8 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 3 Aug 2025 10:35:32 +0200 Subject: [PATCH] Refactor __toString interface declarations --- changelog.md | 1 + src/Interfaces/ColorChannelInterface.php | 10 +++------- src/Interfaces/ColorInterface.php | 8 ++------ src/Interfaces/FileInterface.php | 10 +++------- src/Interfaces/ProfileInterface.php | 13 ++++++++++--- src/Interfaces/ResolutionInterface.php | 9 +++------ 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/changelog.md b/changelog.md index 133b32e7..67785e1b 100644 --- a/changelog.md +++ b/changelog.md @@ -26,3 +26,4 @@ - Signature of ImageInterface::crop() changed `offset_x` is no `x` and `offset_y` is now `y` - Signature of ImageInterface::place() changed `offset_x` is no `x` and `offset_y` is now `y` - EncodedImageInterface::toDataUri() now returns `DataUriInterface` instead of `string“ +- ProfileInterface requires implementation of `::fromPath()` diff --git a/src/Interfaces/ColorChannelInterface.php b/src/Interfaces/ColorChannelInterface.php index ed705570..ff27ac04 100644 --- a/src/Interfaces/ColorChannelInterface.php +++ b/src/Interfaces/ColorChannelInterface.php @@ -5,8 +5,9 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; use Intervention\Image\Exceptions\ColorException; +use Stringable; -interface ColorChannelInterface +interface ColorChannelInterface extends Stringable { /** * Create new instance by either value or normalized value @@ -46,12 +47,7 @@ interface ColorChannelInterface public function max(): int; /** - * Cast color channel's value to string + * Transform color channel's value to string */ public function toString(): string; - - /** - * Cast color channel's value to string - */ - public function __toString(): string; } diff --git a/src/Interfaces/ColorInterface.php b/src/Interfaces/ColorInterface.php index 82ab7eff..e85196f8 100644 --- a/src/Interfaces/ColorInterface.php +++ b/src/Interfaces/ColorInterface.php @@ -6,8 +6,9 @@ namespace Intervention\Image\Interfaces; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\RuntimeException; +use Stringable; -interface ColorInterface +interface ColorInterface extends Stringable { /** * Static color factory method that takes any supported color format @@ -79,9 +80,4 @@ interface ColorInterface * Determine whether the current color is completely transparent */ public function isClear(): bool; - - /** - * Cast color object to string - */ - public function __toString(): string; } diff --git a/src/Interfaces/FileInterface.php b/src/Interfaces/FileInterface.php index c6943223..b354c1e1 100644 --- a/src/Interfaces/FileInterface.php +++ b/src/Interfaces/FileInterface.php @@ -5,8 +5,9 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; use Intervention\Image\Exceptions\RuntimeException; +use Stringable; -interface FileInterface +interface FileInterface extends Stringable { /** * Save data in given path in file system @@ -28,12 +29,7 @@ interface FileInterface public function size(): int; /** - * Turn encoded data into string + * Transform file object into string */ public function toString(): string; - - /** - * Cast encoded data into string - */ - public function __toString(): string; } diff --git a/src/Interfaces/ProfileInterface.php b/src/Interfaces/ProfileInterface.php index a10f5de8..fc40e11d 100644 --- a/src/Interfaces/ProfileInterface.php +++ b/src/Interfaces/ProfileInterface.php @@ -4,10 +4,17 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; -interface ProfileInterface +use Stringable; + +interface ProfileInterface extends Stringable { /** - * Cast color profile object to string + * Create profile object from path in file system */ - public function __toString(): string; + public static function fromPath(string $path): self; + + /** + * Transform object to string + */ + public function toString(): string; } diff --git a/src/Interfaces/ResolutionInterface.php b/src/Interfaces/ResolutionInterface.php index ccdd5190..e4726bf2 100644 --- a/src/Interfaces/ResolutionInterface.php +++ b/src/Interfaces/ResolutionInterface.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace Intervention\Image\Interfaces; -interface ResolutionInterface +use Stringable; + +interface ResolutionInterface extends Stringable { /** * Return resolution of x-axis @@ -45,9 +47,4 @@ interface ResolutionInterface * Transform object to string */ public function toString(): string; - - /** - * Cast object to string - */ - public function __toString(): string; }