Issues (426)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/grid/ChargeGridView.php (4 issues)

Upgrade to new PHP Analysis Engine

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\grid;
12
13
use hipanel\grid\CurrencyColumn;
14
use hipanel\grid\MainColumn;
15
use hipanel\modules\client\grid\ClientColumn;
16
use hipanel\modules\finance\logic\bill\QuantityFormatterFactoryInterface;
17
use hipanel\modules\finance\models\Charge;
18
use hipanel\modules\finance\models\ChargeSearch;
19
use hipanel\modules\finance\widgets\BillType;
20
use hipanel\modules\finance\widgets\BillTypeFilter;
21
use hipanel\modules\finance\widgets\LinkToObjectResolver;
22
use hipanel\widgets\IconStateLabel;
23
use hiqdev\combo\StaticCombo;
24
use hiqdev\higrid\DataColumn;
25
use Yii;
26
use yii\helpers\Html;
27
28
/**
29
 * Class ChargeGridView.
30
 *
31
 * @author Dmytro Naumenko <[email protected]>
32
 */
33
class ChargeGridView extends \hipanel\grid\BoxedGridView
34
{
35
    /**
36
     * @var QuantityFormatterFactoryInterface
37
     */
38
    private $formatterFactory;
39
40
    /**
41
     * ChargeGridView constructor.
42
     *
43
     * @param QuantityFormatterFactoryInterface $formatterFactory
44
     * @param array $config
45
     */
46
    public function __construct(QuantityFormatterFactoryInterface $formatterFactory, array $config = [])
47
    {
48
        parent::__construct($config);
49
        $this->formatterFactory = $formatterFactory;
50
    }
51
52
    public function columns()
53
    {
54
        return array_merge(parent::columns(), [
55
            'label' => [
56
                'attribute' => 'label_ilike',
57
                'sortAttribute' => 'label_ilike',
58
                'label' => Yii::t('hipanel', 'Description'),
59
                'value' => function (Charge $model): string {
60
                    return $model->label ?? '';
0 ignored issues
show
The property label does not exist on object<hipanel\modules\finance\models\Charge>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
                },
62
            ],
63
            'tariff' => [
64
                'attribute' => 'tariff_id',
65
                'label' => Yii::t('hipanel', 'Plan'),
66
                'filter' => false,
67
                'format' => 'html',
68
                'value' => function (Charge $model): string {
69
                    return $this->tariffLink($model);
70
                },
71
            ],
72
            'type_label' => [
73
                'label' => Yii::t('hipanel', 'Type'),
74
                'format' => 'raw',
75
                'value' => function (Charge $model) {
76
                    return BillType::widget([
77
                        'model' => $model,
78
                        'field' => 'ftype',
79
                        'labelField' => 'type_label',
80
                    ]);
81
                },
82
                'filterAttribute' => 'type',
83
                'filter' => function (DataColumn $column, ChargeSearch $filterModel): string {
84
                    return BillTypeFilter::widget([
85
                        'options' => ['class' => 'form-control text-right', 'style' => 'max-width: 12em'],
86
                        'attribute' => 'ftype',
87
                        'model' => $filterModel,
88
                    ]);
89
                },
90
            ],
91
            'sum' => [
92
                'class' => CurrencyColumn::class,
93
                'attribute' => 'sum',
94
                'sortAttribute' => 'sum',
95
                'colors' => ['danger' => 'warning'],
96
                'headerOptions' => ['class' => 'text-right'],
97
                'filter' => false,
98
                'contentOptions' => function ($model) {
99
                    return ['class' => 'text-right' . ($model->sum > 0 ? ' text-bold' : '')];
100
                },
101
            ],
102
            'name' => [
103
                'attribute' => 'name_ilike',
104
                'label' => Yii::t('hipanel', 'Object'),
105
                'format' => 'raw',
106
                'value' => function (Charge $model) {
107
                    $result = LinkToObjectResolver::widget([
108
                        'model' => $model,
109
                        'idAttribute' => 'object_id',
110
                        'typeAttribute' => 'class',
111
                        'labelAttribute' => 'name',
112
                    ]) . ($model->label ? " &ndash; $model->label" : '');
0 ignored issues
show
The property label does not exist on object<hipanel\modules\finance\models\Charge>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
113
114
                    if ($model->commonObject->id !== null && $model->commonObject->id !== $model->latestCommonObject->id) {
115
                        $result .= ' ' . Html::tag(
116
                            'span',
117
                            Yii::t('hipanel:finance', 'Now it is in {objectLink}', [
118
                                'objectLink' => LinkToObjectResolver::widget([
119
                                    'model'          => $model->latestCommonObject,
120
                                    'idAttribute'    => 'id',
121
                                    'labelAttribute' => 'name',
122
                                    'typeAttribute'  => 'type',
123
                                ]),
124
                            ]),
125
                            ['class' => 'badge', 'style' => 'background-color: #f89406;']
126
                        );
127
                    }
128
129
                    return $result;
130
                },
131
            ],
132
            'quantity' => [
133
                'attribute' => 'quantity',
134
                'format' => 'raw',
135
                'filter' => false,
136
                'value' => function (Charge $model) {
137
                    return $this->renderQuantity($model);
138
                },
139
            ],
140
            'time' => [
141
                'format' => 'raw',
142
                'filter' => false,
143
                'contentOptions' => ['class' => 'text-nowrap'],
144
                'value' => function ($model) {
145
                    list($date, $time) = explode(' ', $model->time, 2);
146
147
                    return $model->isMonthly() && $time === '00:00:00'
148
                        ? Yii::$app->formatter->asDate($date, 'LLLL y')
149
                        : Yii::$app->formatter->asDateTime($model->time);
150
                },
151
            ],
152
            'is_payed' => [
153
                'attribute' => 'is_payed',
154
                'format' => 'raw',
155
                'enableSorting' => false,
156
                'filter' => StaticCombo::widget([
157
                    'attribute' => 'is_payed',
158
                    'model' => $this->filterModel,
159
                    'data' => [
160
                        0 => Yii::t('hipanel:finance', 'Charge not paid'),
161
                        1 => Yii::t('hipanel:finance', 'Charge paid'),
162
                    ],
163
                    'hasId' => true,
164
                    'inputOptions' => ['id' => 'is_payed'],
165
                ]),
166
                'contentOptions' => ['class' => 'text-center'],
167
                'headerOptions' => ['class' => 'text-center'],
168
                'value' => static function (Charge $model) {
169
                    return IconStateLabel::widget([
170
                        'model' => $model,
171
                        'attribute' => 'is_payed',
172
                        'icons' => ['fa-check', 'fa-times'],
173
                        'colors' => ['#00a65a', '#dd4b39'],
174
                        'messages' => [
175
                            Yii::t('hipanel:finance', 'Charge paid'),
176
                            Yii::t('hipanel:finance', 'Charge not paid'),
177
                        ],
178
                    ]);
179
                }
180
            ]
181
        ]);
182
    }
183
184
    /**
185
     * @param Charge $model
186
     * @return string|null
187
     */
188
    public function tariffLink(Charge $model): ?string
189
    {
190
        $canSeeLink = Yii::$app->user->can('plan.create');
191
192
        return $canSeeLink ? Html::a($model->tariff, ['@plan/view', 'id' => $model->tariff_id]) : $model->tariff;
0 ignored issues
show
The property tariff_id does not seem to exist. Did you mean tariff?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
$model->tariff is of type object<hipanel\modules\finance\models\Tariff>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
193
    }
194
195
    /**
196
     * @return string
197
     */
198
    private function renderQuantity(Charge $charge): string
199
    {
200
        $formatter = $this->formatterFactory->forCharge($charge);
201
202
        if ($formatter !== null) {
203
            return Html::tag('nobr', Html::tag('b', $formatter->format()));
204
        }
205
206
        return '';
207
    }
208
}
209