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
|
|
|
class TypeSemantics |
9
|
|
|
{ |
10
|
|
|
private const MONTHLY = 'monthly'; |
11
|
|
|
private const OVERUSE = 'overuse'; |
12
|
|
|
private const DISCOUNT = 'discount'; |
13
|
|
|
private const DEPOSIT = 'deposit'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* // TODO: Probably not the best place for this method |
17
|
|
|
* |
18
|
|
|
* @return TypeInterface |
19
|
|
|
*/ |
20
|
|
|
public function createMonthlyType(): TypeInterface |
21
|
|
|
{ |
22
|
|
|
return new Type(null, self::MONTHLY . ',' . self::MONTHLY); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param TypeInterface $type |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
public function isMonthly(TypeInterface $type): bool |
30
|
|
|
{ |
31
|
|
|
return $this->groupName($type) === self::MONTHLY; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param TypeInterface $type |
36
|
|
|
* @return bool |
37
|
6 |
|
*/ |
38
|
|
|
public function isDiscount(TypeInterface $type): bool |
39
|
6 |
|
{ |
40
|
|
|
return $this->groupName($type) === self::DISCOUNT; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param TypeInterface $type |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
public function isOveruse(TypeInterface $type): bool |
48
|
|
|
{ |
49
|
|
|
return $this->groupName($type) === self::OVERUSE; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param TypeInterface $type |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function isDeposit(TypeInterface $type): bool |
57
|
|
|
{ |
58
|
|
|
return $this->groupName($type) === self::DEPOSIT; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param TypeInterface $type |
63
|
|
|
* @return string |
64
|
1 |
|
*/ |
65
|
|
|
public function groupName(TypeInterface $type): string |
66
|
1 |
|
{ |
67
|
|
|
$name = $type->getName(); |
68
|
|
|
if (strpos($name, ',') !== false) { |
69
|
|
|
[$name,] = explode(',', $name, 2); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $name; |
|
|
|
|
73
|
6 |
|
} |
74
|
|
|
|
75
|
6 |
|
public function localName(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
|
|
|
|