TemplatePrice   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 43
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 4 1
A getSubprice() 0 3 1
A getSubprices() 0 3 1
A __construct() 0 12 1
1
<?php
2
/**
3
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\price;
12
13
use hiqdev\php\billing\plan\PlanInterface;
14
use hiqdev\php\billing\price\SinglePrice;
15
use hiqdev\php\billing\target\TargetInterface;
16
use hiqdev\php\billing\type\TypeInterface;
17
use hiqdev\php\units\QuantityInterface;
18
use Money\Money;
19
20
/**
21
 * Class TemplatePrice.
22
 *
23
 * @author Dmytro Naumenko <[email protected]>
24
 */
25
class TemplatePrice extends SinglePrice
26
{
27
    /**
28
     * @var Money[]
29
     */
30
    protected $subprices = [];
31
32
    public function __construct(
33
        $id,
34
        TypeInterface $type,
35
        TargetInterface $target,
36
        PlanInterface $plan = null,
37
        QuantityInterface $prepaid,
38
        Money $price,
39
        array $subprices
40
    ) {
41
        parent::__construct($id, $type, $target, $plan, $prepaid, $price);
42
43
        $this->subprices = $subprices;
44
    }
45
46
    public function jsonSerialize()
47
    {
48
        return array_merge(parent::jsonSerialize(), [
49
            'subprices' => $this->subprices,
50
        ]);
51
    }
52
53
    /**
54
     * @return Money[]
55
     */
56
    public function getSubprices(): array
57
    {
58
        return $this->subprices;
59
    }
60
61
    /**
62
     * @param string $currencyCode
63
     * @return string the subprice in decimal format (e.g. `10.25`)
64
     */
65
    public function getSubprice($currencyCode): string
66
    {
67
        return $this->subprices[strtoupper($currencyCode)] ?? '0';
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->subprices[...($currencyCode)] ?? '0' could return the type Money\Money which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
68
    }
69
}
70