Skip to content

Commit 4d305cd

Browse files
committed
Add argument check
1 parent aede5f3 commit 4d305cd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Colors/FloatColorChannel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ final public function __construct(float $value)
3030
*/
3131
public static function fromNormalized(float $normalized): self
3232
{
33+
if ($normalized < 0 || $normalized > 1) {
34+
throw new InvalidArgumentException(
35+
'Normalized color channel value of ' . static::class . ' must be in range 0 to 1',
36+
);
37+
}
38+
3339
return new static(static::min() + $normalized * (static::max() - static::min()));
3440
}
3541

src/Colors/IntegerColorChannel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ final public function __construct(int $value)
3030
*/
3131
public static function fromNormalized(float $normalized): self
3232
{
33+
if ($normalized < 0 || $normalized > 1) {
34+
throw new InvalidArgumentException(
35+
'Normalized color channel value of ' . static::class . ' must be in range 0 to 1',
36+
);
37+
}
38+
3339
return new static(intval(round($normalized * static::max())));
3440
}
3541

0 commit comments

Comments
 (0)