Issues (434)

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/forms/ServerTariffForm.php (10 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\forms;
12
13
use hipanel\helpers\ArrayHelper;
14
use hipanel\modules\finance\logic\ServerTariffCalculatorInterface;
15
use hipanel\modules\finance\models\Resource;
16
use hipanel\modules\finance\models\ServerResource;
17
use Yii;
18
use yii\web\UnprocessableEntityHttpException;
19
20
class ServerTariffForm extends AbstractTariffForm
21
{
22
    public $note;
23
    public $label;
24
25 View Code Duplication
    public function load($data, $formName = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $this->setAttributes($data[$this->formName()]);
28
        $this->setResources($data[(new ServerResource())->formName()]);
29
30
        return true;
31
    }
32
33 View Code Duplication
    public function rules()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $rules = parent::rules();
36
        $rules[] = [['note', 'label'], 'safe', 'on' => ['create', 'update']];
37
        unset($rules['parent-id-required']);
38
39
        return $rules;
40
    }
41
42
    /**
43
     * @return \hipanel\modules\finance\models\ServerResource[]
44
     */
45 View Code Duplication
    public function getHardwareResources()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        /** @var ServerResource[] $resources */
48
        $resources = array_filter($this->tariff->resources, function ($model) {
49
            /** @var ServerResource $model */
50
            return $model->isHardwareTypeCorrect();
51
        });
52
53
        if (empty($result)) {
54
            return [];
55
        }
56
57
        $order = array_keys(reset($resources)->getHardwareTypes());
58
59
        return $this->sortResourcesByDefinedOrder($resources, $order, 'model_type');
60
    }
61
62
    /**
63
     * @param ServerResource[] $resources
64
     * @param array $order array of ordered values. $resources array will be re-ordered according this order
65
     * @param string $key the key that will be used to re-order
66
     * @return array
67
     */
68 View Code Duplication
    private function sortResourcesByDefinedOrder($resources, $order, $key)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $result = [];
71
        $resources = ArrayHelper::index($resources, $key);
72
73
        foreach ($order as $type) {
74
            if (isset($resources[$type])) {
75
                $result[] = $resources[$type];
76
            }
77
        }
78
79
        return $result;
80
    }
81
82
    /**
83
     * @return ServerResource[]
84
     */
85
    public function getOrFakeOveruseResources()
86
    {
87
        $types = (new ServerResource())->getTypes();
88
        $resources = $this->getOveruseResources();
89
90
        $result = [];
91
92
        foreach ($types as $type => $name) {
93
            foreach ($resources as $resource) {
94
                if ($resource->type === $type) {
95
                    $result[] = $resource;
96
                    continue 2;
97
                }
98
            }
99
100
            $result[] = (new ServerResource(['type' => $type, 'tariff_id' => $this->tariff->id]));
101
        }
102
103
        return $result;
104
    }
105
106
    /**
107
     * @return \hipanel\modules\finance\models\ServerResource[]
108
     */
109 View Code Duplication
    public function getOveruseResources()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        /** @var ServerResource[] $resources */
112
        $resources = array_filter($this->tariff->resources, function ($model) {
113
            /** @var ServerResource $model */
114
            return $model->isTypeCorrect();
115
        });
116
117
        if (empty($resources)) {
118
            return [];
119
        }
120
121
        $order = array_keys(reset($resources)->getTypes());
122
123
        return $this->sortResourcesByDefinedOrder($resources, $order, 'type');
124
    }
125
126 View Code Duplication
    public function getParentOveruseResource($type_id)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        return reset(array_filter($this->parentTariff->resources, function ($resource) use ($type_id) {
129
            /** @var ServerResource $resource */
130
            return strcmp($resource->type_id, $type_id) === 0 && $resource->isTypeCorrect();
131
        }));
132
    }
133
134
    /**
135
     * @return \hipanel\modules\finance\models\ServerResource[]
136
     */
137 View Code Duplication
    public function getParentHardwareResource($object_id)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
    {
139
        return reset(array_filter($this->parentTariff->resources, function ($resource) use ($object_id) {
140
            /** @var ServerResource $resource */
141
            return strcmp($resource->object_id, $object_id) === 0 && $resource->isHardwareTypeCorrect();
142
        }));
143
    }
144
145
    /** {@inheritdoc} */
146 View Code Duplication
    public function setResources($resources)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    {
148
        $result = [];
149
        foreach ((array) $resources as $resource) {
150
            if ($resource instanceof ServerResource) {
151
                $result[] = $resource;
152
                continue;
153
            }
154
155
            $model = new ServerResource(['scenario' => $this->scenario]);
156
157
            if ($model->load($resource, '') && $model->validate()) {
158
                $result[] = $model;
159
            } else {
160
                throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors()));
161
            }
162
        }
163
164
        $this->_resources = $result;
165
166
        return $this;
167
    }
168
169 View Code Duplication
    protected function calculator()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
    {
171
        if (!isset($this->_calculator)) {
172
            $this->_calculator = Yii::createObject(ServerTariffCalculatorInterface::class, [[$this->tariff]]);
173
        }
174
175
        return $this->_calculator;
176
    }
177
178 View Code Duplication
    protected function parentCalculator()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179
    {
180
        if (!isset($this->_parentCalculator)) {
181
            $this->_parentCalculator = Yii::createObject(ServerTariffCalculatorInterface::class, [[$this->parentTariff]]);
182
        }
183
184
        return $this->_parentCalculator;
185
    }
186
}
187