|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hiqdev\billing\hiapi\type; |
|
4
|
|
|
|
|
5
|
|
|
use hiqdev\php\billing\type\Type; |
|
6
|
|
|
use hiqdev\php\billing\type\TypeInterface; |
|
7
|
|
|
|
|
8
|
|
|
final class TypeSemantics |
|
9
|
|
|
{ |
|
10
|
|
|
private const MONTHLY = 'monthly'; |
|
11
|
|
|
private const OVERUSE = 'overuse'; |
|
12
|
|
|
private const DISCOUNT = 'discount'; |
|
13
|
|
|
private const DEPOSIT = 'deposit'; |
|
14
|
|
|
private const HARDWARE = 'hardware'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* // TODO: Probably not the best place for this method |
|
18
|
|
|
* |
|
19
|
|
|
* @return TypeInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
public function createMonthlyType(): TypeInterface |
|
22
|
|
|
{ |
|
23
|
|
|
return new Type(null, self::MONTHLY . ',' . self::MONTHLY); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param TypeInterface $type |
|
28
|
|
|
* @return bool |
|
29
|
|
|
*/ |
|
30
|
|
|
public function isMonthly(TypeInterface $type): bool |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->groupName($type) === self::MONTHLY; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param TypeInterface $type |
|
37
|
6 |
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
6 |
|
public function isHardware(TypeInterface $type): bool |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->localName($type) === self::HARDWARE; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param TypeInterface $type |
|
46
|
|
|
* @return bool |
|
47
|
|
|
*/ |
|
48
|
|
|
public function isDiscount(TypeInterface $type): bool |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->groupName($type) === self::DISCOUNT; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param TypeInterface $type |
|
55
|
|
|
* @return bool |
|
56
|
|
|
*/ |
|
57
|
|
|
public function isOveruse(TypeInterface $type): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->groupName($type) === self::OVERUSE; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param TypeInterface $type |
|
64
|
1 |
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function isDeposit(TypeInterface $type): bool |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->groupName($type) === self::DEPOSIT; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param TypeInterface $type |
|
73
|
6 |
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
6 |
|
public function groupName(TypeInterface $type): string |
|
76
|
6 |
|
{ |
|
77
|
3 |
|
$name = $type->getName(); |
|
78
|
|
|
if (strpos($name, ',') !== false) { |
|
79
|
|
|
[$name,] = explode(',', $name, 2); |
|
80
|
6 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $name; |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function localName(TypeInterface $type): string |
|
86
|
|
|
{ |
|
87
|
|
|
$name = $type->getName(); |
|
88
|
|
|
if (strpos($name, ',') !== false) { |
|
89
|
|
|
[,$name] = explode(',', $name, 2); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $name; |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|