Skip to content

Commit

Permalink
add return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Feb 18, 2021
1 parent 5a85297 commit 1425e84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function hslValueToRgb(float $hue, float $saturation, float $light
}
}

public static function rgbValueToHsl($red, $green, $blue)
public static function rgbValueToHsl($red, $green, $blue): array
{
$r = $red / 255;
$g = $green / 255;
Expand Down
18 changes: 9 additions & 9 deletions src/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

class Validate
{
public static function rgbChannelValue(int $value, string $channel)
public static function rgbChannelValue(int $value, string $channel): void
{
if ($value < 0 || $value > 255) {
throw InvalidColorValue::rgbChannelValueNotInRange($value, $channel);
}
}

public static function alphaChannelValue(float $value)
public static function alphaChannelValue(float $value): void
{
if ($value < 0 || $value > 1) {
throw InvalidColorValue::alphaChannelValueNotInRange($value);
}
}

public static function hexChannelValue(string $value)
public static function hexChannelValue(string $value): void
{
if (strlen($value) !== 2) {
throw InvalidColorValue::hexChannelValueHasInvalidLength($value);
Expand All @@ -31,42 +31,42 @@ public static function hexChannelValue(string $value)
}
}

public static function hslValue(float $value, string $name)
public static function hslValue(float $value, string $name): void
{
if ($value < 0 || $value > 100) {
throw InvalidColorValue::hslValueNotInRange($value, $name);
}
}

public static function rgbColorString($string)
public static function rgbColorString($string): void
{
if (! preg_match('/^ *rgb\( *\d{1,3} *, *\d{1,3} *, *\d{1,3} *\) *$/i', $string)) {
throw InvalidColorValue::malformedRgbColorString($string);
}
}

public static function rgbaColorString($string)
public static function rgbaColorString($string): void
{
if (! preg_match('/^ *rgba\( *\d{1,3} *, *\d{1,3} *, *\d{1,3} *, *[0-1](\.\d{1,2})? *\) *$/i', $string)) {
throw InvalidColorValue::malformedRgbaColorString($string);
}
}

public static function hexColorString($string)
public static function hexColorString($string): void
{
if (! preg_match('/^#[a-f0-9]{6}$/i', $string)) {
throw InvalidColorValue::malformedHexColorString($string);
}
}

public static function hslColorString($string)
public static function hslColorString($string): void
{
if (! preg_match('/^ *hsl\( *-?\d{1,3} *, *\d{1,3}%? *, *\d{1,3}%? *\) *$/i', $string)) {
throw InvalidColorValue::malformedHslColorString($string);
}
}

public static function hslaColorString($string)
public static function hslaColorString($string): void
{
if (! preg_match('/^ *hsla\( *\d{1,3} *, *\d{1,3}%? *, *\d{1,3}%? *, *[0-1](\.\d{1,2})? *\) *$/i', $string)) {
throw InvalidColorValue::malformedHslaColorString($string);
Expand Down

0 comments on commit 1425e84

Please sign in to comment.