| Total Complexity | 11 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class Rgb implements Color |
||
| 11 | { |
||
| 12 | private int $red = 0; |
||
| 13 | private int $green = 0; |
||
| 14 | private int $blue = 0; |
||
| 15 | |||
| 16 | public function __construct(int $red = null, int $green = null, int $blue = null) |
||
| 17 | { |
||
| 18 | if ($red) { |
||
|
|
|||
| 19 | $this->setRed($red); |
||
| 20 | } |
||
| 21 | |||
| 22 | if ($green) { |
||
| 23 | $this->setGreen($green); |
||
| 24 | } |
||
| 25 | |||
| 26 | if ($blue) { |
||
| 27 | 13 | $this->setBlue($blue); |
|
| 28 | } |
||
| 29 | 13 | } |
|
| 30 | 13 | ||
| 31 | 13 | public function setRed(int $red): void |
|
| 32 | 13 | { |
|
| 33 | $this->isValid($red); |
||
| 34 | 13 | $this->red = $red; |
|
| 35 | } |
||
| 36 | 13 | ||
| 37 | 13 | public function setGreen(int $green): void |
|
| 38 | 13 | { |
|
| 39 | $this->isValid($green); |
||
| 40 | 13 | $this->green = $green; |
|
| 41 | } |
||
| 42 | 13 | ||
| 43 | 13 | public function setBlue(int $blue): void |
|
| 47 | } |
||
| 48 | 13 | ||
| 49 | 13 | public function toString(): string |
|
| 50 | 13 | { |
|
| 51 | return sprintf('rgb(%s, %s, %s)', $this->red, $this->green, $this->blue); |
||
| 52 | 7 | } |
|
| 53 | |||
| 54 | 7 | private function isValid(int $value): void |
|
| 58 | } |
||
| 59 | 13 | } |
|
| 60 | } |
||
| 61 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: