@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function getTableName() |
67 | 67 | { |
68 | 68 | $className = explode('\\', get_called_class()); |
69 | - $table = strtolower(end($className) .'s'); |
|
69 | + $table = strtolower(end($className) . 's'); |
|
70 | 70 | return $table; |
71 | 71 | } |
72 | 72 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $sqlStatement = $this->databaseConnection->prepare($sql); |
96 | 96 | $sqlStatement->setFetchMode($this->databaseConnection::FETCH_CLASS, get_called_class()); |
97 | 97 | $sqlStatement->execute(); |
98 | - if($sqlStatement->rowCount() < 1){ |
|
98 | + if ($sqlStatement->rowCount() < 1) { |
|
99 | 99 | throw new ModelNotFoundException($id); |
100 | 100 | } |
101 | 101 | return $sqlStatement->fetch(); |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | { |
136 | 136 | |
137 | 137 | $bindNameParameters = []; |
138 | - $sqlUpdate = "UPDATE " . $this->getTableName() . " SET " ; |
|
138 | + $sqlUpdate = "UPDATE " . $this->getTableName() . " SET "; |
|
139 | 139 | foreach ($this->properties as $columnName => $columnValue) { |
140 | - if($columnName == 'id') continue; |
|
140 | + if ($columnName == 'id') continue; |
|
141 | 141 | $bindColumnName = ':' . $columnName; |
142 | 142 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
143 | 143 | $bindNameParameters[$bindColumnName] = $columnValue; |
144 | 144 | } |
145 | 145 | //Remove the last comma in sql command then join it to the other query part. |
146 | - $sqlUpdate = substr($sqlUpdate, 0, -1)." WHERE id = :id"; |
|
146 | + $sqlUpdate = substr($sqlUpdate, 0, -1) . " WHERE id = :id"; |
|
147 | 147 | $sqlStatement = $this->databaseConnection->prepare($sqlUpdate); |
148 | 148 | $sqlStatement->bindValue(":id", $this->properties['id']); |
149 | 149 | $sqlStatement->execute($bindNameParameters); |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | $columnNames = ""; |
162 | 162 | $columnValues = ""; |
163 | 163 | $bindNameParameters = []; |
164 | - $sqlCreate = "INSERT" . " INTO " . $this->getTableName()." ("; |
|
164 | + $sqlCreate = "INSERT" . " INTO " . $this->getTableName() . " ("; |
|
165 | 165 | foreach ($this->properties as $columnName => $columnValue) { |
166 | 166 | |
167 | 167 | $bindColumnName = ':' . $columnName; |
168 | - $columnNames .= $columnName.","; |
|
169 | - $columnValues .= $bindColumnName.","; |
|
168 | + $columnNames .= $columnName . ","; |
|
169 | + $columnValues .= $bindColumnName . ","; |
|
170 | 170 | $bindNameParameters[$bindColumnName] = $columnValue; |
171 | 171 | } |
172 | 172 | // Remove ending comma and whitespace. |
173 | 173 | $columnNames = substr($columnNames, 0, -1); |
174 | 174 | $columnValues = substr($columnValues, 0, -1); |
175 | 175 | |
176 | - $sqlCreate .= $columnNames.') VALUES (' .$columnValues.')'; |
|
176 | + $sqlCreate .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
177 | 177 | $sqlStatement = $this->databaseConnection->prepare($sqlCreate); |
178 | 178 | $sqlStatement->execute($bindNameParameters); |
179 | 179 | return $sqlStatement->rowCount(); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function delete($id) |
210 | 210 | { |
211 | - $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id; |
|
211 | + $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id; |
|
212 | 212 | $sqlStatment = $this->databaseConnection->prepare($sql); |
213 | 213 | $sqlStatment->execute(); |
214 | 214 | return ($sqlStatment->rowCount() > 0) ? true : false; |