Completed
Push — master ( d26128...b08c4e )
by Andrii
03:02
created

Generalizer::generalizeCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 1
    public function createBill(ChargeInterface $charge)
21
    {
22 1
        return new Bill(
23 1
            null,
24 1
            $this->generalizeType($charge),
25 1
            $this->generalizeTime($charge),
26 1
            $this->generalizeSum($charge),
27 1
            $this->generalizeQuantity($charge),
28 1
            $this->generalizeCustomer($charge),
29 1
            $this->generalizeTarget($charge),
30 1
            $this->generalizePlan($charge),
31 1
            [$charge]
32
        );
33
    }
34
35 1
    public function generalizeType(ChargeInterface $charge)
36
    {
37 1
        return $charge->getPrice()->getType();
38
    }
39
40 1
    public function generalizeTime(ChargeInterface $charge)
41
    {
42 1
        return $charge->getAction()->getTime()->modify('first day of this month midnight');
43
    }
44
45 1
    public function generalizeSum(ChargeInterface $charge)
46
    {
47 1
        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 1
    public function generalizeQuantity(ChargeInterface $charge)
51
    {
52 1
        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 1
    public function generalizeCustomer(ChargeInterface $charge)
56
    {
57 1
        return $charge->getAction()->getCustomer();
58
    }
59
60 1
    public function generalizeTarget(ChargeInterface $charge)
61
    {
62 1
        return $charge->getAction()->getTarget();
63
    }
64
65 1
    public function generalizePlan(ChargeInterface $charge)
66
    {
67 1
        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