This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
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. ![]() |
|||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
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. ![]() |
|||
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. ![]() |
|||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
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 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state