Generalizer::generalizeSum()   A
last analyzed

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-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge;
12
13
use hiqdev\php\billing\action\UsageInterval;
14
use hiqdev\php\billing\bill\Bill;
15
use hiqdev\php\billing\bill\BillInterface;
16
use hiqdev\php\billing\customer\CustomerInterface;
17
use hiqdev\php\billing\plan\PlanInterface;
18
use hiqdev\php\billing\target\TargetInterface;
19
use hiqdev\php\billing\type\TypeInterface;
0 ignored issues
show
Bug introduced by
The type hiqdev\php\billing\type\TypeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use hiqdev\php\units\QuantityInterface;
21
use Money\Money;
22
23
/**
24
 * @author Andrii Vasyliev <[email protected]>
25
 */
26
class Generalizer implements GeneralizerInterface
27 1
{
28
    public function createBill(ChargeInterface $charge): BillInterface
29 1
    {
30 1
        $bill = new Bill(
31 1
            null,
32 1
            $this->generalizeType($charge),
33 1
            $this->generalizeTime($charge),
34 1
            $this->generalizeSum($charge),
35 1
            $this->generalizeQuantity($charge),
36 1
            $this->generalizeCustomer($charge),
37 1
            $this->generalizeTarget($charge),
38 1
            $this->generalizePlan($charge),
39
            [$charge],
40
        );
41
42 1
        $bill->setUsageInterval($this->generalizeUsageInterval($charge));
43
44 1
        return $bill;
45
    }
46
47 1
    public function generalizeType(ChargeInterface $charge): TypeInterface
48
    {
49 1
        return $charge->getType();
50
    }
51
52 1
    public function generalizeTime(ChargeInterface $charge): \DateTimeImmutable
53
    {
54 1
        return $charge->getAction()->getTime();
55
    }
56
57 1
    public function generalizeSum(ChargeInterface $charge): Money
58
    {
59 1
        return $charge->getSum()->negative();
60
    }
61
62 1
    public function generalizeQuantity(ChargeInterface $charge): QuantityInterface
63
    {
64 1
        return $charge->getUsage();
65
    }
66
67 1
    public function generalizeCustomer(ChargeInterface $charge): CustomerInterface
68
    {
69 1
        return $charge->getAction()->getCustomer();
70
    }
71
72 1
    public function generalizeTarget(ChargeInterface $charge): TargetInterface
73
    {
74 1
        return $charge->getTarget();
75
    }
76
77 17
    public function generalizePlan(ChargeInterface $charge): ?PlanInterface
78
    {
79 17
        return $charge->getPrice()->getPlan();
80
    }
81
82 17
    public function specializeType(TypeInterface $first, TypeInterface $other): TypeInterface
83
    {
84 17
        return $first;
85
    }
86
87
    public function specializeTarget(TargetInterface $first, TargetInterface $other): TargetInterface
88
    {
89
        return $first;
90
    }
91
92
    private function generalizeUsageInterval(ChargeInterface $charge): UsageInterval
93
    {
94
        return $charge->getAction()->getUsageInterval();
95
    }
96
}
97