@@ -18,13 +18,13 @@ |
||
18 | 18 | |
19 | 19 | switch ($driver) { |
20 | 20 | case 'sqlite': |
21 | - $dsn = $driver.'::memory:'; |
|
21 | + $dsn = $driver . '::memory:'; |
|
22 | 22 | break; |
23 | 23 | case 'mysql': |
24 | 24 | case 'postgres': |
25 | - if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql"; |
|
26 | - $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME']; |
|
27 | - if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT']; |
|
25 | + if (strcasecmp($driver, 'postgres') == 0) $driver = "pgsql"; |
|
26 | + $dsn = $driver . ':host=' . $config['HOSTNAME'] . ';dbname=' . $config['DBNAME']; |
|
27 | + if (isset($config['PORT'])) $dsn .= ';port=' . $config['PORT']; |
|
28 | 28 | break; |
29 | 29 | default: |
30 | 30 | throw new DatabaseDriverNotSupportedException; |
@@ -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 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $sqlStatement = $this->databaseConnection->prepare($sql); |
82 | 82 | $sqlStatement->setFetchMode($this->databaseConnection::FETCH_CLASS, get_called_class()); |
83 | 83 | $sqlStatement->execute(); |
84 | - if($sqlStatement->rowCount() < 1){ |
|
84 | + if ($sqlStatement->rowCount() < 1) { |
|
85 | 85 | throw new ModelNotFoundException($id); |
86 | 86 | } |
87 | 87 | return $sqlStatement->fetch(); |
@@ -111,20 +111,20 @@ discard block |
||
111 | 111 | $columnNames = ""; |
112 | 112 | $columnValues = ""; |
113 | 113 | $count = 0; |
114 | - $update = "UPDATE " . $this->getTableName() . " SET " ; |
|
114 | + $update = "UPDATE " . $this->getTableName() . " SET "; |
|
115 | 115 | foreach ($this->properties as $key => $val) { |
116 | 116 | $count++; |
117 | - if(($key == 'id')) continue; |
|
117 | + if (($key == 'id')) continue; |
|
118 | 118 | $update .= "$key = '$val'"; |
119 | - if ($count < count($this->properties) ) |
|
119 | + if ($count < count($this->properties)) |
|
120 | 120 | { |
121 | - $update .=","; |
|
121 | + $update .= ","; |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | $update .= " WHERE id = " . $this->properties['id']; |
125 | 125 | $stmt = $connection->prepare($update); |
126 | 126 | foreach ($this->properties as $key => $val) { |
127 | - if($key == 'id') continue; |
|
127 | + if ($key == 'id') continue; |
|
128 | 128 | } |
129 | 129 | $stmt->execute(); |
130 | 130 | return $stmt->rowCount(); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $columnNames = ""; |
139 | 139 | $columnValues = ""; |
140 | 140 | $count = 0; |
141 | - $create = "INSERT" . " INTO " . $this->getTableName()." ("; |
|
141 | + $create = "INSERT" . " INTO " . $this->getTableName() . " ("; |
|
142 | 142 | foreach ($this->properties as $key => $val) { |
143 | 143 | $columnNames .= $key; |
144 | 144 | $columnValues .= ':' . $key; |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | $columnValues .= ', '; |
150 | 150 | } |
151 | 151 | } |
152 | - $create .= $columnNames.') VALUES (' .$columnValues.')'; |
|
152 | + $create .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
153 | 153 | $stmt = $connection->prepare($create); |
154 | 154 | foreach ($this->properties as $key => $val) { |
155 | - $stmt->bindValue(':'.$key, $val); |
|
155 | + $stmt->bindValue(':' . $key, $val); |
|
156 | 156 | } |
157 | 157 | try { |
158 | 158 | // if prop returned and props from db differ throw exception |
159 | 159 | $stmt->execute(); |
160 | - } catch(PDOException $e){ |
|
160 | + } catch (PDOException $e) { |
|
161 | 161 | return $e->getExceptionMessage(); |
162 | 162 | } |
163 | 163 | return $stmt->rowCount(); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function getConnection($connection = null) |
169 | 169 | { |
170 | - if(is_null($connection)) |
|
170 | + if (is_null($connection)) |
|
171 | 171 | { |
172 | 172 | return new Connection(); |
173 | 173 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | public static function destroy($id) |
194 | 194 | { |
195 | 195 | |
196 | - $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id; |
|
196 | + $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id; |
|
197 | 197 | $delete = $connection->prepare($sql); |
198 | 198 | $delete->execute(); |
199 | 199 | $count = $delete->rowCount(); |