Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
</projectFiles>
<issueHandlers>
<InvalidOperand errorLevel="suppress" />
<UndefinedAttributeClass errorLevel="suppress" />
</issueHandlers>
</psalm>
11 changes: 11 additions & 0 deletions src/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private function __construct(float $value)
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function max(): self
{
return new self(1);
Expand All @@ -34,6 +35,7 @@ public static function max(): self
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function of(float $value): Attempt
{
return Attempt::of(static fn() => new self($value));
Expand All @@ -44,6 +46,7 @@ public static function of(float $value): Attempt
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function fromHexadecimal(string $hex): Attempt
{
if (\mb_strlen($hex) === 1) {
Expand All @@ -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(
Expand All @@ -63,6 +67,7 @@ public function add(self $alpha): self
);
}

#[\NoDiscard]
public function subtract(self $alpha): self
{
return new self(
Expand All @@ -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(
Expand All @@ -105,6 +115,7 @@ public function toHexadecimal(): string
);
}

#[\NoDiscard]
public function toString(): string
{
return (string) $this->value;
Expand Down
9 changes: 9 additions & 0 deletions src/Black.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 100> $value
*/
#[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
Expand All @@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 100) {
Expand All @@ -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(
Expand All @@ -52,6 +55,7 @@ public function add(self $black): self
);
}

#[\NoDiscard]
public function subtract(self $black): self
{
return new self(
Expand All @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/Blue.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private function __construct(
*
* @param int<0, 255> $value
*/
#[\NoDiscard]
public static function at(int $value): self
{
return new self($value);
Expand All @@ -33,6 +34,7 @@ public static function at(int $value): self
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function of(int $value): Attempt
{
if ($value < 0 || $value > 255) {
Expand All @@ -47,6 +49,7 @@ public static function of(int $value): Attempt
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function fromHexadecimal(string $hex): Attempt
{
if (\mb_strlen($hex) === 1) {
Expand All @@ -59,13 +62,15 @@ public static function fromHexadecimal(string $hex): Attempt
/**
* @return Attempt<self>
*/
#[\NoDiscard]
public static function fromIntensity(Intensity $intensity): Attempt
{
return self::of(
(int) \round((255 * $intensity->toInt()) / 100),
);
}

#[\NoDiscard]
public function add(self $blue): self
{
return new self(
Expand All @@ -76,6 +81,7 @@ public function add(self $blue): self
);
}

#[\NoDiscard]
public function subtract(self $blue): self
{
return new self(
Expand All @@ -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;
Expand All @@ -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(
Expand Down
Loading