Completed
Branch develop (32cfca)
by Oyebanji Jacob
03:26
created
src/DatabaseConnectionStringFactory.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,13 +18,13 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/Model.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.
potatoTest.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     public function getTableName()
192 192
     {
193 193
         $className = explode('\\', get_called_class());
194
-        $table = strtolower(end($className) .'s');
194
+        $table = strtolower(end($className) . 's');
195 195
         return $table;
196 196
     }
197 197
     /**
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
         $sqlStatement = $this->databaseConnection->prepare($sql);
218 218
         $sqlStatement->setFetchMode(PDO::FETCH_CLASS, get_called_class());
219 219
         $sqlStatement->execute();
220
-        if($sqlStatement->rowCount() < 1){
220
+        if ($sqlStatement->rowCount() < 1) {
221 221
             throw new ModelNotFoundException($id);
222 222
         }
223 223
         return $sqlStatement->fetch();
@@ -247,20 +247,20 @@  discard block
 block discarded – undo
247 247
         $columnNames = "";
248 248
         $columnValues = "";
249 249
         $count = 0;
250
-        $update = "UPDATE " . $this->getTableName() . " SET " ;
250
+        $update = "UPDATE " . $this->getTableName() . " SET ";
251 251
         foreach ($this->properties as $key => $val) {
252 252
             $count++;
253
-            if(($key == 'id')) continue;
253
+            if (($key == 'id')) continue;
254 254
             $update .= "$key = '$val'";
255
-            if ($count < count($this->properties) )
255
+            if ($count < count($this->properties))
256 256
             {
257
-                $update .=",";
257
+                $update .= ",";
258 258
             }
259 259
         }
260 260
         $update .= " WHERE id = " . $this->properties['id'];
261 261
         $stmt = $connection->prepare($update);
262 262
             foreach ($this->properties as $key => $val) {
263
-                if($key == 'id') continue;
263
+                if ($key == 'id') continue;
264 264
             }
265 265
         $stmt->execute();
266 266
         return $stmt->rowCount();
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         $columnNames = "";
275 275
         $columnValues = "";
276 276
         $count = 0;
277
-        $create = "INSERT" . " INTO " . $this->getTableName()." (";
277
+        $create = "INSERT" . " INTO " . $this->getTableName() . " (";
278 278
             foreach ($this->properties as $key => $val) {
279 279
                 $columnNames .= $key;
280 280
                 $columnValues .= ':' . $key;
@@ -285,15 +285,15 @@  discard block
 block discarded – undo
285 285
                     $columnValues .= ', ';
286 286
                 }
287 287
             }
288
-        $create .= $columnNames.') VALUES (' .$columnValues.')';
288
+        $create .= $columnNames . ') VALUES (' . $columnValues . ')';
289 289
         $stmt = $connection->prepare($create);
290 290
             foreach ($this->properties as $key => $val) {
291
-                $stmt->bindValue(':'.$key, $val);
291
+                $stmt->bindValue(':' . $key, $val);
292 292
             }
293 293
             try {
294 294
                 // if prop returned and props from db differ throw exception
295 295
                 $stmt->execute();
296
-            } catch(PDOException $e){
296
+            } catch (PDOException $e) {
297 297
                 return $e->getExceptionMessage();
298 298
             }
299 299
         return $stmt->rowCount();
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     */
304 304
     public function getConnection($connection = null)
305 305
     {
306
-        if(is_null($connection))
306
+        if (is_null($connection))
307 307
         {
308 308
             return new Connection();
309 309
         }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
     public static function destroy($id)
330 330
     {
331 331
         
332
-        $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id;
332
+        $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id;
333 333
         $delete = $connection->prepare($sql);
334 334
         $delete->execute();
335 335
         $count = $delete->rowCount();
@@ -391,13 +391,13 @@  discard block
 block discarded – undo
391 391
 
392 392
         switch ($driver) {
393 393
             case 'sqlite':
394
-                $dsn = $driver.'::memory:';
394
+                $dsn = $driver . '::memory:';
395 395
                 break;
396 396
             case 'mysql':
397 397
             case 'postgres':
398
-                if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql";
399
-                $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME'];
400
-                if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT'];
398
+                if (strcasecmp($driver, 'postgres') == 0) $driver = "pgsql";
399
+                $dsn = $driver . ':host=' . $config['HOSTNAME'] . ';dbname=' . $config['DBNAME'];
400
+                if (isset($config['PORT'])) $dsn .= ';port=' . $config['PORT'];
401 401
                 break;
402 402
             default:
403 403
                 throw new DatabaseDriverNotSupportedException;
Please login to merge, or discard this patch.
indexPDO.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     private $dbh;
59 59
     private $error;
60 60
  
61
-    public function __construct(){
61
+    public function __construct() {
62 62
     	$config = parse_ini_file('config.ini');
63 63
         // Set DSN
64 64
         $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
             PDO::ATTR_ERRMODE       => PDO::ERRMODE_EXCEPTION
69 69
         );
70 70
         // Create a new PDO instanace
71
-        try{
71
+        try {
72 72
             $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
73 73
         }
74 74
         // Catch any errors
75
-        catch(PDOException $e){
75
+        catch (PDOException $e) {
76 76
             $this->error = $e->getMessage();
77 77
         }
78 78
     }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 try {
83 83
 	 
84 84
 	$dbh = new PDO('mysql:host=localhost;dbname=potatoORM', 'homestead', 'secret');
85
-	foreach($dbh->query('SELECT * from test') as $row) {
85
+	foreach ($dbh->query('SELECT * from test') as $row) {
86 86
 	        print_r($row);
87 87
 	    }
88 88
 } catch (PDOException $e) {
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     **/
130 130
     protected function loadDotenv()
131 131
     {
132
-        if(getenv('APP_ENV') !== 'production')
132
+        if (getenv('APP_ENV') !== 'production')
133 133
         {
134 134
             $dotenv = new Dotenv(__DIR__);
135 135
             $dotenv->load();
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
         // is set on the server but needs to be set here on this client objects.
180 180
         $charset = $config['charset'];
181 181
 
182
-        $names = "set names '$charset'".
183
-            (! is_null($collation) ? " collate '$collation'" : '');
182
+        $names = "set names '$charset'" .
183
+            (!is_null($collation) ? " collate '$collation'" : '');
184 184
 
185 185
         $connection->prepare($names)->execute();
186 186
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      */
209 209
     protected function configHasSocket(array $config)
210 210
     {
211
-        return isset($config['unix_socket']) && ! empty($config['unix_socket']);
211
+        return isset($config['unix_socket']) && !empty($config['unix_socket']);
212 212
     }
213 213
 
214 214
     /**
Please login to merge, or discard this patch.