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

Aggregator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
nc 1
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