From f73d1a25919352325ad1d724f2f9202912ec9a89 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 21 Oct 2023 15:47:08 +0200 Subject: [PATCH] Add doc blocks --- src/Colors/Rgb/Channels/Red.php | 50 ++++++++++++++++++++++++ src/Interfaces/ColorChannelInterface.php | 42 ++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/src/Colors/Rgb/Channels/Red.php b/src/Colors/Rgb/Channels/Red.php index da8bf81b..510d628c 100644 --- a/src/Colors/Rgb/Channels/Red.php +++ b/src/Colors/Rgb/Channels/Red.php @@ -9,31 +9,71 @@ class Red implements ColorChannelInterface { protected int $value; + /** + * Create and validate new instance + * + * @param int $value + */ public function __construct(int $value) { $this->value = $this->validate($value); } + /** + * Alias of value() + * + * @return int + */ + public function toInt(): int + { + return $this->value; + } + + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::value() + */ public function value(): int { return $this->value; } + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::normalize() + */ public function normalize($precision = 32): float { return round($this->value() / $this->max(), $precision); } + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::min() + */ public function min(): int { return 0; } + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::max() + */ public function max(): int { return 255; } + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::validate() + */ public function validate(mixed $value): mixed { if ($value < $this->min() || $value > $this->max()) { @@ -43,11 +83,21 @@ class Red implements ColorChannelInterface return $value; } + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::toString() + */ public function toString(): string { return (string) $this->value(); } + /** + * {@inheritdoc} + * + * @see ColorChannelInterface::__toString() + */ public function __toString(): string { return $this->toString(); diff --git a/src/Interfaces/ColorChannelInterface.php b/src/Interfaces/ColorChannelInterface.php index 6c3c7ce8..7c061ee1 100644 --- a/src/Interfaces/ColorChannelInterface.php +++ b/src/Interfaces/ColorChannelInterface.php @@ -4,11 +4,53 @@ namespace Intervention\Image\Interfaces; interface ColorChannelInterface { + /** + * Return color channels integer value + * + * @return int + */ public function value(): int; + + /** + * Return the channels value normalized to a float value form 0 to 1 by its range + * + * @return float + */ public function normalize(int $precision = 32): float; + + /** + * Throw exception if the given value is not applicable for channel + * otherwise the value is returned unchanged. + * + * @return mixed + */ public function validate(mixed $value): mixed; + + /** + * Return the the minimal possible value of the color channel + * + * @return int + */ public function min(): int; + + /* + * Return the the maximal possible value of the color channel + * + * @return int + */ public function max(): int; + + /** + * Cast color channel's value to string + * + * @return string + */ public function toString(): string; + + /** + * Cast color channel's value to string + * + * @return string + */ public function __toString(): string; }