Completed
Push — master ( 988510...c327dd )
by Andrii
02:29
created

SimpleBilling::calculate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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-2018, 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\order\Billing;
15
use hiqdev\php\billing\order\BillingInterface;
16
use hiqdev\php\billing\order\Calculator;
17
use hiqdev\php\billing\order\OrderInterface;
18
use hiqdev\php\billing\plan\PlanInterface;
19
use hiqdev\php\billing\sale\SaleInterface;
20
use hiqdev\php\billing\tests\support\plan\SimplePlanRepository;
21
use hiqdev\php\billing\tests\support\sale\SimpleSaleRepository;
22
use hiqdev\php\billing\tools\Aggregator;
23
use hiqdev\php\billing\tools\Merger;
24
25
class SimpleBilling implements BillingInterface
26
{
27
    private $billing;
28
29
    public function __construct(SaleInterface $sale = null, PlanInterface $plan = null)
30
    {
31
        $saleRepo = $sale ? new SimpleSaleRepository($sale) : null;
32
        $planRepo = $plan ? new SimplePlanRepository($plan) : null;
33
        $calculator = new Calculator(new Generalizer(), $saleRepo, $planRepo);
34
        $aggregator = new Aggregator(new Generalizer());
35
        $this->billing = new Billing($calculator, $aggregator, new Merger(), null);
36
    }
37
38
    public function calculate(OrderInterface $order): array
39
    {
40
        return $this->billing->calculate($order);
41
    }
42
43
44
    public function perform(OrderInterface $order): array
45
    {
46
        return $this->billing->perform($order);
47
    }
48
}
49