| @@ 8-30 (lines=23) @@ | ||
| 5 | ||
| 6 | use Innmind\Server\Status\Exception\OutOfBoundsPercentage; |
|
| 7 | ||
| 8 | final class Percentage |
|
| 9 | { |
|
| 10 | private $value; |
|
| 11 | ||
| 12 | public function __construct(float $value) |
|
| 13 | { |
|
| 14 | if ($value < 0 || $value > 100) { |
|
| 15 | throw new OutOfBoundsPercentage; |
|
| 16 | } |
|
| 17 | ||
| 18 | $this->value = $value; |
|
| 19 | } |
|
| 20 | ||
| 21 | public function toFloat(): float |
|
| 22 | { |
|
| 23 | return $this->value; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function __toString(): string |
|
| 27 | { |
|
| 28 | return $this->value.'%'; |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| @@ 8-30 (lines=23) @@ | ||
| 5 | ||
| 6 | use Innmind\Server\Status\Exception\OutOfBoundsPercentage; |
|
| 7 | ||
| 8 | final class Memory |
|
| 9 | { |
|
| 10 | private $value; |
|
| 11 | ||
| 12 | public function __construct(float $value) |
|
| 13 | { |
|
| 14 | if ($value < 0 || $value > 100) { |
|
| 15 | throw new OutOfBoundsPercentage; |
|
| 16 | } |
|
| 17 | ||
| 18 | $this->value = $value; |
|
| 19 | } |
|
| 20 | ||
| 21 | public function toFloat(): float |
|
| 22 | { |
|
| 23 | return $this->value; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function __toString(): string |
|
| 27 | { |
|
| 28 | return $this->value.'%'; |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||