Completed
Push — master ( d75f5b...e2e89f )
by Andrii
14:28
created

SimpleBilling::fromPlan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\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\SaleInterface;
19
use hiqdev\php\billing\target\Target;
20
use hiqdev\php\billing\tests\support\bill\SimpleBillRepository;
21
use hiqdev\php\billing\tools\Aggregator;
22
use hiqdev\php\billing\tools\AggregatorInterface;
23
use hiqdev\php\billing\tools\Merger;
24
use hiqdev\php\billing\tools\MergerInterface;
25
use hiqdev\php\billing\sale\Sale;
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());
0 ignored issues
show
Bug introduced by
The method getGeneralizer() does not exist on hiqdev\php\billing\order\CalculatorInterface. It seems like you code against a sub-type of hiqdev\php\billing\order\CalculatorInterface such as hiqdev\php\billing\tests...\order\SimpleCalculator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        $aggregator = $aggregator ?: new Aggregator($calculator->/** @scrutinizer ignore-call */ getGeneralizer());
Loading history...
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 ??= $plan->getSeller();
51
        $sale = new Sale(null, Target::any(), $customer, $plan);
0 ignored issues
show
Bug introduced by
It seems like $customer can also be of type null; however, parameter $customer of hiqdev\php\billing\sale\Sale::__construct() does only seem to accept hiqdev\php\billing\customer\CustomerInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $sale = new Sale(null, Target::any(), /** @scrutinizer ignore-type */ $customer, $plan);
Loading history...
52
        return self::fromSale($sale);
53
    }
54
55
    public static function fromSale(SaleInterface $sale)
56
    {
57
        return new self(new SimpleCalculator(null, $sale));
58
    }
59
}
60