These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Finance module for HiPanel |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/hipanel-module-finance |
||
6 | * @package hipanel-module-finance |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hipanel\modules\finance\logic\bill; |
||
12 | |||
13 | use hipanel\modules\finance\forms\BillForm; |
||
14 | use hipanel\modules\finance\models\Bill; |
||
15 | use hipanel\modules\finance\models\Charge; |
||
16 | use hipanel\modules\server\models\Consumption; |
||
17 | use Yii; |
||
18 | |||
19 | /** |
||
20 | * Class MonthlyQuantity. |
||
21 | * |
||
22 | * @author Dmytro Naumenko <[email protected]> |
||
23 | */ |
||
24 | class MonthlyQuantity extends DefaultQuantityFormatter implements ContextAwareQuantityFormatter |
||
25 | { |
||
26 | /** @var Bill|Charge */ |
||
27 | protected $model; |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function format(): string |
||
33 | { |
||
34 | $text = Yii::t('hipanel:finance', '{quantity, plural, one{# day} other{# days}}', ['quantity' => $this->getClientValue()]); |
||
35 | |||
36 | return $text; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function getValue(): string |
||
43 | { |
||
44 | return $this->getQuantity()->getQuantity() / $this->getNumberOfDays(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | public function getClientValue(): string |
||
51 | { |
||
52 | return round($this->getQuantity()->getQuantity() * $this->getNumberOfDays()); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return false|string |
||
57 | */ |
||
58 | protected function getNumberOfDays() |
||
59 | { |
||
60 | return date('t', strtotime($this->model->time)); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param $context |
||
65 | * @return ContextAwareQuantityFormatter |
||
66 | */ |
||
67 | public function setContext($context): ContextAwareQuantityFormatter |
||
68 | { |
||
69 | if (!$context instanceof Bill && !$context instanceof Charge && !$context instanceof BillForm && !$context instanceof Consumption) { |
||
0 ignored issues
–
show
|
|||
70 | throw new \OutOfBoundsException(sprintf( |
||
71 | 'Context "%s" is not supported by Monthly quantity', |
||
72 | get_class($context) |
||
73 | )); |
||
74 | } |
||
75 | |||
76 | $this->model = $context; |
||
77 | |||
78 | return $this; |
||
79 | } |
||
80 | } |
||
81 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.