Completed
Push — master ( bab678...d073e6 )
by Andrii
02:26
created

Generalizer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 55
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createBill() 0 14 1
A generalizeType() 0 4 1
A generalizeTime() 0 6 1
A generalizeSum() 0 4 1
A generalizeQuantity() 0 4 1
A generalizeCustomer() 0 4 1
A generalizeTarget() 0 4 1
A generalizePlan() 0 4 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 DateTimeImmutable;
14
use hiqdev\php\billing\bill\Bill;
15
use hiqdev\php\billing\bill\BillInterface;
16
use hiqdev\php\units\QuantityInterface;
17
use Money\Money;
18
19
/**
20
 * @author Andrii Vasyliev <[email protected]>
21 1
 */
22
class Generalizer implements GeneralizerInterface
23 1
{
24 1
25 1
    public function createBill(ChargeInterface $charge)
26 1
    {
27 1
        return new Bill(
28 1
            null,
29 1
            $this->generalizeType($charge),
30 1
            $this->generalizeTime($charge),
31 1
            $this->generalizeSum($charge),
32 1
            $this->generalizeQuantity($charge),
33
            $this->generalizeCustomer($charge),
34
            $this->generalizeTarget($charge),
35
            $this->generalizePlan($charge),
36 1
            [$charge]
37
        );
38 1
    }
39
40
    public function generalizeType(ChargeInterface $charge)
41 1
    {
42
        return $charge->getPrice()->getType();
43 1
    }
44
45 1
    public function generalizeTime(ChargeInterface $charge)
46
    {
47
        $date = new DateTimeImmutable($charge->getTime());
48 1
49
        return $date->modify('first day of this month midnight');
50 1
    }
51
52
    public function generalizeSum(ChargeInterface $charge)
53 1
    {
54
        return $charge->getSum();
55 1
    }
56
57
    public function generalizeQuantity(ChargeInterface $charge)
58 1
    {
59
        return $charge->getUsage();
60 1
    }
61
62
    public function generalizeCustomer(ChargeInterface $charge)
63 1
    {
64
        return $charge->getAction()->getCustomer();
65 1
    }
66
67
    public function generalizeTarget(ChargeInterface $charge)
68 1
    {
69
        return $charge->getAction()->getTarget();
70 1
    }
71
72
    public function generalizePlan(ChargeInterface $charge)
73
    {
74
        return $charge->getPrice()->getPlan();
75
    }
76
}
77