Passed
Push — master ( 6ae125...ae3d7a )
by Dmitry
02:46
created

TypeSemantics::isOveruse()   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
rs 10
c 0
b 0
f 0
ccs 0
cts 1
cp 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
14
    /**
15
     * // TODO: Probably not the best place for this method
16
     *
17
     * @return TypeInterface
18
     */
19
    public function createMonthlyType(): TypeInterface
20
    {
21
        return new Type(null, self::MONTHLY . ',' . self::MONTHLY);
22
    }
23
24
    /**
25
     * @param TypeInterface $type
26
     * @return bool
27
     */
28
    public function isMonthly(TypeInterface $type): bool
29
    {
30
        return $this->groupName($type) === self::MONTHLY;
31
    }
32
33
    /**
34
     * @param TypeInterface $type
35
     * @return bool
36 6
     */
37
    public function isDiscount(TypeInterface $type): bool
38 6
    {
39
        return $this->groupName($type) === self::DISCOUNT;
40
    }
41
42
    /**
43
     * @param TypeInterface $type
44
     * @return bool
45
     */
46
    public function isOveruse(TypeInterface $type): bool
47
    {
48
        return $this->groupName($type) === self::OVERUSE;
49
    }
50
51
    /**
52
     * @param TypeInterface $type
53
     * @return string
54
     */
55
    public function groupName(TypeInterface $type): string
56
    {
57
        $name = $type->getName();
58
        if (strpos($name, ',') !== false) {
59
            [$name,] = explode(',', $name, 2);
60
        }
61
62
        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...
63 6
    }
64
}
65