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/DomainTariffForm.php (9 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\modules\finance\logic\IntegrityException;
14
use hipanel\modules\finance\models\DomainResource;
15
use hipanel\modules\finance\models\DomainService;
16
use yii\web\UnprocessableEntityHttpException;
17
18
class DomainTariffForm extends AbstractTariffForm
19
{
20
    /**
21
     * @var array Domain zones
22
     * Key - zone name (com, net, ...)
23
     * Value - zone id
24
     * @see getZones
25
     */
26
    protected $zones;
27
28 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...
29
    {
30
        $this->setAttributes($data[$this->formName()]);
31
        $this->setResources($data[(new DomainResource())->formName()]);
0 ignored issues
show
Deprecated Code introduced by
The class hipanel\modules\finance\models\DomainResource has been deprecated with message: Is implemented in plan module

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
32
33
        $this->initTariff();
34
35
        return true;
36
    }
37
38
    /**
39
     * @return DomainService[]
40
     */
41
    public function getServices()
42
    {
43
        return $this->createServices($this->tariff->resources);
44
    }
45
46
    /**
47
     * @return DomainService[]
48
     */
49
    public function getParentServices()
50
    {
51
        return $this->createServices($this->parentTariff->resources);
52
    }
53
54
    /**
55
     * @param $resources
56
     * @return DomainService[]
57
     */
58
    protected function createServices($resources)
59
    {
60
        $result = [];
61
        $resource = reset($resources);
62
63
        foreach ($resource->getServiceTypes() as $type => $name) {
64
            $service = new DomainService([
65
                'name' => $name,
66
                'type' => $type,
67
            ]);
68
69
            foreach ($resources as $resource) {
70
                if ($service->tryResourceAssignation($resource) && $service->isFulfilled()) {
71
                    $result[$type] = $service;
72
                    break;
73
                }
74
            }
75
        }
76
77
        return $result;
78
    }
79
80 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...
81
    {
82
        $result = [];
83
        foreach ($resources as $resource) {
84
            if ($resource instanceof DomainResource) {
85
                $result[] = $resource;
86
                continue;
87
            }
88
89
            $model = new DomainResource(['scenario' => $this->scenario]);
0 ignored issues
show
Deprecated Code introduced by
The class hipanel\modules\finance\models\DomainResource has been deprecated with message: Is implemented in plan module

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
90
91
            if ($model->load($resource, '') && $model->validate()) {
92
                $result[] = $model;
93
            } else {
94
                throw new UnprocessableEntityHttpException('Failed to load resource model: ' . reset($model->getFirstErrors()));
0 ignored issues
show
$model->getFirstErrors() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
95
            }
96
        }
97
98
        $this->_resources = $result;
99
100
        return $this;
101
    }
102
103 View Code Duplication
    public function getZoneResources($zone)
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...
104
    {
105
        $id = $this->zones[$zone];
106
107
        $result = [];
108
109
        foreach ($this->tariff->resources as $resource) {
110
            if (strcmp($resource->object_id, $id) === 0 && $resource->isTypeCorrect()) {
111
                $result[$resource->type] = $resource;
112
            }
113
        }
114
115
        if (empty($result)) {
116
            return [];
117
        }
118
119
        $types = $resource->getTypes();
0 ignored issues
show
The variable $resource seems to be defined by a foreach iteration on line 109. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
120
        if (count($result) !== count($types)) {
121
            throw new IntegrityException('Found ' . count($result) . ' resources for zone "' . $zone . '". Must be exactly ' . count($types));
122
        }
123
124
        // sorts $result by order of $resource->getTypes()
125
        $result = array_merge($types, $result);
126
127
        return $result;
128
    }
129
130 View Code Duplication
    public function getZoneParentResources($zone)
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...
131
    {
132
        $id = $this->zones[$zone];
133
134
        $result = [];
135
136
        foreach ($this->parentTariff->resources as $resource) {
137
            if (strcmp($resource->object_id, $id) === 0 && $resource->isTypeCorrect()) {
138
                $result[$resource->type] = $resource;
139
            }
140
        }
141
142
        if (empty($result)) {
143
            return [];
144
        }
145
146
        $types = $resource->getTypes();
0 ignored issues
show
The variable $resource seems to be defined by a foreach iteration on line 136. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
147
        if (count($result) !== count($types)) {
148
            throw new IntegrityException('Found ' . count($result) . ' resources for zone "' . $zone . '". Must be exactly ' . count($types));
149
        }
150
151
        // sorts $result by order of $resource->getTypes()
152
        $result = array_merge($types, $result);
153
154
        return $result;
155
    }
156
157
    public function getZones()
158
    {
159
        return $this->zones;
160
    }
161
162
    public function setZones($zones)
163
    {
164
        $this->zones = array_flip($zones);
165
    }
166
}
167