Completed
Push — master ( 4f1ff9...3d2e51 )
by Dmitry
03:44
created

TypeSemantics::isDeposit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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;
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...
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;
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