Completed
Push — test ( e682d1...5bf343 )
by Temitope
03:04
created
src/Interface/InterfaceBaseClass.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,12 +10,12 @@
 block discarded – undo
10 10
 
11 11
 interface InterfaceBaseClass {
12 12
 
13
-    /**
14
-     * This method gets all the record from a particular table
15
-     * @params void
16
-     * @return associative array
17
-     */
18
-    public static function getAll();
13
+	/**
14
+	 * This method gets all the record from a particular table
15
+	 * @params void
16
+	 * @return associative array
17
+	 */
18
+	public static function getAll();
19 19
    
20 20
    /**
21 21
     * This method create or update record in a database table
Please login to merge, or discard this patch.
src/Database/DatabaseHandler.php 4 patches
Doc Comments   +7 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,6 +21,7 @@  discard block
 block discarded – undo
21 21
     
22 22
     /**
23 23
      * This is a constructor; a default method  that will be called automatically during class instantiation
24
+     * @param string|false $modelClassName
24 25
      */
25 26
      public function __construct($modelClassName, $dbConn = Null)
26 27
      {
@@ -35,6 +36,7 @@  discard block
 block discarded – undo
35 36
     /**
36 37
      * This method create a record and store it in a table row
37 38
      * @params associative array, string tablename
39
+     * @param string|false $tableName
38 40
      * @return boolean true or false
39 41
      */
40 42
     public function create($associative1DArray, $tableName, $dbConn = Null)
@@ -69,6 +71,7 @@  discard block
 block discarded – undo
69 71
     /**
70 72
      * This method updates any table by supplying 3 parameter
71 73
      * @params: $updateParams, $tableName, $associative1DArray
74
+     * @param string|false $tableName
72 75
      * @return boolean true or false
73 76
      */
74 77
     public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null)
@@ -101,6 +104,7 @@  discard block
 block discarded – undo
101 104
   /**
102 105
    * This method retrieves record from a table
103 106
    * @params int id, string tableName
107
+   * @param string|false $tableName
104 108
    * @return array
105 109
    */
106 110
    public static function read($id, $tableName, $dbConn = Null)
@@ -131,6 +135,7 @@  discard block
 block discarded – undo
131 135
   /**
132 136
    * This method deletes a record  from a table row
133 137
    * @params int id, string tableName
138
+   * @param string|false $tableName
134 139
    * @return boolean true or false
135 140
    */
136 141
   public static function delete($id, $tableName, $dbConn = Null)
@@ -163,7 +168,7 @@  discard block
 block discarded – undo
163 168
   
164 169
   /**
165 170
    * This method returns sql query
166
-   * @param $sql
171
+   * @param string $sql
167 172
    * @return string
168 173
    */
169 174
   public function prepareUpdateQuery($sql)
@@ -204,6 +209,7 @@  discard block
 block discarded – undo
204 209
    * This method returns column fields of a particular table
205 210
    * @param $table
206 211
    * @param $conn
212
+   * @param DatabaseConnection $dbConn
207 213
    * @return array
208 214
    */
209 215
  public function getColumnNames($table, $dbConn = Null) {
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -9,12 +9,9 @@
 block discarded – undo
9 9
 namespace Laztopaz\potatoORM;
10 10
 
11 11
 use PDO;
12
-use Laztopaz\potatoORM\DatabaseHelper;
13 12
 use Laztopaz\potatoORM\TableFieldUndefinedException;
14 13
 use Laztopaz\potatoORM\EmptyArrayException;
15 14
 use Laztopaz\potatoORM\NoRecordDeletionException;
16
-use Laztopaz\potatoORM\NoRecordInsertionException;
17
-use Laztopaz\potatoORM\NoRecordUpdateException;
18 15
 
19 16
 class DatabaseHandler {
20 17
 
Please login to merge, or discard this patch.
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -18,131 +18,131 @@  discard block
 block discarded – undo
18 18
 
19 19
 class DatabaseHandler {
20 20
 
21
-    private $tableFields;
22
-    private $dbHelperInstance;
23
-    private $dbConnection;
24
-    private $model;
21
+	private $tableFields;
22
+	private $dbHelperInstance;
23
+	private $dbConnection;
24
+	private $model;
25 25
     
26
-    /**
27
-     * This is a constructor; a default method  that will be called automatically during class instantiation
28
-     */
29
-    public function __construct($modelClassName, $dbConn = Null) 
30
-    {
31
-        if (is_null($dbConn)) {
32
-            $this->dbConnection = new DatabaseConnection();
33
-
34
-        } else {
35
-            $this->dbConnection = $dbConn;
36
-
37
-        }
26
+	/**
27
+	 * This is a constructor; a default method  that will be called automatically during class instantiation
28
+	 */
29
+	public function __construct($modelClassName, $dbConn = Null) 
30
+	{
31
+		if (is_null($dbConn)) {
32
+			$this->dbConnection = new DatabaseConnection();
33
+
34
+		} else {
35
+			$this->dbConnection = $dbConn;
36
+
37
+		}
38 38
         
39
-        $this->model = $modelClassName;
40
-     }
39
+		$this->model = $modelClassName;
40
+	 }
41 41
      
42
-    /**
43
-     * This method create a record and store it in a table row
44
-     * @params associative array, string tablename
45
-     * @return boolean true or false
46
-     */
47
-    public function create($associative1DArray, $tableName, $dbConn = Null) 
48
-    {
49
-        $tableFields = $this->getColumnNames($this->model, $this->dbConnection);
50
-
51
-        $unexpectedFields = self::filterTheAttributesThatDoesNotBelongToThisClass($tableFields, $associative1DArray);
42
+	/**
43
+	 * This method create a record and store it in a table row
44
+	 * @params associative array, string tablename
45
+	 * @return boolean true or false
46
+	 */
47
+	public function create($associative1DArray, $tableName, $dbConn = Null) 
48
+	{
49
+		$tableFields = $this->getColumnNames($this->model, $this->dbConnection);
50
+
51
+		$unexpectedFields = self::filterTheAttributesThatDoesNotBelongToThisClass($tableFields, $associative1DArray);
52 52
       
53
-        if (count($unexpectedFields) > 0) {
54
-            throw TableFieldUndefinedException::create($unexpectedFields,"needs to be created as a table field");
55
-        }
53
+		if (count($unexpectedFields) > 0) {
54
+			throw TableFieldUndefinedException::create($unexpectedFields,"needs to be created as a table field");
55
+		}
56 56
 
57
-        unset($associative1DArray[0]);
57
+		unset($associative1DArray[0]);
58 58
 
59
-        if (is_null($dbConn)) {
60
-            $dbConn = $this->dbConnection;
59
+		if (is_null($dbConn)) {
60
+			$dbConn = $this->dbConnection;
61 61
 
62
-        }
62
+		}
63 63
 
64
-        return $this->insertRecord($dbConn, $tableName, $associative1DArray);
64
+		return $this->insertRecord($dbConn, $tableName, $associative1DArray);
65 65
 
66
-    }
66
+	}
67 67
     
68
-    /**
69
-     * This method runs the insertion query
70
-     * @param  $dbConn           
71
-     * @param  $tableName          
72
-     * @param  $associative1DArray 
73
-     * @return boolean true         
74
-     */
75
-    private function  insertRecord($dbConn, $tableName, $associative1DArray) 
76
-    {
77
-        $insertQuery = 'INSERT INTO '.$tableName;
68
+	/**
69
+	 * This method runs the insertion query
70
+	 * @param  $dbConn           
71
+	 * @param  $tableName          
72
+	 * @param  $associative1DArray 
73
+	 * @return boolean true         
74
+	 */
75
+	private function  insertRecord($dbConn, $tableName, $associative1DArray) 
76
+	{
77
+		$insertQuery = 'INSERT INTO '.$tableName;
78 78
 
79
-        $TableValues = implode(',',array_keys($associative1DArray));
79
+		$TableValues = implode(',',array_keys($associative1DArray));
80 80
 
81
-        foreach ($associative1DArray as $field => $value) {
82
-            $FormValues[] = "'".trim(addslashes($value))."'";
83
-        }
81
+		foreach ($associative1DArray as $field => $value) {
82
+			$FormValues[] = "'".trim(addslashes($value))."'";
83
+		}
84 84
 
85
-        $splittedTableValues = implode(',', $FormValues);
85
+		$splittedTableValues = implode(',', $FormValues);
86 86
 
87
-        $insertQuery.= ' ('.$TableValues.')';
88
-        $insertQuery.= ' VALUES ('.$splittedTableValues.')';
87
+		$insertQuery.= ' ('.$TableValues.')';
88
+		$insertQuery.= ' VALUES ('.$splittedTableValues.')';
89 89
 
90
-        $executeQuery = $dbConn->exec($insertQuery);
90
+		$executeQuery = $dbConn->exec($insertQuery);
91 91
 
92
-        if ($executeQuery) {
93
-            return true;
94
-        }
92
+		if ($executeQuery) {
93
+			return true;
94
+		}
95 95
 
96
-        return false;
96
+		return false;
97 97
 
98
-      }
98
+	  }
99 99
 
100
-    /**
101
-     * This method updates any table by supplying 3 parameter
102
-     * @params: $updateParams, $tableName, $associative1DArray
103
-     * @return boolean true or false
104
-     */
105
-    public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = null)
106
-    {
107
-        $sql = "";
100
+	/**
101
+	 * This method updates any table by supplying 3 parameter
102
+	 * @params: $updateParams, $tableName, $associative1DArray
103
+	 * @return boolean true or false
104
+	 */
105
+	public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = null)
106
+	{
107
+		$sql = "";
108 108
 
109
-        if (is_null($dbConn)) {
110
-            $dbConn = $this->dbConnection;
109
+		if (is_null($dbConn)) {
110
+			$dbConn = $this->dbConnection;
111 111
 
112
-        }
112
+		}
113 113
 
114
-        $updateSql = "UPDATE `$tableName` SET ";
114
+		$updateSql = "UPDATE `$tableName` SET ";
115 115
 
116
-        unset($associative1DArray['id']);
116
+		unset($associative1DArray['id']);
117 117
 
118
-        $unexpectedFields = self::filterTheAttributesThatDoesNotBelongToThisClass($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray);
118
+		$unexpectedFields = self::filterTheAttributesThatDoesNotBelongToThisClass($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray);
119 119
 
120
-        if (count($unexpectedFields) > 0) {
121
-            throw TableFieldUndefinedException::create($unexpectedFields, "needs to be created as a table field");
122
-        }
120
+		if (count($unexpectedFields) > 0) {
121
+			throw TableFieldUndefinedException::create($unexpectedFields, "needs to be created as a table field");
122
+		}
123 123
 
124
-        foreach ($associative1DArray as $field => $value) {
125
-            $sql .= "`$field` = '$value'".",";
126
-        }
124
+		foreach ($associative1DArray as $field => $value) {
125
+			$sql .= "`$field` = '$value'".",";
126
+		}
127 127
 
128
-        $updateSql .= $this->prepareUpdateQuery($sql);
128
+		$updateSql .= $this->prepareUpdateQuery($sql);
129 129
 
130
-        foreach ($updateParams as $key => $val) {
131
-            $updateSql .= " WHERE $key = $val";
132
-        }
130
+		foreach ($updateParams as $key => $val) {
131
+			$updateSql .= " WHERE $key = $val";
132
+		}
133 133
 
134
-        $stmt = $dbConn->prepare($updateSql);
134
+		$stmt = $dbConn->prepare($updateSql);
135 135
 
136
-        $boolResponse = $stmt->execute();
136
+		$boolResponse = $stmt->execute();
137 137
 
138
-        if ($boolResponse) {
139
-            return true;
138
+		if ($boolResponse) {
139
+			return true;
140 140
 
141
-        }
141
+		}
142 142
 
143
-        return false;
143
+		return false;
144 144
 
145
-    }
145
+	}
146 146
     
147 147
   /**
148 148
    * This method retrieves record from a table
@@ -151,26 +151,26 @@  discard block
 block discarded – undo
151 151
    */
152 152
    public static function read($id, $tableName, $dbConn = null)
153 153
    {
154
-       $tableData = [];
154
+	   $tableData = [];
155 155
 
156
-       if (is_null($dbConn)) {
157
-           $dbConn = new DatabaseConnection();
158
-       }
156
+	   if (is_null($dbConn)) {
157
+		   $dbConn = new DatabaseConnection();
158
+	   }
159 159
 
160
-       $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
160
+	   $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
161 161
 
162
-       $stmt = $dbConn->prepare($sql);
163
-       $stmt->bindValue(':table', $tableName);
164
-       $stmt->bindValue(':id', $id);
165
-       $stmt->execute();
162
+	   $stmt = $dbConn->prepare($sql);
163
+	   $stmt->bindValue(':table', $tableName);
164
+	   $stmt->bindValue(':id', $id);
165
+	   $stmt->execute();
166 166
 
167
-       $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
167
+	   $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
168 168
 
169
-       foreach ($results as $result) {
170
-           array_push($tableData, $result);
171
-       }
169
+	   foreach ($results as $result) {
170
+		   array_push($tableData, $result);
171
+	   }
172 172
 
173
-       return $tableData;
173
+	   return $tableData;
174 174
 
175 175
    }
176 176
    
@@ -181,20 +181,20 @@  discard block
 block discarded – undo
181 181
    */
182 182
   public static function delete($id, $tableName, $dbConn = null)
183 183
   {
184
-      if (is_null($dbConn)) {
185
-          $dbConn = new DatabaseConnection();
186
-      }
184
+	  if (is_null($dbConn)) {
185
+		  $dbConn = new DatabaseConnection();
186
+	  }
187 187
 
188
-      $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id;
188
+	  $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id;
189 189
 
190
-      $boolResponse = $dbConn->exec($sql);
190
+	  $boolResponse = $dbConn->exec($sql);
191 191
 
192
-      if ($boolResponse) {
193
-          return true;
192
+	  if ($boolResponse) {
193
+		  return true;
194 194
 
195
-      }
195
+	  }
196 196
 
197
-      throw NoRecordDeletionException::create("Record deletion unsuccessful because id does not match any record");
197
+	  throw NoRecordDeletionException::create("Record deletion unsuccessful because id does not match any record");
198 198
   }
199 199
   
200 200
   /**
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
    */
206 206
   public static function filterTheAttributesThatDoesNotBelongToThisClass(array $tableColumn, array $userSetterArray)
207 207
   {
208
-      $unexpectedFields = [];
208
+	  $unexpectedFields = [];
209 209
 
210
-      foreach ($userSetterArray as $key => $val) {
211
-          if (! in_array($key, $tableColumn)) {
212
-              $unexpectedFields[] = $key;
213
-          }
214
-      }
210
+	  foreach ($userSetterArray as $key => $val) {
211
+		  if (! in_array($key, $tableColumn)) {
212
+			  $unexpectedFields[] = $key;
213
+		  }
214
+	  }
215 215
 
216
-      return $unexpectedFields;
216
+	  return $unexpectedFields;
217 217
 
218 218
   }
219 219
   
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
    */
225 225
   public function prepareUpdateQuery($sql)
226 226
   {
227
-      $splittedQuery = explode(",",$sql);
227
+	  $splittedQuery = explode(",",$sql);
228 228
 
229
-      array_pop($splittedQuery);
229
+	  array_pop($splittedQuery);
230 230
 
231
-      $mergeData = implode(",",$splittedQuery);
231
+	  $mergeData = implode(",",$splittedQuery);
232 232
 
233
-      return $mergeData;
233
+	  return $mergeData;
234 234
 
235 235
   }
236 236
   
@@ -243,27 +243,27 @@  discard block
 block discarded – undo
243 243
    */
244 244
   public function findAndWhere($params, $tableName, $dbConn = null)
245 245
   {
246
-      if (is_null($dbConn)) {
247
-          $dbConn = $this->dbConnection;
248
-      }
246
+	  if (is_null($dbConn)) {
247
+		  $dbConn = $this->dbConnection;
248
+	  }
249 249
 
250
-      if (is_array($params) && !empty($params)) {
251
-          $sql = "SELECT * FROM ".$tableName;
250
+	  if (is_array($params) && !empty($params)) {
251
+		  $sql = "SELECT * FROM ".$tableName;
252 252
 
253
-          foreach ($params as $key => $val) {
254
-              $sql .= " WHERE `$key` = '$val'";
255
-          }
253
+		  foreach ($params as $key => $val) {
254
+			  $sql .= " WHERE `$key` = '$val'";
255
+		  }
256 256
 
257
-          $statement = $dbConn->prepare($sql);
258
-          $statement->execute();
257
+		  $statement = $dbConn->prepare($sql);
258
+		  $statement->execute();
259 259
 
260
-          $returnedRowNumbers = $statement->rowCount();
260
+		  $returnedRowNumbers = $statement->rowCount();
261 261
           
262
-          return $returnedRowNumbers ? true : false;
262
+		  return $returnedRowNumbers ? true : false;
263 263
 
264
-      }
264
+	  }
265 265
 
266
-      throw EmptyArrayException::create("Array Expected: parameter passed to this function is not an array");
266
+	  throw EmptyArrayException::create("Array Expected: parameter passed to this function is not an array");
267 267
   }
268 268
   
269 269
   /**
@@ -274,25 +274,25 @@  discard block
 block discarded – undo
274 274
    */
275 275
   public function getColumnNames($table, $dbConn = null) 
276 276
   {
277
-      $tableFields = [];
277
+	  $tableFields = [];
278 278
      
279
-      if (is_null($dbConn)) {
280
-         $dbConn = $this->dbConnection;
281
-      }
279
+	  if (is_null($dbConn)) {
280
+		 $dbConn = $this->dbConnection;
281
+	  }
282 282
 
283
-      $sql = "SHOW COLUMNS FROM ".$table;
283
+	  $sql = "SHOW COLUMNS FROM ".$table;
284 284
      
285
-      $stmt = $dbConn->prepare($sql);
286
-      $stmt->bindValue(':table', $table, PDO::PARAM_STR);
287
-      $stmt->execute();
285
+	  $stmt = $dbConn->prepare($sql);
286
+	  $stmt->bindValue(':table', $table, PDO::PARAM_STR);
287
+	  $stmt->execute();
288 288
 
289
-      $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
289
+	  $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
290 290
      
291
-      foreach ($results as $result) {
292
-          array_push($tableFields, $result['Field']);
293
-      }
291
+	  foreach ($results as $result) {
292
+		  array_push($tableFields, $result['Field']);
293
+	  }
294 294
 
295
-      return $tableFields;
295
+	  return $tableFields;
296 296
      
297 297
   }
298 298
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $unexpectedFields = self::filterTheAttributesThatDoesNotBelongToThisClass($tableFields, $associative1DArray);
52 52
       
53 53
         if (count($unexpectedFields) > 0) {
54
-            throw TableFieldUndefinedException::create($unexpectedFields,"needs to be created as a table field");
54
+            throw TableFieldUndefinedException::create($unexpectedFields, "needs to be created as a table field");
55 55
         }
56 56
 
57 57
         unset($associative1DArray[0]);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     {
77 77
         $insertQuery = 'INSERT INTO '.$tableName;
78 78
 
79
-        $TableValues = implode(',',array_keys($associative1DArray));
79
+        $TableValues = implode(',', array_keys($associative1DArray));
80 80
 
81 81
         foreach ($associative1DArray as $field => $value) {
82 82
             $FormValues[] = "'".trim(addslashes($value))."'";
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 
85 85
         $splittedTableValues = implode(',', $FormValues);
86 86
 
87
-        $insertQuery.= ' ('.$TableValues.')';
88
-        $insertQuery.= ' VALUES ('.$splittedTableValues.')';
87
+        $insertQuery .= ' ('.$TableValues.')';
88
+        $insertQuery .= ' VALUES ('.$splittedTableValues.')';
89 89
 
90 90
         $executeQuery = $dbConn->exec($insertQuery);
91 91
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
       $unexpectedFields = [];
209 209
 
210 210
       foreach ($userSetterArray as $key => $val) {
211
-          if (! in_array($key, $tableColumn)) {
211
+          if (!in_array($key, $tableColumn)) {
212 212
               $unexpectedFields[] = $key;
213 213
           }
214 214
       }
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
    */
225 225
   public function prepareUpdateQuery($sql)
226 226
   {
227
-      $splittedQuery = explode(",",$sql);
227
+      $splittedQuery = explode(",", $sql);
228 228
 
229 229
       array_pop($splittedQuery);
230 230
 
231
-      $mergeData = implode(",",$splittedQuery);
231
+      $mergeData = implode(",", $splittedQuery);
232 232
 
233 233
       return $mergeData;
234 234
 
Please login to merge, or discard this patch.
src/Helper/Inflector.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -74,14 +74,14 @@
 block discarded – undo
74 74
 			'sex' => 'sexes',
75 75
 			'move' => 'moves');
76 76
 		$lowercased_word = strtolower($word);
77
-		foreach ($uncountable as $_uncountable){
78
-			if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){
77
+		foreach ($uncountable as $_uncountable) {
78
+			if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) {
79 79
 				return $word;
80 80
 			}
81 81
 		}
82
-		foreach ($irregular as $_plural=> $_singular){
82
+		foreach ($irregular as $_plural=> $_singular) {
83 83
 			if (preg_match('/('.$_plural.')$/i', $word, $arr)) {
84
-				return preg_replace('/('.$_plural.')$/i', substr($arr[0],0,1).substr($_singular,1), $word);
84
+				return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word);
85 85
 			}
86 86
 		}
87 87
 		foreach ($plural as $rule => $replacement) {
Please login to merge, or discard this patch.
src/Helper/InflectorClass.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,5 @@
 block discarded – undo
10 10
 
11 11
 class Inflector {
12 12
 	
13
-    use Inflector;
13
+	use Inflector;
14 14
 }
Please login to merge, or discard this patch.
src/Model/BaseModel.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     /**
118 118
      * This method find a record by id
119 119
      * @params int id
120
-     * @return Object
120
+     * @return BaseModel
121 121
      * @throws NoArgumentPassedToFunctionException
122 122
      */
123 123
     public static function find($id)
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
    /**
169 169
     * This method return the current class name
170 170
     * $params void
171
-    * @return classname
171
+    * @return string|false
172 172
     */
173 173
    public static function getClassName()
174 174
    {
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -9,12 +9,10 @@
 block discarded – undo
9 9
 namespace Laztopaz\potatoORM;
10 10
 
11 11
 use Laztopaz\potatoORM\DatabaseHandler;
12
-use Laztopaz\potatoORM\InterfaceBaseClass;
13 12
 use Laztopaz\potatoORM\NoRecordDeletionException;
14 13
 use Laztopaz\potatoORM\NoRecordFoundException;
15 14
 use Laztopaz\potatoORM\NoRecordInsertionException;
16 15
 use Laztopaz\potatoORM\NullArgumentPassedToFunction;
17
-use Laztopaz\potatoORM\WrongArgumentException;
18 16
 use Laztopaz\potatoORM\NoArgumentPassedToFunctionException;
19 17
 use Laztopaz\potatoORM\EmptyArrayException;
20 18
 
Please login to merge, or discard this patch.
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -20,156 +20,156 @@  discard block
 block discarded – undo
20 20
 
21 21
 class BaseModel implements BaseModelInterface
22 22
 {
23
-    // Inject the inflector trait
24
-    use Inflector; 
23
+	// Inject the inflector trait
24
+	use Inflector; 
25 25
     
26
-    // Private variable that contains instance of database
27
-    protected $databaseModel; 
26
+	// Private variable that contains instance of database
27
+	protected $databaseModel; 
28 28
 
29
-    // Class variable holding class name pluralized
30
-    protected $tableName; 
29
+	// Class variable holding class name pluralized
30
+	protected $tableName; 
31 31
 
32
-    // Properties will later contain key, value pairs from the magic setter, getter methods
33
-    protected $properties = []; 
32
+	// Properties will later contain key, value pairs from the magic setter, getter methods
33
+	protected $properties = []; 
34 34
 
35
-    public function  __construct()
36
-    {
37
-        $this->tableName = $this->getClassName();
35
+	public function  __construct()
36
+	{
37
+		$this->tableName = $this->getClassName();
38 38
 
39
-        $this->databaseModel = new DatabaseHandler($this->tableName);
39
+		$this->databaseModel = new DatabaseHandler($this->tableName);
40 40
 
41
-        $this->properties['id'] = 0;
42
-    }
41
+		$this->properties['id'] = 0;
42
+	}
43 43
     
44
-    /**
45
-     * The magic getter method
46
-     * @params key
47
-     * @return array key
48
-     */
49
-    public function __get($key)
50
-    {
51
-        $this->properties[$key];
52
-
53
-    }
44
+	/**
45
+	 * The magic getter method
46
+	 * @params key
47
+	 * @return array key
48
+	 */
49
+	public function __get($key)
50
+	{
51
+		$this->properties[$key];
52
+
53
+	}
54 54
     
55
-    /**
56
-     * The magic setter method
57
-     * @params property, key
58
-     * @return array associative array properties
59
-     */
60
-    public function  __set($property, $value)
61
-    {
62
-        $this->properties[$property] = $value;
63
-
64
-    }
55
+	/**
56
+	 * The magic setter method
57
+	 * @params property, key
58
+	 * @return array associative array properties
59
+	 */
60
+	public function  __set($property, $value)
61
+	{
62
+		$this->properties[$property] = $value;
63
+
64
+	}
65 65
     
66
-    /**
67
-     * This method gets all the record from a particular table
68
-     * @params void
69
-     * @return associative array
70
-     * @throws NoRecordFoundException
71
-     */
72
-    public static function getAll()
73
-    {
74
-        $allData = DatabaseHandler::read($id = false, self::getClassName());
66
+	/**
67
+	 * This method gets all the record from a particular table
68
+	 * @params void
69
+	 * @return associative array
70
+	 * @throws NoRecordFoundException
71
+	 */
72
+	public static function getAll()
73
+	{
74
+		$allData = DatabaseHandler::read($id = false, self::getClassName());
75 75
 
76
-        if (count($allData) > 0) {
77
-            return $allData;
76
+		if (count($allData) > 0) {
77
+			return $allData;
78 78
 
79
-        }
79
+		}
80 80
 
81
-        throw NoRecordFoundException::create("There is no record to display");
81
+		throw NoRecordFoundException::create("There is no record to display");
82 82
 
83
-    }
83
+	}
84 84
     
85
-    /**
86
-     * This method create or update record in a database table
87
-     * @params void
88
-     * @return bool true or false;
89
-     * @throws EmptyArrayException
90
-     * @throws NoRecordInsertionException
91
-     * @throws NoRecordUpdateException
92
-     */
93
-    public function save()
94
-    {
95
-        $boolCommit = false;
96
-
97
-        if ($this->properties['id']) {
98
-            $allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName());
99
-
100
-            if ($this->checkIfRecordIsEmpty($allData)) {
101
-                $boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties);
102
-
103
-                if ($boolCommit) {
104
-                    return true;
105
-
106
-                }
107
-
108
-                throw NoRecordUpdateException::create("Record not updated successfully");
109
-            }
110
-
111
-            throw EmptyArrayException::create("Value passed didn't match any record");
112
-        }
113
-
114
-        $boolCommit = $this->databaseModel->create($this->properties, $this->tableName);
115
-
116
-        if ($boolCommit) {
117
-            return true;
118
-        }
119
-
120
-        throw NoRecordInsertionException::create("Record not created successfully");
121
-    }
122
-
123
-    /**
124
-     * This method find a record by id
125
-     * @params int id
126
-     * @return Object
127
-     * @throws NoArgumentPassedToFunctionException
128
-     */
129
-    public static function find($id)
130
-    {
131
-        $num_args = (int) func_num_args(); // get number of arguments passed to
132
-
133
-        if ($num_args == 0 || $num_args > 1) {
134
-            throw NoArgumentPassedToFunctionException::create("Argument missing: only one argument is allowed");
135
-        }
136
-
137
-        if ($id == "") {
138
-            throw NullArgumentPassedToFunction::create("This function expect a value");
139
-        }
140
-
141
-        $staticFindInstance = new static();
142
-        $staticFindInstance->id = $id == "" ? false : $id;
143
-
144
-        return $staticFindInstance;
85
+	/**
86
+	 * This method create or update record in a database table
87
+	 * @params void
88
+	 * @return bool true or false;
89
+	 * @throws EmptyArrayException
90
+	 * @throws NoRecordInsertionException
91
+	 * @throws NoRecordUpdateException
92
+	 */
93
+	public function save()
94
+	{
95
+		$boolCommit = false;
96
+
97
+		if ($this->properties['id']) {
98
+			$allData = DatabaseHandler::read($id = $this->properties['id'], self::getClassName());
99
+
100
+			if ($this->checkIfRecordIsEmpty($allData)) {
101
+				$boolCommit = $this->databaseModel->update(['id' => $this->properties['id']], $this->tableName, $this->properties);
102
+
103
+				if ($boolCommit) {
104
+					return true;
105
+
106
+				}
107
+
108
+				throw NoRecordUpdateException::create("Record not updated successfully");
109
+			}
110
+
111
+			throw EmptyArrayException::create("Value passed didn't match any record");
112
+		}
113
+
114
+		$boolCommit = $this->databaseModel->create($this->properties, $this->tableName);
115
+
116
+		if ($boolCommit) {
117
+			return true;
118
+		}
119
+
120
+		throw NoRecordInsertionException::create("Record not created successfully");
121
+	}
122
+
123
+	/**
124
+	 * This method find a record by id
125
+	 * @params int id
126
+	 * @return Object
127
+	 * @throws NoArgumentPassedToFunctionException
128
+	 */
129
+	public static function find($id)
130
+	{
131
+		$num_args = (int) func_num_args(); // get number of arguments passed to
132
+
133
+		if ($num_args == 0 || $num_args > 1) {
134
+			throw NoArgumentPassedToFunctionException::create("Argument missing: only one argument is allowed");
135
+		}
136
+
137
+		if ($id == "") {
138
+			throw NullArgumentPassedToFunction::create("This function expect a value");
139
+		}
140
+
141
+		$staticFindInstance = new static();
142
+		$staticFindInstance->id = $id == "" ? false : $id;
143
+
144
+		return $staticFindInstance;
145 145
         
146
-    }
146
+	}
147 147
     
148
-    /**
149
-     * This method delete a row from the table by the row id
150
-     * @params int id
151
-     * @return boolean true or false
152
-     * @throws NoRecordDeletionException;
153
-     */
154
-    public static function destroy($id)
155
-    {
156
-        $boolDeleted = false;
157
-
158
-        $num_args = (int) func_num_args(); // get number of arguments passed to
148
+	/**
149
+	 * This method delete a row from the table by the row id
150
+	 * @params int id
151
+	 * @return boolean true or false
152
+	 * @throws NoRecordDeletionException;
153
+	 */
154
+	public static function destroy($id)
155
+	{
156
+		$boolDeleted = false;
157
+
158
+		$num_args = (int) func_num_args(); // get number of arguments passed to
159 159
         
160
-        if ($num_args == 0 || $num_args > 1) {
161
-            throw NoArgumentPassedToFunctionException::create("Argument missing: only one argument is allowed");
162
-        }
160
+		if ($num_args == 0 || $num_args > 1) {
161
+			throw NoArgumentPassedToFunctionException::create("Argument missing: only one argument is allowed");
162
+		}
163 163
 
164
-        $boolDeleted = DatabaseHandler::delete($id, self::getClassName());
164
+		$boolDeleted = DatabaseHandler::delete($id, self::getClassName());
165 165
 
166
-        if ($boolDeleted) {
167
-            return true;
166
+		if ($boolDeleted) {
167
+			return true;
168 168
 
169
-        }
169
+		}
170 170
 
171
-        throw NoRecordDeletionException::create("Record deletion unsuccessful because id does not match any record");
172
-    }
171
+		throw NoRecordDeletionException::create("Record deletion unsuccessful because id does not match any record");
172
+	}
173 173
 
174 174
    /**
175 175
     * This method return the current class name
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
     */
179 179
    public static function getClassName()
180 180
    {
181
-       $tableName = preg_split('/(?=[A-Z])/', get_called_class());
181
+	   $tableName = preg_split('/(?=[A-Z])/', get_called_class());
182 182
        
183
-       $className = end($tableName);
183
+	   $className = end($tableName);
184 184
 
185
-       return self::pluralize(strtolower($className));
185
+	   return self::pluralize(strtolower($className));
186 186
 
187 187
    }
188 188
    
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
     * @param $arrayOfRecord
192 192
     * @return bool
193 193
     */
194
-    public function checkIfRecordIsEmpty($arrayOfRecord)
195
-    {
196
-        if (count($arrayOfRecord) > 0) {
197
-            return true;
194
+	public function checkIfRecordIsEmpty($arrayOfRecord)
195
+	{
196
+		if (count($arrayOfRecord) > 0) {
197
+			return true;
198 198
 
199
-        }
199
+		}
200 200
         
201
-        return false;
202
-    }
201
+		return false;
202
+	}
203 203
 
204 204
 }
Please login to merge, or discard this patch.
src/Database/DatabaseConnection.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -14,75 +14,75 @@
 block discarded – undo
14 14
 
15 15
 class DatabaseConnection extends PDO {
16 16
     
17
-    private $databaseName;
18
-    private $databaseHost;
19
-    private $databaseDriver;
20
-    private $databaseUsername;
21
-    private $databasePassword;
17
+	private $databaseName;
18
+	private $databaseHost;
19
+	private $databaseDriver;
20
+	private $databaseUsername;
21
+	private $databasePassword;
22 22
     
23
-    public  function  __construct() 
24
-    {
25
-        $this->loadEnv(); // load the environment variables
23
+	public  function  __construct() 
24
+	{
25
+		$this->loadEnv(); // load the environment variables
26 26
 
27
-        $this->databaseName     =  getenv('databaseName');
28
-        $this->databaseHost     =  getenv('databaseHost');
29
-        $this->databaseDriver   =  getenv('databaseDriver');
30
-        $this->databaseUsername =  getenv('databaseUsername');
31
-        $this->databasePassword =  getenv('databasePassword');
27
+		$this->databaseName     =  getenv('databaseName');
28
+		$this->databaseHost     =  getenv('databaseHost');
29
+		$this->databaseDriver   =  getenv('databaseDriver');
30
+		$this->databaseUsername =  getenv('databaseUsername');
31
+		$this->databasePassword =  getenv('databasePassword');
32 32
         
33
-        try {
34
-            $options = [
35
-                PDO::ATTR_PERSISTENT => true,
36
-                PDO::ATTR_ERRMODE    => PDO::ERRMODE_EXCEPTION
37
-            ];
33
+		try {
34
+			$options = [
35
+				PDO::ATTR_PERSISTENT => true,
36
+				PDO::ATTR_ERRMODE    => PDO::ERRMODE_EXCEPTION
37
+			];
38 38
 
39
-        parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options);
39
+		parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options);
40 40
             
41
-        } catch(PDOException $e) {
42
-            return $e->getMessage();
41
+		} catch(PDOException $e) {
42
+			return $e->getMessage();
43 43
 
44
-        }
44
+		}
45 45
         
46
-    }
46
+	}
47 47
 
48
-    /**
49
-     * This method determines the driver to be used for appropriate database server
50
-     * @params void
51
-     * @return string dsn
52
-     */
53
-     public function getDatabaseDriver()
54
-     {
55
-        $dsn = "";
48
+	/**
49
+	 * This method determines the driver to be used for appropriate database server
50
+	 * @params void
51
+	 * @return string dsn
52
+	 */
53
+	 public function getDatabaseDriver()
54
+	 {
55
+		$dsn = "";
56 56
 
57
-        switch ($this->databaseDriver) {
58
-            case 'mysql':
59
-                $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; // Set DSN
60
-                break;
61
-            case 'sqlite':
62
-                $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName;
63
-                break;
64
-            case 'pgsql':
65
-                $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName;
66
-                break;
67
-            default:
68
-                $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName;
69
-                break;
70
-        }
57
+		switch ($this->databaseDriver) {
58
+			case 'mysql':
59
+				$dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; // Set DSN
60
+				break;
61
+			case 'sqlite':
62
+				$dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName;
63
+				break;
64
+			case 'pgsql':
65
+				$dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName;
66
+				break;
67
+			default:
68
+				$dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName;
69
+				break;
70
+		}
71 71
 
72
-        return $dsn;
72
+		return $dsn;
73 73
 
74
-     }
74
+	 }
75 75
 
76
-     /**
77
-      * Load Dotenv to grant getenv() access to environment variables in .env file
78
-      */
79
-     public function loadEnv()
80
-     {
81
-        if (! getenv("APP_ENV")) {
82
-            $dotenv = new Dotenv(__DIR__.'/../../');
83
-            $dotenv->load();
84
-        }
76
+	 /**
77
+	  * Load Dotenv to grant getenv() access to environment variables in .env file
78
+	  */
79
+	 public function loadEnv()
80
+	 {
81
+		if (! getenv("APP_ENV")) {
82
+			$dotenv = new Dotenv(__DIR__.'/../../');
83
+			$dotenv->load();
84
+		}
85 85
         
86
-     }
86
+	 }
87 87
 
88 88
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $this->loadEnv(); // load the environment variables
26 26
 
27
-        $this->databaseName     =  getenv('databaseName');
28
-        $this->databaseHost     =  getenv('databaseHost');
29
-        $this->databaseDriver   =  getenv('databaseDriver');
30
-        $this->databaseUsername =  getenv('databaseUsername');
31
-        $this->databasePassword =  getenv('databasePassword');
27
+        $this->databaseName     = getenv('databaseName');
28
+        $this->databaseHost     = getenv('databaseHost');
29
+        $this->databaseDriver   = getenv('databaseDriver');
30
+        $this->databaseUsername = getenv('databaseUsername');
31
+        $this->databasePassword = getenv('databasePassword');
32 32
         
33 33
         try {
34 34
             $options = [
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
         parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options);
40 40
             
41
-        } catch(PDOException $e) {
41
+        } catch (PDOException $e) {
42 42
             return $e->getMessage();
43 43
 
44 44
         }
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
       */
79 79
      public function loadEnv()
80 80
      {
81
-        if (! getenv("APP_ENV")) {
81
+        if (!getenv("APP_ENV")) {
82 82
             $dotenv = new Dotenv(__DIR__.'/../../');
83 83
             $dotenv->load();
84 84
         }
Please login to merge, or discard this patch.
src/Database/DatabaseHelper.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
         }
36 36
 
37 37
         $sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'(';
38
-        $sql.= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )';
38
+        $sql .= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )';
39 39
 
40 40
         return $conn->exec($sql);
41 41
 
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -12,34 +12,34 @@
 block discarded – undo
12 12
 
13 13
 class DatabaseHelper {
14 14
   
15
-    public $dbConn;
15
+	public $dbConn;
16 16
     
17
-    /**
18
-     * This is a constructor; a default method  that will be called automatically during class instantiation
19
-     */
20
-    public function __construct($dbConnect)
21
-    {
22
-        $this->dbConn = $dbConnect;
23
-
24
-    }
17
+	/**
18
+	 * This is a constructor; a default method  that will be called automatically during class instantiation
19
+	 */
20
+	public function __construct($dbConnect)
21
+	{
22
+		$this->dbConn = $dbConnect;
23
+
24
+	}
25 25
     
26
-    /**
27
-     * This method creates a particular table
28
-     * @param tableName
29
-     * $return boolean true or false
30
-     */
31
-    public function createTable($tableName, $conn = NULL)
32
-    {
33
-        if (is_null($conn)) {
34
-            $conn = $this->dbConn;
35
-        }
36
-
37
-        $sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'(';
38
-        $sql.= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )';
39
-
40
-        return $conn->exec($sql);
41
-
42
-        throw TableNotCreatedException::create("Check your database connection");
26
+	/**
27
+	 * This method creates a particular table
28
+	 * @param tableName
29
+	 * $return boolean true or false
30
+	 */
31
+	public function createTable($tableName, $conn = NULL)
32
+	{
33
+		if (is_null($conn)) {
34
+			$conn = $this->dbConn;
35
+		}
36
+
37
+		$sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'(';
38
+		$sql.= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )';
39
+
40
+		return $conn->exec($sql);
41
+
42
+		throw TableNotCreatedException::create("Check your database connection");
43 43
    }
44 44
   
45 45
 }
Please login to merge, or discard this patch.
src/Exceptions/NoRecordInsertionException.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  * @license  <https://opensource.org/license/MIT> MIT
7 7
  */
8 8
 
9
-namespace Laztopaz\potatoORM    ;
9
+namespace Laztopaz\potatoORM;
10 10
 
11 11
 use Exception;
12 12
 
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@
 block discarded – undo
12 12
 
13 13
 class NoRecordInsertionException extends Exception {
14 14
 
15
-    public static function create($mesaage)
16
-    {
17
-        return new static($mesaage);
15
+	public static function create($mesaage)
16
+	{
17
+		return new static($mesaage);
18 18
         
19
-    }
19
+	}
20 20
 }
Please login to merge, or discard this patch.
src/Exceptions/NullArgumentPassedToFunctionException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
 
13 13
 class NullArgumentPassedToFunction extends Exception {
14 14
 
15
-    public static function create($message)
16
-    {
17
-        return new static ($message);
15
+	public static function create($message)
16
+	{
17
+		return new static ($message);
18 18
 
19
-    }
19
+	}
20 20
 
21 21
 }
Please login to merge, or discard this patch.