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/VdsTariffForm.php (8 issues)

duplicate/similar methods.

Duplication Informational

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\models\ServerResource;
15
use yii\web\UnprocessableEntityHttpException;
16
17
class VdsTariffForm extends AbstractTariffForm
18
{
19
    public $note;
20
    public $label;
21
22 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...
23
    {
24
        $this->setAttributes($data[$this->formName()]);
25
        $this->setResources($data[(new ServerResource())->formName()]);
26
27
        return true;
28
    }
29
30 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...
31
    {
32
        $rules = parent::rules();
33
        $rules[] = [['note', 'label'], 'safe', 'on' => ['create', 'update']];
34
35
        return $rules;
36
    }
37
38
    /**
39
     * @return \hipanel\modules\finance\models\ServerResource[]
40
     */
41 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...
42
    {
43
        /** @var ServerResource[] $resources */
44
        $resources = array_filter($this->tariff->resources, function ($model) {
45
            /** @var ServerResource $model */
46
            return $model->isHardwareTypeCorrect();
47
        });
48
49
        if (empty($resources)) {
50
            return [];
51
        }
52
53
        $order = array_keys(reset($resources)->getHardwareTypes());
54
55
        return $this->sortResourcesByDefinedOrder($resources, $order, 'model_type');
56
    }
57
58
    /**
59
     * @param ServerResource[] $resources
60
     * @param array $order array of ordered values. $resources array will be re-ordered according this order
61
     * @param string $key the key that will be used to re-order
62
     * @return array
63
     */
64 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...
65
    {
66
        $result = [];
67
        $resources = ArrayHelper::index($resources, $key);
68
69
        foreach ($order as $type) {
70
            if (isset($resources[$type])) {
71
                $result[] = $resources[$type];
72
            }
73
        }
74
75
        return $result;
76
    }
77
78
    /**
79
     * @return \hipanel\modules\finance\models\ServerResource[]
80
     */
81 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...
82
    {
83
        /** @var ServerResource[] $resources */
84
        $resources = array_filter($this->tariff->resources, function ($model) {
85
            /** @var ServerResource $model */
86
            return $model->isTypeCorrect();
87
        });
88
        if (empty($resources)) {
89
            return [];
90
        }
91
92
        $order = array_keys(reset($resources)->getTypes());
93
94
        return $this->sortResourcesByDefinedOrder($resources, $order, 'type');
95
    }
96
97 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...
98
    {
99
        return reset(array_filter($this->parentTariff->resources, function ($resource) use ($type_id) {
100
            /** @var ServerResource $resource */
101
            return strcmp($resource->type_id, $type_id) === 0 && $resource->isTypeCorrect();
102
        }));
103
    }
104
105
    /**
106
     * @return \hipanel\modules\finance\models\ServerResource[]
107
     */
108 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...
109
    {
110
        return reset(array_filter($this->parentTariff->resources, function ($resource) use ($object_id) {
111
            /** @var ServerResource $resource */
112
            return strcmp($resource->object_id, $object_id) === 0 && $resource->isHardwareTypeCorrect();
113
        }));
114
    }
115
116
    /** {@inheritdoc} */
117 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...
118
    {
119
        $result = [];
120
        foreach ((array) $resources as $resource) {
121
            if ($resource instanceof ServerResource) {
122
                $result[] = $resource;
123
                continue;
124
            }
125
126
            $model = new ServerResource(['scenario' => $this->scenario]);
127
128
            if ($model->load($resource, '') && $model->validate()) {
129
                $result[] = $model;
130
            } else {
131
                throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors()));
132
            }
133
        }
134
135
        $this->_resources = $result;
136
137
        return $this;
138
    }
139
}
140