|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\Color\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
|
|
7
|
|
|
class InvalidColorValue extends Exception |
|
8
|
|
|
{ |
|
9
|
|
|
public static function rgbChannelValueNotInRange(int $value, string $channel): self |
|
10
|
|
|
{ |
|
11
|
|
|
return new static("An rgb values must be an integer between 0 and 255, `{$value}` provided for channel {$channel}."); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public static function alphaChannelValueNotInRange(int $value): self |
|
15
|
|
|
{ |
|
16
|
|
|
return new static("An alpha values must be a float between 0 and 1, `{$value}` provided."); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public static function hexChannelValueHasInvalidLength(string $value): self |
|
20
|
|
|
{ |
|
21
|
|
|
$length = strlen($value); |
|
22
|
|
|
|
|
23
|
|
|
return new static("Hex values must contain exactly 2 characters, `{$value}` contains {$length} characters."); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function hexValueContainsInvalidCharacters(string $value): self |
|
27
|
|
|
{ |
|
28
|
|
|
return new static("Hex values can only contain numbers or letters from A-F, `{$value}` contains invalid characters."); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public static function hslValueNotInRange(float $value, string $name): self |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
return new static("Hsl value `{$name}` must be a number between 0 and 100"); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function malformedHexColorString(string $string): self |
|
37
|
|
|
{ |
|
38
|
|
|
return new static("Hex color string `{$string}` is malformed. A hex color string starts with a `#` and contains exactly six characters, e.g. `#aabbcc`."); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function malformedHslColorString(string $string): self |
|
42
|
|
|
{ |
|
43
|
|
|
return new static("Hsl color string `{$string}` is malformed. An hsl color contains hue, saturation, and lightness values, wrapped in `hsl()`, e.g. `hsl(300,10%,50%)`."); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function malformedHslaColorString(string $string): self |
|
47
|
|
|
{ |
|
48
|
|
|
return new static("Hsla color string `{$string}` is malformed. An hsla color contains hue, saturation, lightness and alpha values, wrapped in `hsl()`, e.g. `hsl(300,10%,50%,0.25)`."); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function malformedRgbColorString(string $string): self |
|
52
|
|
|
{ |
|
53
|
|
|
return new static("Rgb color string `{$string}` is malformed. An rgb color contains 3 comma separated values between 0 and 255, wrapped in `rgb()`, e.g. `rgb(0,0,255)`."); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function malformedRgbaColorString(string $string): self |
|
57
|
|
|
{ |
|
58
|
|
|
return new static("Rgba color string `{$string}` is malformed. An rgba color contains 3 comma separated values between 0 and 255 with an alpha value between 0 and 1, wrapped in `rgba()`, e.g. `rgb(0,0,255,0.5)`."); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public static function malformedColorString(string $string): self |
|
62
|
|
|
{ |
|
63
|
|
|
return new static("Color string `{$string}` doesn't match any of the available colors."); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.