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

Aggregator::aggregateQuantity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace hiqdev\billing\hiapi\charge;
4
5
use hiqdev\billing\hiapi\type\TypeSemantics;
6
use hiqdev\php\billing\bill\BillInterface;
7
use hiqdev\php\billing\charge\GeneralizerInterface;
8
use hiqdev\php\units\QuantityInterface;
9
10
/**
11
 * Class Aggregator
12
 *
13
 * @author Dmytro Naumenko <[email protected]>
14
 */
15
class Aggregator extends \hiqdev\php\billing\charge\Aggregator
16
{
17
    /**
18
     * @var TypeSemantics
19
     */
20
    private $typeSemantics;
21
22
    public function __construct(GeneralizerInterface $generalizer, TypeSemantics $typeSemantics)
23
    {
24
        parent::__construct($generalizer);
25
26
        $this->typeSemantics = $typeSemantics;
27
    }
28
29
    protected function aggregateQuantity(BillInterface $first, BillInterface $other): QuantityInterface
30 1
    {
31
        $billType = $first->getType();
32 1
33
        if ($this->typeSemantics->isMonthly($billType)) {
34 1
            return $first->getQuantity();
35 1
        }
36
37 1
        return $first->getQuantity()->add($other->getQuantity());
38
    }
39
}
40