@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | if (!$this->tableName) |
| 29 | 29 | { |
| 30 | 30 | $ref = new ReflectionClass($this); |
| 31 | - $this->tableName = strtolower($ref->getShortName()).'s'; |
|
| 31 | + $this->tableName = strtolower($ref->getShortName()) . 's'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | Self::$table = $this->tableName; |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public static function getAll() |
| 63 | 63 | { |
| 64 | - if(!Self::$table) { |
|
| 64 | + if (!Self::$table) { |
|
| 65 | 65 | self::$table = strtolower(static::class) . 's'; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - $query = "SELECT * FROM ".self::$table; |
|
| 68 | + $query = "SELECT * FROM " . self::$table; |
|
| 69 | 69 | $results = Connection::db()->query($query); |
| 70 | 70 | $res = []; |
| 71 | 71 | |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | public static function getOne($id) |
| 80 | 80 | { |
| 81 | - if(!Self::$table) { |
|
| 81 | + if (!Self::$table) { |
|
| 82 | 82 | self::$table = strtolower(static::class) . 's'; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - $query = "SELECT * FROM ".self::$table." WHERE id = $id"; |
|
| 85 | + $query = "SELECT * FROM " . self::$table . " WHERE id = $id"; |
|
| 86 | 86 | $results = Connection::db()->query($query); |
| 87 | 87 | $res = []; |
| 88 | 88 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | if (!empty($res)) { |
| 96 | 96 | return $res; |
| 97 | 97 | } else { |
| 98 | - throw new PotatoException('There is no user with id '. $id); |
|
| 98 | + throw new PotatoException('There is no user with id ' . $id); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -127,21 +127,21 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | if (!self::$id) { |
| 129 | 129 | // new record so we insert |
| 130 | - $query = "INSERT INTO $this->tableName (".implode(", ", $availableColumnNames).") VALUES('".implode("', '", $availableColumnValues)."');"; |
|
| 130 | + $query = "INSERT INTO $this->tableName (" . implode(", ", $availableColumnNames) . ") VALUES('" . implode("', '", $availableColumnValues) . "');"; |
|
| 131 | 131 | } else { |
| 132 | 132 | // existing record, se we update |
| 133 | 133 | $query = "UPDATE $this->tableName SET "; |
| 134 | 134 | |
| 135 | 135 | for ($i = 0; $i < count($availableColumnNames); $i++) { |
| 136 | 136 | $prop = $availableColumnNames[$i]; |
| 137 | - $query .= " $prop = '". $this->{$prop}."'"; |
|
| 137 | + $query .= " $prop = '" . $this->{$prop} . "'"; |
|
| 138 | 138 | |
| 139 | 139 | if ($i != count($availableColumnNames) - 1) { |
| 140 | 140 | $query .= ","; |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $query .= " WHERE id = ".self::$id; |
|
| 144 | + $query .= " WHERE id = " . self::$id; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $result = Connection::db()->query($query); |
@@ -161,13 +161,13 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | public static function destroy($id) |
| 163 | 163 | { |
| 164 | - if(!Self::$table) { |
|
| 164 | + if (!Self::$table) { |
|
| 165 | 165 | self::$table = strtolower(static::class) . 's'; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | self::getOne($id); |
| 169 | 169 | |
| 170 | - $query = "DELETE FROM ".self::$table." WHERE id = ".$id; |
|
| 170 | + $query = "DELETE FROM " . self::$table . " WHERE id = " . $id; |
|
| 171 | 171 | |
| 172 | 172 | $result = Connection::db()->query($query); |
| 173 | 173 | } |