-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInteger.php
More file actions
42 lines (33 loc) · 811 Bytes
/
Integer.php
File metadata and controls
42 lines (33 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace Epignosis\Types\Number;
use Epignosis\Types\AbstractType;
use InvalidArgumentException;
class Integer extends AbstractType
{
private int $value;
final public function __construct(int $value)
{
$this->validate($value);
$this->value = $value;
}
final public function getValue(): int
{
return $this->value;
}
/**
* @param int|float|string $value
* @return static
*/
final public static function fromNumeric($value): static
{
if (is_numeric($value)) {
return new static((int)$value);
}
throw new InvalidArgumentException('Value is not numeric.');
}
protected function validate(int $value): void
{
// Integer does nothing.
}
}