Completed
Push — master ( c327dd...cf53d8 )
by Andrii
02:35
created

SimpleBilling::getBillRepository()   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 0
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\bill\BillRepositoryInterface;
14
use hiqdev\php\billing\charge\Generalizer;
15
use hiqdev\php\billing\order\Billing;
16
use hiqdev\php\billing\order\BillingInterface;
17
use hiqdev\php\billing\order\Calculator;
18
use hiqdev\php\billing\order\OrderInterface;
19
use hiqdev\php\billing\plan\PlanInterface;
20
use hiqdev\php\billing\sale\SaleInterface;
21
use hiqdev\php\billing\tests\support\bill\SimpleBillRepository;
22
use hiqdev\php\billing\tests\support\plan\SimplePlanRepository;
23
use hiqdev\php\billing\tests\support\sale\SimpleSaleRepository;
24
use hiqdev\php\billing\tools\Aggregator;
25
use hiqdev\php\billing\tools\Merger;
26
27
class SimpleBilling implements BillingInterface
28
{
29
    private $billing;
30
31
    private $billRepository;
32
33
    public function __construct(SaleInterface $sale = null, PlanInterface $plan = null)
34
    {
35
        $saleRepo = $sale ? new SimpleSaleRepository($sale) : null;
36
        $planRepo = $plan ? new SimplePlanRepository($plan) : null;
37
        $this->billRepository = $plan ? new SimpleBillRepository() : null;
38
        $calculator = new Calculator(new Generalizer(), $saleRepo, $planRepo);
39
        $aggregator = new Aggregator(new Generalizer());
40
        $this->billing = new Billing($calculator, $aggregator, new Merger(), $this->billRepository);
41
    }
42
43
    public function calculate(OrderInterface $order): array
44
    {
45
        return $this->billing->calculate($order);
46
    }
47
48
    public function perform(OrderInterface $order): array
49
    {
50
        return $this->billing->perform($order);
51
    }
52
53
    public function getBillRepository(): BillRepositoryInterface
54
    {
55
        return $this->billRepository;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->billRepository could return the type null which is incompatible with the type-hinted return hiqdev\php\billing\bill\BillRepositoryInterface. Consider adding an additional type-check to rule them out.
Loading history...
56
    }
57
}
58