diff --git a/psalm.xml b/psalm.xml
index a4a4d73..ad25b18 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -16,5 +16,6 @@
+
diff --git a/src/Alpha.php b/src/Alpha.php
index 2fae613..22b7aeb 100644
--- a/src/Alpha.php
+++ b/src/Alpha.php
@@ -24,6 +24,7 @@ private function __construct(float $value)
/**
* @psalm-pure
*/
+ #[\NoDiscard]
public static function max(): self
{
return new self(1);
@@ -34,6 +35,7 @@ public static function max(): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(float $value): Attempt
{
return Attempt::of(static fn() => new self($value));
@@ -44,6 +46,7 @@ public static function of(float $value): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromHexadecimal(string $hex): Attempt
{
if (\mb_strlen($hex) === 1) {
@@ -53,6 +56,7 @@ public static function fromHexadecimal(string $hex): Attempt
return self::of(\round(\hexdec($hex) / 255, 2));
}
+ #[\NoDiscard]
public function add(self $alpha): self
{
return new self(
@@ -63,6 +67,7 @@ public function add(self $alpha): self
);
}
+ #[\NoDiscard]
public function subtract(self $alpha): self
{
return new self(
@@ -73,26 +78,31 @@ public function subtract(self $alpha): self
);
}
+ #[\NoDiscard]
public function equals(self $alpha): bool
{
return $this->value === $alpha->toFloat();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 1.0;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0.0;
}
+ #[\NoDiscard]
public function toFloat(): float
{
return $this->value;
}
+ #[\NoDiscard]
public function toHexadecimal(): string
{
return \str_pad(
@@ -105,6 +115,7 @@ public function toHexadecimal(): string
);
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/Black.php b/src/Black.php
index 66ac6f6..f77e4db 100644
--- a/src/Black.php
+++ b/src/Black.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function add(self $black): self
{
return new self(
@@ -52,6 +55,7 @@ public function add(self $black): self
);
}
+ #[\NoDiscard]
public function subtract(self $black): self
{
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $black): self
);
}
+ #[\NoDiscard]
public function equals(self $black): bool
{
return $this->value === $black->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 100;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/Blue.php b/src/Blue.php
index 69e4231..23e7c6d 100644
--- a/src/Blue.php
+++ b/src/Blue.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 255> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 255) {
@@ -47,6 +49,7 @@ public static function of(int $value): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromHexadecimal(string $hex): Attempt
{
if (\mb_strlen($hex) === 1) {
@@ -59,6 +62,7 @@ public static function fromHexadecimal(string $hex): Attempt
/**
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromIntensity(Intensity $intensity): Attempt
{
return self::of(
@@ -66,6 +70,7 @@ public static function fromIntensity(Intensity $intensity): Attempt
);
}
+ #[\NoDiscard]
public function add(self $blue): self
{
return new self(
@@ -76,6 +81,7 @@ public function add(self $blue): self
);
}
+ #[\NoDiscard]
public function subtract(self $blue): self
{
return new self(
@@ -86,16 +92,19 @@ public function subtract(self $blue): self
);
}
+ #[\NoDiscard]
public function equals(self $blue): bool
{
return $this->integer === $blue->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->integer === 255;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->integer === 0;
@@ -104,11 +113,13 @@ public function atMinimum(): bool
/**
* @return int<0, 255>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->integer;
}
+ #[\NoDiscard]
public function toString(): string
{
return \str_pad(
diff --git a/src/CMYKA.php b/src/CMYKA.php
index 472ad54..80ce9d7 100644
--- a/src/CMYKA.php
+++ b/src/CMYKA.php
@@ -29,6 +29,7 @@ private function __construct(
/**
* @psalm-pure
*/
+ #[\NoDiscard]
public static function from(
Cyan $cyan,
Magenta $magenta,
@@ -44,6 +45,7 @@ public static function from(
*
* @throws \Exception
*/
+ #[\NoDiscard]
public static function of(string $colour): self
{
return self::attempt($colour)->unwrap();
@@ -54,6 +56,7 @@ public static function of(string $colour): self
*
* @return Maybe
*/
+ #[\NoDiscard]
public static function maybe(string $colour): Maybe
{
return self::attempt($colour)->maybe();
@@ -64,6 +67,7 @@ public static function maybe(string $colour): Maybe
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function attempt(string $colour): Attempt
{
$colour = Str::of($colour)->trim();
@@ -73,31 +77,37 @@ public static function attempt(string $colour): Attempt
);
}
+ #[\NoDiscard]
public function cyan(): Cyan
{
return $this->cyan;
}
+ #[\NoDiscard]
public function magenta(): Magenta
{
return $this->magenta;
}
+ #[\NoDiscard]
public function yellow(): Yellow
{
return $this->yellow;
}
+ #[\NoDiscard]
public function black(): Black
{
return $this->black;
}
+ #[\NoDiscard]
public function alpha(): Alpha
{
return $this->alpha;
}
+ #[\NoDiscard]
public function addCyan(Cyan $cyan): self
{
return new self(
@@ -109,6 +119,7 @@ public function addCyan(Cyan $cyan): self
);
}
+ #[\NoDiscard]
public function subtractCyan(Cyan $cyan): self
{
return new self(
@@ -120,6 +131,7 @@ public function subtractCyan(Cyan $cyan): self
);
}
+ #[\NoDiscard]
public function addMagenta(Magenta $magenta): self
{
return new self(
@@ -131,6 +143,7 @@ public function addMagenta(Magenta $magenta): self
);
}
+ #[\NoDiscard]
public function subtractMagenta(Magenta $magenta): self
{
return new self(
@@ -142,6 +155,7 @@ public function subtractMagenta(Magenta $magenta): self
);
}
+ #[\NoDiscard]
public function addYellow(Yellow $yellow): self
{
return new self(
@@ -153,6 +167,7 @@ public function addYellow(Yellow $yellow): self
);
}
+ #[\NoDiscard]
public function subtractYellow(Yellow $yellow): self
{
return new self(
@@ -164,6 +179,7 @@ public function subtractYellow(Yellow $yellow): self
);
}
+ #[\NoDiscard]
public function addBlack(Black $black): self
{
return new self(
@@ -175,6 +191,7 @@ public function addBlack(Black $black): self
);
}
+ #[\NoDiscard]
public function subtractBlack(Black $black): self
{
return new self(
@@ -186,6 +203,7 @@ public function subtractBlack(Black $black): self
);
}
+ #[\NoDiscard]
public function addAlpha(Alpha $alpha): self
{
return new self(
@@ -197,6 +215,7 @@ public function addAlpha(Alpha $alpha): self
);
}
+ #[\NoDiscard]
public function subtractAlpha(Alpha $alpha): self
{
return new self(
@@ -208,6 +227,7 @@ public function subtractAlpha(Alpha $alpha): self
);
}
+ #[\NoDiscard]
public function equals(self $cmyka): bool
{
return $this->cyan->equals($cmyka->cyan()) &&
@@ -217,6 +237,7 @@ public function equals(self $cmyka): bool
$this->alpha->equals($cmyka->alpha());
}
+ #[\NoDiscard]
public function toRGBA(): RGBA
{
$cyan = $this->cyan->toInt() / 100;
@@ -236,16 +257,19 @@ public function toRGBA(): RGBA
);
}
+ #[\NoDiscard]
public function toHSLA(): HSLA
{
return $this->toRGBA()->toHSLA();
}
+ #[\NoDiscard]
public function toCMYKA(): self
{
return $this;
}
+ #[\NoDiscard]
public function toString(): string
{
if ($this->alpha->atMaximum()) {
diff --git a/src/Colour.php b/src/Colour.php
index 1e79f79..28c2c3f 100644
--- a/src/Colour.php
+++ b/src/Colour.php
@@ -119,6 +119,7 @@ enum Colour
*
* @throws \Exception
*/
+ #[\NoDiscard]
public static function of(string $colour): RGBA|HSLA|CMYKA
{
return self::attempt($colour)->unwrap();
@@ -129,6 +130,7 @@ public static function of(string $colour): RGBA|HSLA|CMYKA
*
* @return Maybe
*/
+ #[\NoDiscard]
public static function maybe(string $colour): Maybe
{
return self::attempt($colour)->maybe();
@@ -139,6 +141,7 @@ public static function maybe(string $colour): Maybe
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function attempt(string $colour): Attempt
{
return RGBA::attempt($colour)
@@ -149,6 +152,7 @@ public static function attempt(string $colour): Attempt
/**
* @see http://www.w3schools.com/colors/colors_names.asp
*/
+ #[\NoDiscard]
public function toRGBA(): RGBA
{
return match ($this) {
@@ -253,6 +257,7 @@ public function toRGBA(): RGBA
};
}
+ #[\NoDiscard]
public function light(): RGBA
{
/** @psalm-suppress UnhandledMatchCondition */
@@ -272,6 +277,7 @@ public function light(): RGBA
};
}
+ #[\NoDiscard]
public function dark(): RGBA
{
/** @psalm-suppress UnhandledMatchCondition */
@@ -295,6 +301,7 @@ public function dark(): RGBA
};
}
+ #[\NoDiscard]
public function medium(): RGBA
{
/** @psalm-suppress UnhandledMatchCondition */
@@ -310,6 +317,7 @@ public function medium(): RGBA
};
}
+ #[\NoDiscard]
public function pale(): RGBA
{
/** @psalm-suppress UnhandledMatchCondition */
diff --git a/src/Cyan.php b/src/Cyan.php
index 3c1402c..2824b06 100644
--- a/src/Cyan.php
+++ b/src/Cyan.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function add(self $cyan): self
{
return new self(
@@ -52,6 +55,7 @@ public function add(self $cyan): self
);
}
+ #[\NoDiscard]
public function subtract(self $cyan): self
{
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $cyan): self
);
}
+ #[\NoDiscard]
public function equals(self $cyan): bool
{
return $this->value === $cyan->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 100;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/Green.php b/src/Green.php
index 54a0273..f571787 100644
--- a/src/Green.php
+++ b/src/Green.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 255> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 255) {
@@ -47,6 +49,7 @@ public static function of(int $value): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromHexadecimal(string $hex): Attempt
{
if (\mb_strlen($hex) === 1) {
@@ -61,6 +64,7 @@ public static function fromHexadecimal(string $hex): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromIntensity(Intensity $intensity): Attempt
{
return self::of(
@@ -68,6 +72,7 @@ public static function fromIntensity(Intensity $intensity): Attempt
);
}
+ #[\NoDiscard]
public function add(self $green): self
{
return new self(
@@ -78,6 +83,7 @@ public function add(self $green): self
);
}
+ #[\NoDiscard]
public function subtract(self $green): self
{
return new self(
@@ -88,16 +94,19 @@ public function subtract(self $green): self
);
}
+ #[\NoDiscard]
public function equals(self $green): bool
{
return $this->integer === $green->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->integer === 255;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->integer === 0;
@@ -106,11 +115,13 @@ public function atMinimum(): bool
/**
* @return int<0, 255>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->integer;
}
+ #[\NoDiscard]
public function toString(): string
{
return \str_pad(
diff --git a/src/HSLA.php b/src/HSLA.php
index 94e507b..3249fc9 100644
--- a/src/HSLA.php
+++ b/src/HSLA.php
@@ -28,6 +28,7 @@ private function __construct(
/**
* @psalm-pure
*/
+ #[\NoDiscard]
public static function from(
Hue $hue,
Saturation $saturation,
@@ -42,6 +43,7 @@ public static function from(
*
* @throws \Exception
*/
+ #[\NoDiscard]
public static function of(string $colour): self
{
return self::attempt($colour)->unwrap();
@@ -52,6 +54,7 @@ public static function of(string $colour): self
*
* @return Maybe
*/
+ #[\NoDiscard]
public static function maybe(string $colour): Maybe
{
return self::attempt($colour)->maybe();
@@ -62,6 +65,7 @@ public static function maybe(string $colour): Maybe
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function attempt(string $colour): Attempt
{
$colour = Str::of($colour)->trim();
@@ -71,26 +75,31 @@ public static function attempt(string $colour): Attempt
);
}
+ #[\NoDiscard]
public function hue(): Hue
{
return $this->hue;
}
+ #[\NoDiscard]
public function saturation(): Saturation
{
return $this->saturation;
}
+ #[\NoDiscard]
public function lightness(): Lightness
{
return $this->lightness;
}
+ #[\NoDiscard]
public function alpha(): Alpha
{
return $this->alpha;
}
+ #[\NoDiscard]
public function rotateBy(int $degress): self
{
return new self(
@@ -101,6 +110,7 @@ public function rotateBy(int $degress): self
);
}
+ #[\NoDiscard]
public function addSaturation(Saturation $saturation): self
{
return new self(
@@ -111,6 +121,7 @@ public function addSaturation(Saturation $saturation): self
);
}
+ #[\NoDiscard]
public function subtractSaturation(Saturation $saturation): self
{
return new self(
@@ -121,6 +132,7 @@ public function subtractSaturation(Saturation $saturation): self
);
}
+ #[\NoDiscard]
public function addLightness(Lightness $lightness): self
{
return new self(
@@ -131,6 +143,7 @@ public function addLightness(Lightness $lightness): self
);
}
+ #[\NoDiscard]
public function subtractLightness(Lightness $lightness): self
{
return new self(
@@ -141,6 +154,7 @@ public function subtractLightness(Lightness $lightness): self
);
}
+ #[\NoDiscard]
public function addAlpha(Alpha $alpha): self
{
return new self(
@@ -151,6 +165,7 @@ public function addAlpha(Alpha $alpha): self
);
}
+ #[\NoDiscard]
public function subtractAlpha(Alpha $alpha): self
{
return new self(
@@ -161,6 +176,7 @@ public function subtractAlpha(Alpha $alpha): self
);
}
+ #[\NoDiscard]
public function equals(self $hsla): bool
{
return $this->hue->equals($hsla->hue()) &&
@@ -169,6 +185,7 @@ public function equals(self $hsla): bool
$this->alpha->equals($hsla->alpha());
}
+ #[\NoDiscard]
public function toRGBA(): RGBA
{
$lightness = $this->lightness->toInt() / 100;
@@ -197,16 +214,19 @@ public function toRGBA(): RGBA
);
}
+ #[\NoDiscard]
public function toCMYKA(): CMYKA
{
return $this->toRGBA()->toCMYKA();
}
+ #[\NoDiscard]
public function toHSLA(): self
{
return $this;
}
+ #[\NoDiscard]
public function toString(): string
{
if ($this->alpha->atMaximum()) {
diff --git a/src/Hue.php b/src/Hue.php
index bbd9bd0..41bd9b1 100644
--- a/src/Hue.php
+++ b/src/Hue.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 359> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 359) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function rotateBy(int $degrees): self
{
$degrees = ($this->value + $degrees) % 360;
@@ -53,21 +56,25 @@ public function rotateBy(int $degrees): self
return new self($degrees);
}
+ #[\NoDiscard]
public function opposite(): self
{
return $this->rotateBy(180);
}
+ #[\NoDiscard]
public function equals(self $hue): bool
{
return $this->value === $hue->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 359;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -76,11 +83,13 @@ public function atMinimum(): bool
/**
* @return int<0, 359>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/Intensity.php b/src/Intensity.php
index 4a2e340..3110f61 100644
--- a/src/Intensity.php
+++ b/src/Intensity.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -45,6 +47,7 @@ public static function of(int $value): Attempt
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
diff --git a/src/Lightness.php b/src/Lightness.php
index 667460e..27d34ca 100644
--- a/src/Lightness.php
+++ b/src/Lightness.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function add(self $lightness): self
{
return new self(
@@ -52,6 +55,7 @@ public function add(self $lightness): self
);
}
+ #[\NoDiscard]
public function subtract(self $lightness): self
{
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $lightness): self
);
}
+ #[\NoDiscard]
public function equals(self $lightness): bool
{
return $this->value === $lightness->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 100;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/Magenta.php b/src/Magenta.php
index ab02abc..57f70b8 100644
--- a/src/Magenta.php
+++ b/src/Magenta.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function add(self $magenta): self
{
return new self(
@@ -52,6 +55,7 @@ public function add(self $magenta): self
);
}
+ #[\NoDiscard]
public function subtract(self $magenta): self
{
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $magenta): self
);
}
+ #[\NoDiscard]
public function equals(self $magenta): bool
{
return $this->value === $magenta->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 100;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/RGBA.php b/src/RGBA.php
index c8a2763..118bd20 100644
--- a/src/RGBA.php
+++ b/src/RGBA.php
@@ -32,6 +32,7 @@ private function __construct(
/**
* @psalm-pure
*/
+ #[\NoDiscard]
public static function from(
Red $red,
Green $green,
@@ -46,6 +47,7 @@ public static function from(
*
* @throws \Exception
*/
+ #[\NoDiscard]
public static function of(string $colour): self
{
return self::attempt($colour)->unwrap();
@@ -56,6 +58,7 @@ public static function of(string $colour): self
*
* @return Maybe
*/
+ #[\NoDiscard]
public static function maybe(string $colour): Maybe
{
return self::attempt($colour)->maybe();
@@ -66,6 +69,7 @@ public static function maybe(string $colour): Maybe
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function attempt(string $colour): Attempt
{
$colour = Str::of($colour)->trim();
@@ -75,26 +79,31 @@ public static function attempt(string $colour): Attempt
->recover(static fn() => self::fromRGBAFunction($colour));
}
+ #[\NoDiscard]
public function red(): Red
{
return $this->red;
}
+ #[\NoDiscard]
public function blue(): Blue
{
return $this->blue;
}
+ #[\NoDiscard]
public function green(): Green
{
return $this->green;
}
+ #[\NoDiscard]
public function alpha(): Alpha
{
return $this->alpha;
}
+ #[\NoDiscard]
public function addRed(Red $red): self
{
return new self(
@@ -105,6 +114,7 @@ public function addRed(Red $red): self
);
}
+ #[\NoDiscard]
public function subtractRed(Red $red): self
{
return new self(
@@ -115,6 +125,7 @@ public function subtractRed(Red $red): self
);
}
+ #[\NoDiscard]
public function addBlue(Blue $blue): self
{
return new self(
@@ -125,6 +136,7 @@ public function addBlue(Blue $blue): self
);
}
+ #[\NoDiscard]
public function subtractBlue(Blue $blue): self
{
return new self(
@@ -135,6 +147,7 @@ public function subtractBlue(Blue $blue): self
);
}
+ #[\NoDiscard]
public function addGreen(Green $green): self
{
return new self(
@@ -145,6 +158,7 @@ public function addGreen(Green $green): self
);
}
+ #[\NoDiscard]
public function subtractGreen(Green $green): self
{
return new self(
@@ -155,6 +169,7 @@ public function subtractGreen(Green $green): self
);
}
+ #[\NoDiscard]
public function addAlpha(Alpha $alpha): self
{
return new self(
@@ -165,6 +180,7 @@ public function addAlpha(Alpha $alpha): self
);
}
+ #[\NoDiscard]
public function subtractAlpha(Alpha $alpha): self
{
return new self(
@@ -175,6 +191,7 @@ public function subtractAlpha(Alpha $alpha): self
);
}
+ #[\NoDiscard]
public function equals(self $rgba): bool
{
return $this->red->equals($rgba->red()) &&
@@ -183,6 +200,7 @@ public function equals(self $rgba): bool
$this->alpha->equals($rgba->alpha());
}
+ #[\NoDiscard]
public function toHexadecimal(): string
{
$hex = $this->red->toString().$this->green->toString().$this->blue->toString();
@@ -194,6 +212,7 @@ public function toHexadecimal(): string
return $hex;
}
+ #[\NoDiscard]
public function toHSLA(): HSLA
{
$red = $this->red->toInt() / 255;
@@ -239,6 +258,7 @@ public function toHSLA(): HSLA
);
}
+ #[\NoDiscard]
public function toCMYKA(): CMYKA
{
$red = $this->red->toInt() / 255;
@@ -273,11 +293,13 @@ public function toCMYKA(): CMYKA
);
}
+ #[\NoDiscard]
public function toRGBA(): self
{
return $this;
}
+ #[\NoDiscard]
public function toString(): string
{
if ($this->alpha->atMaximum()) {
diff --git a/src/Red.php b/src/Red.php
index aa7b456..2bb3acd 100644
--- a/src/Red.php
+++ b/src/Red.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 255> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 255) {
@@ -47,6 +49,7 @@ public static function of(int $value): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromHexadecimal(string $hex): Attempt
{
if (\mb_strlen($hex) === 1) {
@@ -61,6 +64,7 @@ public static function fromHexadecimal(string $hex): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function fromIntensity(Intensity $intensity): Attempt
{
return self::of(
@@ -68,6 +72,7 @@ public static function fromIntensity(Intensity $intensity): Attempt
);
}
+ #[\NoDiscard]
public function add(self $red): self
{
return new self(
@@ -78,6 +83,7 @@ public function add(self $red): self
);
}
+ #[\NoDiscard]
public function subtract(self $red): self
{
return new self(
@@ -88,16 +94,19 @@ public function subtract(self $red): self
);
}
+ #[\NoDiscard]
public function equals(self $red): bool
{
return $this->integer === $red->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->integer === 255;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->integer === 0;
@@ -106,11 +115,13 @@ public function atMinimum(): bool
/**
* @return int<0, 255>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->integer;
}
+ #[\NoDiscard]
public function toString(): string
{
return \str_pad(
diff --git a/src/Saturation.php b/src/Saturation.php
index ee3034f..2256e70 100644
--- a/src/Saturation.php
+++ b/src/Saturation.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function add(self $saturation): self
{
return new self(
@@ -52,6 +55,7 @@ public function add(self $saturation): self
);
}
+ #[\NoDiscard]
public function subtract(self $saturation): self
{
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $saturation): self
);
}
+ #[\NoDiscard]
public function equals(self $saturation): bool
{
return $this->value === $saturation->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 100;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
diff --git a/src/Yellow.php b/src/Yellow.php
index 697d7e7..44760f1 100644
--- a/src/Yellow.php
+++ b/src/Yellow.php
@@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
+ #[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
@@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
@@ -42,6 +44,7 @@ public static function of(int $value): Attempt
return Attempt::result(new self($value));
}
+ #[\NoDiscard]
public function add(self $yellow): self
{
return new self(
@@ -52,6 +55,7 @@ public function add(self $yellow): self
);
}
+ #[\NoDiscard]
public function subtract(self $yellow): self
{
return new self(
@@ -62,16 +66,19 @@ public function subtract(self $yellow): self
);
}
+ #[\NoDiscard]
public function equals(self $yellow): bool
{
return $this->value === $yellow->toInt();
}
+ #[\NoDiscard]
public function atMaximum(): bool
{
return $this->value === 100;
}
+ #[\NoDiscard]
public function atMinimum(): bool
{
return $this->value === 0;
@@ -80,11 +87,13 @@ public function atMinimum(): bool
/**
* @return int<0, 100>
*/
+ #[\NoDiscard]
public function toInt(): int
{
return $this->value;
}
+ #[\NoDiscard]
public function toString(): string
{
return (string) $this->value;