TypeSemantics   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 45%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 10
eloc 20
c 4
b 0
f 0
dl 0
loc 85
ccs 9
cts 20
cp 0.45
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createMonthlyType() 0 3 1
A groupName() 0 8 2
A isDiscount() 0 3 1
A isDeposit() 0 3 1
A isMonthly() 0 3 1
A isHardware() 0 3 1
A localName() 0 8 2
A isOveruse() 0 3 1
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $name could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $name could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
93
    }
94
}
95