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\price; |
||
12 | |||
13 | use hiqdev\php\billing\charge\ChargeModifier; |
||
14 | use hiqdev\php\billing\charge\FormulaChargeModifierTrait; |
||
0 ignored issues
–
show
|
|||
15 | use hiqdev\php\billing\plan\PlanInterface; |
||
16 | use hiqdev\php\billing\target\TargetInterface; |
||
17 | use hiqdev\php\billing\type\TypeInterface; |
||
18 | use hiqdev\php\units\Quantity; |
||
19 | use hiqdev\php\units\QuantityInterface; |
||
20 | use Money\Money; |
||
21 | |||
22 | /** |
||
23 | * Single Price. |
||
24 | * |
||
25 | * - no charge for quantity less then prepaid |
||
26 | * - same price for any quantity above prepaid |
||
27 | * |
||
28 | * TODO add `$modifier` property instead of FormulaChargeModifierTrait |
||
29 | * |
||
30 | * @see PriceInterface |
||
31 | * |
||
32 | * @author Andrii Vasyliev <[email protected]> |
||
33 | */ |
||
34 | class SinglePrice extends AbstractPrice |
||
35 | { |
||
36 | /** |
||
37 | * @var QuantityInterface prepaid quantity also implies Unit |
||
38 | */ |
||
39 | protected $prepaid; |
||
40 | |||
41 | /** |
||
42 | * @var Money |
||
43 | */ |
||
44 | protected $price; |
||
45 | 32 | ||
46 | public function __construct( |
||
47 | $id, |
||
48 | TypeInterface $type, |
||
49 | TargetInterface $target, |
||
50 | PlanInterface $plan = null, |
||
51 | QuantityInterface $prepaid, |
||
52 | Money $price |
||
53 | 32 | ) { |
|
54 | 32 | parent::__construct($id, $type, $target, $plan); |
|
55 | 32 | $this->prepaid = $prepaid; |
|
56 | 32 | $this->price = $price; |
|
57 | } |
||
58 | 1 | ||
59 | public function getPrepaid() |
||
60 | 1 | { |
|
61 | return $this->prepaid; |
||
62 | } |
||
63 | 1 | ||
64 | public function getPrice() |
||
65 | 1 | { |
|
66 | return $this->price; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | 18 | */ |
|
72 | public function calculateUsage(QuantityInterface $quantity): ?QuantityInterface |
||
73 | 18 | { |
|
74 | $usage = $quantity->convert($this->prepaid->getUnit())->subtract($this->prepaid); |
||
75 | 18 | ||
76 | return $usage->isPositive() ? $usage : null; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | * Same price for any usage. |
||
82 | 14 | */ |
|
83 | public function calculatePrice(QuantityInterface $usage): ?Money |
||
84 | 14 | { |
|
85 | return $this->price; |
||
86 | } |
||
87 | |||
88 | public function jsonSerialize() |
||
89 | { |
||
90 | return array_merge(parent::jsonSerialize(), [ |
||
91 | 'prepaid' => $this->prepaid, |
||
92 | 'price' => $this->price, |
||
93 | ]); |
||
94 | } |
||
95 | } |
||
96 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths