@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function getTableName() |
56 | 56 | { |
57 | 57 | $className = explode('\\', get_called_class()); |
58 | - $table = strtolower(end($className) .'s'); |
|
58 | + $table = strtolower(end($className) . 's'); |
|
59 | 59 | return $table; |
60 | 60 | } |
61 | 61 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $sqlStatement = $this->databaseConnection->prepare($sql); |
83 | 83 | $sqlStatement->setFetchMode($this->databaseConnection::FETCH_CLASS, get_called_class()); |
84 | 84 | $sqlStatement->execute(); |
85 | - if($sqlStatement->rowCount() < 1){ |
|
85 | + if ($sqlStatement->rowCount() < 1) { |
|
86 | 86 | throw new ModelNotFoundException($id); |
87 | 87 | } |
88 | 88 | return $sqlStatement->fetch(); |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | $columnNames = ""; |
115 | 115 | $columnValues = ""; |
116 | 116 | $bindNameParameters = []; |
117 | - $sqlUpdate = "UPDATE " . $this->getTableName() . " SET " ; |
|
117 | + $sqlUpdate = "UPDATE " . $this->getTableName() . " SET "; |
|
118 | 118 | foreach ($this->properties as $columnName => $columnValue) { |
119 | - if($key == 'id') continue; |
|
119 | + if ($key == 'id') continue; |
|
120 | 120 | $bindColumnName = ':' . $columnName; |
121 | 121 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
122 | 122 | $bindNameParameters[$bindColumnName] = $columnValue |
123 | 123 | } |
124 | 124 | //Remove the last comma in sql command then join it to the other query part. |
125 | - $sqlUpdate = substr($sqlUpdate, 0, -1)." WHERE id = :id"; |
|
125 | + $sqlUpdate = substr($sqlUpdate, 0, -1) . " WHERE id = :id"; |
|
126 | 126 | $sqlStatement = $this->databaseConnection->prepare($sqlUpdate); |
127 | 127 | $sqlStatement->bindValue(":id", $this->properties['id']); |
128 | 128 | $sqlStatement->execute($bindNameParameters); |
@@ -140,19 +140,19 @@ discard block |
||
140 | 140 | $columnNames = ""; |
141 | 141 | $columnValues = ""; |
142 | 142 | $bindNameParameters = []; |
143 | - $sqlCreate = "INSERT" . " INTO " . $this->getTableName()." ("; |
|
143 | + $sqlCreate = "INSERT" . " INTO " . $this->getTableName() . " ("; |
|
144 | 144 | foreach ($this->properties as $columnName => $columnValue) { |
145 | 145 | |
146 | 146 | $bindColumnName = ':' . $columnName; |
147 | - $columnNames .= $columnName.","; |
|
148 | - $columnValues .= $bindColumnName.","; |
|
147 | + $columnNames .= $columnName . ","; |
|
148 | + $columnValues .= $bindColumnName . ","; |
|
149 | 149 | $bindNameParameters[$bindColumnName] = $columnValue |
150 | 150 | } |
151 | 151 | // Remove ending comma and whitespace. |
152 | 152 | $columnNames = substr($columnNames, 0, -1); |
153 | 153 | $columnValues = substr($columnValues, 0, -1); |
154 | 154 | |
155 | - $sqlCreate .= $columnNames.') VALUES (' .$columnValues.')'; |
|
155 | + $sqlCreate .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
156 | 156 | $sqlStatement = $this->databaseConnection->prepare($sqlCreate); |
157 | 157 | $sqlStatement->execute($bindNameParameters); |
158 | 158 | return $sqlStatement->rowCount(); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function delete($id) |
189 | 189 | { |
190 | - $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id; |
|
190 | + $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id; |
|
191 | 191 | $sqlStatment = $this->databaseConnection->prepare($sql); |
192 | 192 | $sqlStatment->execute(); |
193 | 193 | return ($sqlStatment->rowCount() > 0) ? true : false; |