Completed
Push — master ( a29fc9...07f98c )
by Andrii
06:20
created

Generalizer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A generalizeQuantity() 0 3 1
A generalizeSum() 0 3 1
A generalizeTime() 0 3 1
A generalizePlan() 0 3 1
A generalizeTarget() 0 3 1
A createBill() 0 12 1
A generalizeType() 0 3 1
A generalizeCustomer() 0 3 1
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge;
12
13
use hiqdev\php\billing\bill\Bill;
14
15
/**
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class Generalizer implements GeneralizerInterface
19
{
20
    public function createBill(ChargeInterface $charge)
21
    {
22
        return new Bill(
23
            null,
24
            $this->generalizeType($charge),
25
            $this->generalizeTime($charge),
26
            $this->generalizeSum($charge),
27
            $this->generalizeQuantity($charge),
28
            $this->generalizeCustomer($charge),
29
            $this->generalizeTarget($charge),
30
            $this->generalizePlan($charge),
31
            [$charge]
32
        );
33
    }
34
35
    public function generalizeType(ChargeInterface $charge)
36
    {
37
        return $charge->getPrice()->getType();
38
    }
39
40
    public function generalizeTime(ChargeInterface $charge)
41
    {
42
        return $charge->getAction()->getTime()->modify('first day of this month midnight');
43
    }
44
45
    public function generalizeSum(ChargeInterface $charge)
46
    {
47
        return $charge->getSum();
0 ignored issues
show
Bug introduced by
The method getSum() does not exist on hiqdev\php\billing\charge\ChargeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to hiqdev\php\billing\charge\ChargeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        return $charge->/** @scrutinizer ignore-call */ getSum();
Loading history...
48
    }
49
50
    public function generalizeQuantity(ChargeInterface $charge)
51
    {
52
        return $charge->getUsage();
0 ignored issues
show
Bug introduced by
The method getUsage() does not exist on hiqdev\php\billing\charge\ChargeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to hiqdev\php\billing\charge\ChargeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        return $charge->/** @scrutinizer ignore-call */ getUsage();
Loading history...
53
    }
54
55
    public function generalizeCustomer(ChargeInterface $charge)
56
    {
57
        return $charge->getAction()->getCustomer();
58
    }
59
60
    public function generalizeTarget(ChargeInterface $charge)
61
    {
62
        return $charge->getAction()->getTarget();
63
    }
64
65
    public function generalizePlan(ChargeInterface $charge)
66
    {
67
        return $charge->getPrice()->getPlan();
0 ignored issues
show
Bug introduced by
The method getPlan() does not exist on hiqdev\php\billing\price\PriceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to hiqdev\php\billing\price\PriceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        return $charge->getPrice()->/** @scrutinizer ignore-call */ getPlan();
Loading history...
68
    }
69
}
70