Issues (141)

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/services/OTV.php (7 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
// @TODO Move this to a proper entity
3
namespace Service;
4
5
/**
6
 * Model_OTV.php
7
 * Project: yaipam
8
 * User: ktammling
9
 * Date: 13.04.17
10
 * Time: 13:48
11
 */
12
class OTV
13
{
14
    private $OTVID = 0;
15
    private $OTVName = "";
16
    private $OTVDescription = "";
17
    private $OTVDomains = array();
18
19
    private $em;
20
    private $entity;
21
22
    public function __construct($EntityManager)
23
    {
24
        $this->em = $EntityManager;
25
        $this->entity = new \Entity\Otv();
26
    }
27
28
    public function getEntity()
29
    {
30
        return $this->entity;
31
    }
32
33
34
    /**
35
     * @param int $ID
36
     * @return array
37
     */
38
    public function selectByID(int $ID)
39
    {
40
        global $dbal;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
41
42
        $queryBuilder = $dbal->createQueryBuilder();
43
44
        $otv = $queryBuilder
45
            ->select('o.OTVName', 'o.OTVID', 'd.DomainID', 'do.domain_name as DomainName', 'o.OTVDescription')
46
            ->from('otv', 'o')
47
            ->leftJoin('o', 'otv_domains', 'd', 'o.OTVID = d.OTVID')
48
            ->leftJoin('d', 'vlan_domains', 'do', 'd.DomainID = do.domain_id')
49
            ->where('o.OTVID = ?')
50
            ->setParameter(0, $ID)
51
            ->orderBy('do.domain_name', 'ASC')
52
            ->execute()
53
            ->fetchAll();
54
55
        #die(print_r($otv));
0 ignored issues
show
Unused Code Comprehensibility introduced by
88% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
        $this->setOTVID($otv[0]['OTVID']);
57
        $this->setOTVName($otv[0]['OTVName']);
58
        $this->setOTVDescription($otv[0]['OTVDescription']);
59
60
        $domains = array();
61
        foreach ($otv as $data) {
62
            $domains[] = $data['DomainID'];
63
        }
64
65
        $this->setOTVDomains($domains);
66
67
        return $otv;
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    public static function getAll(): array
74
    {
75
        global $dbal;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
76
77
        $queryBuilder = $dbal->createQueryBuilder();
78
79
        $otv = $queryBuilder
80
            ->select('o.OTVName', 'o.OTVID', 'o.OTVDescription')
81
            ->from('otv', 'o')
82
            ->orderBy('o.OTVName', 'ASC')
83
            ->execute()
84
            ->fetchAll();
85
86
        return $otv;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    public function save(): bool
93
    {
94
        global $dbal;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
95
96
        $dbal->beginTransaction();
97
98
        $queryBuilder = $dbal->createQueryBuilder();
99
100
        if ($this->getOTVID() > 0) {
101
            $update = $queryBuilder
102
                ->update('otv')
103
                ->set('OTVName', '?')
104
                ->set('OTVDescription', '?')
105
                ->where('OTVID = ?')
106
                ->setParameter(0, $this->getOTVName())
107
                ->setParameter(1, $this->getOTVDescription())
108
                ->setParameter(2, $this->getOTVID());
109
110
            if ($update->execute() === false) {
111
                $dbal->rollBack();
112
                return false;
113
            }
114
115
116
            $queryBuilder = $dbal->createQueryBuilder();
117
            $delete = $queryBuilder
118
                ->delete('otv_domains')
119
                ->where('OTVID = ?')
120
                ->setParameter(0, $this->getOTVID());
121
122
            if ($delete->execute() === false) {
123
                $dbal->rollBack();
124
                return false;
125
            }
126
127
            $queryBuilder = $dbal->createQueryBuilder();
128
            $Domains = $this->getOTVDomains();
129 View Code Duplication
            foreach ($Domains as $key => $value) {
0 ignored issues
show
This code seems to be duplicated across 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...
130
                $insert = $queryBuilder
131
                    ->insert('otv_domains')
132
                    ->setValue('OTVID', '?')
133
                    ->setValue('DomainID', '?')
134
                    ->setParameter(0, $this->getOTVID())
135
                    ->setParameter(1, $value);
136
137
                if ($insert->execute() === false) {
138
                    $dbal->rollBack();
139
                    return false;
140
                }
141
            }
142
        } else {
143
            $insert = $queryBuilder
144
                ->insert('otv')
145
                ->setValue('OTVName', '?')
146
                ->setValue('OTVDescription', '?')
147
                ->setParameter(0, $this->getOTVName())
148
                ->setParameter(1, $this->getOTVDescription());
149
150
            if (!$insert->execute()) {
151
                $dbal->rollBack();
152
                return false;
153
            }
154
155
            $this->setOTVID($dbal->lastInsertId());
156
157
            $queryBuilder = $dbal->createQueryBuilder();
158
159
            $Domains = $this->getOTVDomains();
160 View Code Duplication
            foreach ($Domains as $key => $value) {
0 ignored issues
show
This code seems to be duplicated across 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...
161
                $insert = $queryBuilder
162
                    ->insert('otv_domains')
163
                    ->setValue('OTVID', '?')
164
                    ->setValue('DomainID', '?')
165
                    ->setParameter(0, $this->getOTVID())
166
                    ->setParameter(1, $value);
167
168
                if (!$insert->execute()) {
169
                    $dbal->rollBack();
170
                    return false;
171
                }
172
            }
173
        }
174
175
        $dbal->commit();
176
177
        return  true;
178
    }
179
180
    /**
181
     * @return bool
182
     */
183
    public function delete(): bool
184
    {
185
        global $dbal;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
186
187
        $queryBuilder = $dbal->createQueryBuilder();
188
189
        $dbal->beginTransaction();
190
191
        $delete = $queryBuilder
192
            ->delete('otv')
193
            ->where('OTVID = ?')
194
            ->setParameter(0, $this->getOTVID());
195
196
        if ($delete->execute() === false) {
197
            $dbal->rollBack();
198
            return false;
199
        }
200
201
        $delete = $queryBuilder
202
            ->delete('otv_domains')
203
            ->where('OTVID = ?')
204
            ->setParameter(0, $this->getOTVID());
205
206
        if ($delete->execute() === false) {
207
            $dbal->rollBack();
208
            return false;
209
        }
210
211
        $update = $queryBuilder
212
            ->update('vlans')
213
            ->set('OTVDomain', 0)
214
            ->where('OTVDomain = ?')
215
            ->setParameter(0, $this->getOTVID());
216
217
        if ($update->execute() === false) {
218
            $dbal->rollBack();
219
            return false;
220
        }
221
222
        $dbal->commit();
223
224
        return true;
225
    }
226
227
    /**
228
     * @return int
229
     */
230
    public function getOTVID(): int
231
    {
232
        return $this->OTVID;
233
    }
234
235
    /**
236
     * @param int $OTVID
237
     */
238
    public function setOTVID(int $OTVID)
239
    {
240
        $this->OTVID = $OTVID;
241
    }
242
243
    /**
244
     * @return string
245
     */
246
    public function getOTVName(): string
247
    {
248
        return $this->OTVName;
249
    }
250
251
    /**
252
     * @param string $OTVName
253
     */
254
    public function setOTVName(string $OTVName)
255
    {
256
        $this->OTVName = $OTVName;
257
    }
258
259
    /**
260
     * @return array
261
     */
262
    public function getOTVDomains(): array
263
    {
264
        return $this->OTVDomains;
265
    }
266
267
    /**
268
     * @param array $OTVDomains
269
     */
270
    public function setOTVDomains(array $OTVDomains)
271
    {
272
        $this->OTVDomains = $OTVDomains;
273
    }
274
275
    /**
276
     * @return string
277
     */
278
    public function getOTVDescription(): string
279
    {
280
        return $this->OTVDescription;
281
    }
282
283
    /**
284
     * @param string $OTVDescription
285
     */
286
    public function setOTVDescription(string $OTVDescription)
287
    {
288
        $this->OTVDescription = $OTVDescription;
289
    }
290
}
291