generated from assoconnect/php-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbsolutePercentValue.php
More file actions
57 lines (42 loc) · 1.16 KB
/
AbsolutePercentValue.php
File metadata and controls
57 lines (42 loc) · 1.16 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace AssoConnect\AbsolutePercentValueBundle\Object;
use Assert\Assertion;
/**
* AbsolutePercentValue representing either an absolute value or a percent
*/
class AbsolutePercentValue
{
public const TYPE_ABSOLUTE = 'ABSOLUTE';
public const TYPE_PERCENT = 'PERCENT';
private const TYPES = [
self::TYPE_ABSOLUTE,
self::TYPE_PERCENT
];
private string $type;
private string $value;
public function __construct(string $type, string $value)
{
Assertion::inArray($type, self::TYPES);
Assertion::numeric($value);
Assertion::greaterOrEqualThan(intval($value), 1);
// if type is PERCENT, check value is valid (1 < $value < 10000)
if ($type === self::TYPE_PERCENT) {
Assertion::between(intval($value), 1, 10000);
}
$this->type = $type;
$this->value = $value;
}
public function getType(): string
{
return $this->type;
}
public function getValue(): string
{
return $this->value;
}
public function __toString(): string
{
return $this->type . ' ' . $this->value;
}
}