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

SimpleBilling   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 32
rs 10
c 2
b 0
f 0
wmc 8
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\bill\BillRepositoryInterface;
14
use hiqdev\php\billing\customer\CustomerInterface;
15
use hiqdev\php\billing\order\Billing;
16
use hiqdev\php\billing\order\CalculatorInterface;
17
use hiqdev\php\billing\plan\PlanInterface;
18
use hiqdev\php\billing\sale\Sale;
19
use hiqdev\php\billing\sale\SaleInterface;
20
use hiqdev\php\billing\target\Target;
21
use hiqdev\php\billing\tests\support\bill\SimpleBillRepository;
22
use hiqdev\php\billing\tools\Aggregator;
23
use hiqdev\php\billing\tools\AggregatorInterface;
24
use hiqdev\php\billing\tools\Merger;
25
use hiqdev\php\billing\tools\MergerInterface;
26
27
class SimpleBilling extends Billing
28
{
29
    public function __construct(
30
        CalculatorInterface $calculator = null,
31
        AggregatorInterface $aggregator = null,
32
        MergerInterface $merger = null,
33
        $repository = null
34
    ) {
35
        $calculator = $calculator ?: new SimpleCalculator();
36
        $aggregator = $aggregator ?: new Aggregator($calculator->getGeneralizer());
37
        $merger = $merger ?: new Merger();
38
        $repository = $repository ?: new SimpleBillRepository();
39
40
        parent::__construct($calculator, $aggregator, $merger, $repository, null);
41
    }
42
43
    public function getBillRepository(): BillRepositoryInterface
44
    {
45
        return $this->repository;
46
    }
47
48
    public static function fromPlan(PlanInterface $plan, CustomerInterface $customer = null)
49
    {
50
        $customer = $customer ?? $plan->getSeller();
51
        $sale = new Sale(null, Target::any(), $customer, $plan);
52
53
        return self::fromSale($sale);
54
    }
55
56
    public static function fromSale(SaleInterface $sale)
57
    {
58
        return new self(new SimpleCalculator(null, $sale));
59
    }
60
}
61