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-2020, HiQDev (http://hiqdev.com/) |
||||
9 | */ |
||||
10 | |||||
11 | namespace hiqdev\php\billing\price; |
||||
12 | |||||
13 | use hiqdev\php\billing\plan\PlanInterface; |
||||
14 | use hiqdev\php\billing\target\TargetInterface; |
||||
15 | use hiqdev\php\billing\type\TypeInterface; |
||||
0 ignored issues
–
show
|
|||||
16 | use hiqdev\php\units\QuantityInterface; |
||||
17 | use Money\Money; |
||||
18 | |||||
19 | /** |
||||
20 | * Rate Price: |
||||
21 | * - holds rate in percents |
||||
22 | * e.g. rate for referral payments calculation |
||||
23 | * @see PriceInterface |
||||
24 | * |
||||
25 | * @author Andrii Vasyliev <[email protected]> |
||||
26 | */ |
||||
27 | class RatePrice extends AbstractPrice implements PriceWithRateInterface |
||||
28 | { |
||||
29 | protected float $rate; |
||||
30 | |||||
31 | public function __construct( |
||||
32 | $id, |
||||
33 | TypeInterface $type, |
||||
34 | TargetInterface $target, |
||||
35 | ?PlanInterface $plan, |
||||
36 | float $rate |
||||
37 | ) { |
||||
38 | parent::__construct($id, $type, $target, $plan); |
||||
39 | $this->rate = $rate; |
||||
40 | } |
||||
41 | |||||
42 | public function getRate(): float |
||||
43 | { |
||||
44 | return $this->rate; |
||||
45 | } |
||||
46 | |||||
47 | public function calculateSum(QuantityInterface $quantity): ?Money |
||||
48 | { |
||||
49 | $sum = $quantity->multiply((string) -$this->rate); |
||||
50 | $currency = strtoupper($sum->getUnit()->getName()); |
||||
51 | |||||
52 | return Money::{$currency}((int)floor($sum->getQuantity())); |
||||
0 ignored issues
–
show
It seems like
$sum->getQuantity() can also be of type string ; however, parameter $num of floor() does only seem to accept double|integer , 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
![]() |
|||||
53 | } |
||||
54 | |||||
55 | public function calculatePrice(QuantityInterface $quantity): ?Money |
||||
56 | { |
||||
57 | $sum = $this->calculateSum($quantity); |
||||
58 | if ($sum === null) { |
||||
59 | return null; |
||||
60 | } |
||||
61 | |||||
62 | $usage = $this->calculateUsage($quantity); |
||||
63 | if ($usage === null) { |
||||
64 | return null; |
||||
65 | } |
||||
66 | |||||
67 | return $sum->divide(sprintf('%.14F', $usage->getQuantity())); |
||||
68 | } |
||||
69 | |||||
70 | public function calculateUsage(QuantityInterface $quantity): ?QuantityInterface |
||||
71 | { |
||||
72 | return $quantity; |
||||
73 | } |
||||
74 | } |
||||
75 |
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