Completed
Branch develop (981d8e)
by Oyebanji Jacob
04:12 queued 01:59
created
src/DatabaseConnectionStringFactory.php 2 patches
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.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,9 +22,13 @@
 block discarded – undo
22 22
                 break;
23 23
             case 'mysql':
24 24
             case 'postgres':
25
-                if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql";
25
+                if(strcasecmp($driver, 'postgres') == 0) {
26
+                    $driver="pgsql";
27
+                }
26 28
                 $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME'];
27
-                if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT'];
29
+                if(isset($config['PORT'])) {
30
+                    $dsn .= ';port='.$config['PORT'];
31
+                }
28 32
                 break;
29 33
             default:
30 34
                 throw new DatabaseDriverNotSupportedException;
Please login to merge, or discard this patch.
src/Model.php 3 patches
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.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -114,7 +114,9 @@  discard block
 block discarded – undo
114 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')) {
118
+                continue;
119
+            }
118 120
             $update .= "$key = '$val'";
119 121
             if ($count < count($this->properties) )
120 122
             {
@@ -124,7 +126,9 @@  discard block
 block discarded – undo
124 126
         $update .= " WHERE id = " . $this->properties['id'];
125 127
         $stmt = $connection->prepare($update);
126 128
             foreach ($this->properties as $key => $val) {
127
-                if($key == 'id') continue;
129
+                if($key == 'id') {
130
+                    continue;
131
+                }
128 132
             }
129 133
         $stmt->execute();
130 134
         return $stmt->rowCount();
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -146,28 +146,28 @@  discard block
 block discarded – undo
146 146
 
147 147
     /**
148 148
      * Store instance of database connection used.
149
-    * @var [type]
150
-    */
149
+     * @var [type]
150
+     */
151 151
     protected  $databaseConnection;
152 152
 
153
-     public function __construct()
153
+        public function __construct()
154 154
     {
155 155
         $this->databaseConnection = DatabaseConnection::getInstance()->databaseConnection;
156 156
         //$databaseConnection->databaseConnection->connect();
157 157
     }
158 158
     /**
159
-    * @param string $key rep column name
160
-    * @param string $val rep column value
161
-    * sets into $propertie the $key => $value pairs
162
-    */
159
+     * @param string $key rep column name
160
+     * @param string $val rep column value
161
+     * sets into $propertie the $key => $value pairs
162
+     */
163 163
     public  function __set($key, $val)
164 164
     {
165 165
         $this->properties[$key] = $val;
166 166
     }
167 167
     /**
168
-    * @param string $key reps the column name
169
-    * @return $key and $value
170
-    */
168
+     * @param string $key reps the column name
169
+     * @return $key and $value
170
+     */
171 171
     public function __get($key)
172 172
     {
173 173
         return $this->properties[$key];
@@ -177,17 +177,17 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @return array
179 179
      */
180
-     public function getProperties()
181
-     {
182
-         return $this->properties;
183
-     }
180
+        public function getProperties()
181
+        {
182
+            return $this->properties;
183
+        }
184 184
     /**
185
-    * Gets the name of the child class only
186
-    * without the namespace
187
-    * @var $className
188
-    * @var $table
189
-    * @return $table
190
-    */
185
+     * Gets the name of the child class only
186
+     * without the namespace
187
+     * @var $className
188
+     * @var $table
189
+     * @return $table
190
+     */
191 191
     public function getTableName()
192 192
     {
193 193
         $className = explode('\\', get_called_class());
@@ -195,22 +195,22 @@  discard block
 block discarded – undo
195 195
         return $table;
196 196
     }
197 197
     /**
198
-    * returns a particular record
199
-    * @param $id reps the record id
200
-    * @param $connection initialised to null
201
-    * @return object
202
-    */
198
+     * returns a particular record
199
+     * @param $id reps the record id
200
+     * @param $connection initialised to null
201
+     * @return object
202
+     */
203 203
     public static function find($id)
204 204
     {
205 205
         $model = new static;
206 206
         return $model->get($id); 
207 207
     }
208 208
     /**
209
-    * returns a particular record
210
-    * @param $id reps the record id
211
-    * @param $connection initialised to null
212
-    * @return object
213
-    */
209
+     * returns a particular record
210
+     * @param $id reps the record id
211
+     * @param $connection initialised to null
212
+     * @return object
213
+     */
214 214
     public function get($id)
215 215
     {
216 216
         $sql = "SELECT * FROM {$this->getTableName()} WHERE id={$id}";
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 
240 240
     }
241 241
     /** update table with instance properties
242
-    *
243
-    */
242
+     *
243
+     */
244 244
     private function update()
245 245
     {
246 246
         $connection = $this->getConnection();
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
         return $stmt->rowCount();
267 267
     }
268 268
     /**
269
-    * insert instance data into the table
270
-    */
269
+     * insert instance data into the table
270
+     */
271 271
     private function create()
272 272
     {
273 273
         $connection = $this->getConnection();
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
         return $stmt->rowCount();
300 300
     }
301 301
     /**
302
-    * get db connection
303
-    */
302
+     * get db connection
303
+     */
304 304
     public function getConnection($connection = null)
305 305
     {
306 306
         if(is_null($connection))
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
         }
310 310
     }
311 311
     /**
312
-    * checks if the id exists
313
-    * update if exist
314
-    * create if not exist
315
-    */
312
+     * checks if the id exists
313
+     * update if exist
314
+     * create if not exist
315
+     */
316 316
     public function save()
317 317
     {
318 318
         if ($this->id) {
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
         }
323 323
     }
324 324
     /**
325
-    * @param row reps record id
326
-    * @param $connection initialised to null
327
-    * @return boolean
328
-    */
325
+     * @param row reps record id
326
+     * @param $connection initialised to null
327
+     * @return boolean
328
+     */
329 329
     public static function destroy($id)
330 330
     {
331 331
         
Please login to merge, or discard this patch.
test/DatabaseConnectionStringFactoryTest.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,11 +4,11 @@
 block discarded – undo
4 4
 
5 5
 class DatabaseConnectionStringFactoryTest extends PHPUnit_Framework_TestCase
6 6
 {
7
-     /**
8
-     * The instance of DatabaseConnectionStringFactory used in the test.
9
-     *
10
-     * @var Pyjac\ORM\DatabaseConnectionStringFactory
11
-     */
7
+        /**
8
+         * The instance of DatabaseConnectionStringFactory used in the test.
9
+         *
10
+         * @var Pyjac\ORM\DatabaseConnectionStringFactory
11
+         */
12 12
     protected $openSourceEvangelistFactory;
13 13
 
14 14
     /**
Please login to merge, or discard this patch.