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 | |||
3 | namespace Opeyemiabiodun\PotatoORM\Connections; |
||
4 | |||
5 | use InvalidArgumentException; |
||
6 | |||
7 | trait DatabaseTransactionsTrait |
||
8 | { |
||
9 | /** |
||
10 | * Creates a record in the database. |
||
11 | * |
||
12 | * @param string $table The table where the a new record is made. |
||
13 | * @param array $record The record to be made in the database. |
||
14 | * |
||
15 | * @return bool |
||
16 | */ |
||
17 | 1 | public function createRecord($table, $record) |
|
18 | { |
||
19 | 1 | if (gettype($table) !== 'string') { |
|
20 | throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead."); |
||
21 | } |
||
22 | |||
23 | 1 | if (gettype($record) !== 'array') { |
|
24 | throw new InvalidArgumentException("The parameter {$record} is not an array. An array is required instead."); |
||
25 | } |
||
26 | |||
27 | 1 | $count = count($record); |
|
28 | |||
29 | 1 | $sql = "INSERT INTO {$table} ("; |
|
30 | 1 | View Code Duplication | foreach ($record as $key => $value) { |
0 ignored issues
–
show
|
|||
31 | 1 | $count--; |
|
32 | |||
33 | 1 | if ($key === $this->getPrimaryKey($table)) { |
|
0 ignored issues
–
show
It seems like
getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
34 | 1 | continue; |
|
35 | } |
||
36 | |||
37 | 1 | if ($count > 0) { |
|
38 | 1 | $sql = $sql."{$key}, "; |
|
39 | 1 | } else { |
|
40 | 1 | $sql = $sql."{$key}) "; |
|
41 | } |
||
42 | 1 | } |
|
43 | |||
44 | 1 | $count = count($record); |
|
45 | |||
46 | 1 | $sql .= 'VALUES ('; |
|
47 | 1 | foreach ($record as $key => $value) { |
|
48 | 1 | $count--; |
|
49 | |||
50 | 1 | if ($key === $this->getPrimaryKey($table)) { |
|
0 ignored issues
–
show
It seems like
getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
51 | 1 | continue; |
|
52 | } |
||
53 | |||
54 | 1 | if ($count > 0) { |
|
55 | 1 | $sql = (empty($value)) ? $sql.'NULL, ' : $sql."'{$value}', "; |
|
56 | 1 | } else { |
|
57 | 1 | $sql = (empty($value)) ? $sql.'NULL ' : $sql."'{$value}') "; |
|
58 | } |
||
59 | 1 | } |
|
60 | |||
61 | 1 | return $this->getPdo()->prepare($sql)->execute(); |
|
0 ignored issues
–
show
It seems like
getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Remove a record in the database. |
||
66 | * |
||
67 | * @param string $table The table where the record is removed in the database. |
||
68 | * @param string $pk The primary key value of the record. |
||
69 | * |
||
70 | * @return bool Returns boolean true if the record was successfully deleted or else it returns false. |
||
71 | */ |
||
72 | 1 | View Code Duplication | public function deleteRecord($table, $pk) |
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. ![]() |
|||
73 | { |
||
74 | 1 | if (gettype($table) !== 'string') { |
|
75 | throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead."); |
||
76 | } |
||
77 | |||
78 | 1 | return $this->getPdo()->prepare("DELETE FROM {$table} |
|
0 ignored issues
–
show
It seems like
getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
79 | 1 | WHERE {$this->getPrimaryKey($table)}={$pk}")->execute(); |
|
0 ignored issues
–
show
It seems like
getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Returns a particular record in a table. |
||
84 | * |
||
85 | * @param string $table The table of the record. |
||
86 | * @param string $pk The primary key value of the record. |
||
87 | * |
||
88 | * @return array An array containing the particular record. |
||
89 | */ |
||
90 | 1 | View Code Duplication | public function findRecord($table, $pk) |
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. ![]() |
|||
91 | { |
||
92 | 1 | if (gettype($table) !== 'string') { |
|
93 | throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead."); |
||
94 | } |
||
95 | |||
96 | 1 | return $this->getPdo()->query("SELECT * FROM {$table} |
|
0 ignored issues
–
show
It seems like
getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
97 | 1 | WHERE {$this->getPrimaryKey($table)}={$pk}")->fetchAll(); |
|
0 ignored issues
–
show
It seems like
getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Returns all the records in a table. |
||
102 | * |
||
103 | * @param string $table The table inspected for all its records. |
||
104 | * |
||
105 | * @return array All the records in the table. |
||
106 | */ |
||
107 | 1 | public function getAllRecords($table) |
|
108 | { |
||
109 | 1 | if (gettype($table) !== 'string') { |
|
110 | throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead."); |
||
111 | } |
||
112 | |||
113 | 1 | return $this->getPdo()->query("SELECT * FROM {$table}")->fetchAll(); |
|
0 ignored issues
–
show
It seems like
getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Update a record in the database. |
||
118 | * |
||
119 | * @param string $table The table where the record update is being made. |
||
120 | * @param string $pk The primary key value of the record to be updated. |
||
121 | * @param array $record The updates to be made to the record in the database. |
||
122 | * |
||
123 | * @return bool Returns boolean true if the record was successfully updated or else it returns false. |
||
124 | */ |
||
125 | 1 | public function updateRecord($table, $pk, $record) |
|
126 | { |
||
127 | 1 | if (gettype($table) !== 'string') { |
|
128 | throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead."); |
||
129 | } |
||
130 | |||
131 | 1 | if (gettype($pk) !== 'string') { |
|
132 | throw new InvalidArgumentException("The parameter {$pk} is not a string. A string is required instead."); |
||
133 | } |
||
134 | |||
135 | 1 | if (gettype($record) !== 'array') { |
|
136 | throw new InvalidArgumentException("The parameter {$record} is not an array. An array is required instead."); |
||
137 | } |
||
138 | |||
139 | 1 | $count = count($record); |
|
140 | |||
141 | 1 | $sql = "UPDATE {$table} SET "; |
|
142 | 1 | View Code Duplication | foreach ($record 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. ![]() |
|||
143 | 1 | $count--; |
|
144 | |||
145 | 1 | if ($key === $this->getPrimaryKey($table)) { |
|
0 ignored issues
–
show
It seems like
getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
146 | 1 | continue; |
|
147 | } |
||
148 | |||
149 | 1 | if ($count > 0) { |
|
150 | 1 | $sql = $sql."{$key}='{$value}', "; |
|
151 | 1 | } else { |
|
152 | 1 | $sql = $sql."{$key}='{$value}' "; |
|
153 | } |
||
154 | 1 | } |
|
155 | 1 | $sql .= "WHERE {$this->getPrimaryKey($table)}='{$pk}'"; |
|
0 ignored issues
–
show
It seems like
getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
156 | |||
157 | 1 | return $this->getPdo()->prepare($sql)->execute(); |
|
0 ignored issues
–
show
It seems like
getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
158 | } |
||
159 | } |
||
160 |
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.