Passed
Pull Request — master (#78)
by
unknown
14:55
created

SimpleCalculator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 6
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\tests\support\order;
12
13
use hiqdev\php\billing\charge\Generalizer;
14
use hiqdev\php\billing\charge\GeneralizerInterface;
15
use hiqdev\php\billing\order\Calculator;
16
use hiqdev\php\billing\plan\PlanInterface;
17
use hiqdev\php\billing\sale\SaleInterface;
18
use hiqdev\php\billing\tests\support\plan\SimplePlanRepository;
19
use hiqdev\php\billing\tests\support\sale\SimpleSaleRepository;
20
21
class SimpleCalculator extends Calculator
22
{
23
    /**
24
     * @param GeneralizerInterface $generalizer
25
     * @param SaleRepositoryInterface|SaleInterface $sale
26
     * @param PlanRepositoryInterface|PlanInterface $plan
27
     */
28
    public function __construct(GeneralizerInterface $generalizer = null, $sale = null, $plan = null)
29
    {
30
        $this->generalizer = $generalizer ?: new Generalizer();
31
        if ($sale instanceof SaleInterface) {
32
            if (empty($plan)) {
33
                $plan = $sale->getPlan();
34
            }
35
            $sale = new SimpleSaleRepository($sale);
36
        }
37
        if ($plan instanceof PlanInterface) {
38
            $plan = new SimplePlanRepository($plan);
39
        }
40
41
        return parent::__construct($this->generalizer, $sale, $plan);
42
    }
43
44
    public function getGeneralizer(): GeneralizerInterface
45
    {
46
        return $this->generalizer;
47
    }
48
}
49