Completed
Push — test ( ce85b4...b0706c )
by Temitope
04:17 queued 54s
created
src/Exceptions/NoRecordDeletionException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@
 block discarded – undo
12 12
 
13 13
 class NoRecordDeletionException extends  Exception
14 14
 {
15
-    public static function checkNoRecordUpdateException($message)
16
-    {
17
-        return new static($message);
18
-    }
15
+	public static function checkNoRecordUpdateException($message)
16
+	{
17
+		return new static($message);
18
+	}
19 19
 }
Please login to merge, or discard this patch.
src/Exceptions/EmptyArrayException.php 1 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 EmptyArrayException extends Exception {
14 14
 	
15
-    public static function checkEmptyArrayException($message)
16
-    {
17
-    	return new static($message);
18
-    }
15
+	public static function checkEmptyArrayException($message)
16
+	{
17
+		return new static($message);
18
+	}
19 19
 
20 20
 }
Please login to merge, or discard this patch.
src/Exceptions/NoArgumentPassedToFunctionException.php 1 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 NoArgumentPassedToFunctionException extends Exception {
14 14
 	
15
-    public static function checkNoArgumentPassedToFunction($message)
16
-    {
17
-    	return new static($message);
18
-    }
15
+	public static function checkNoArgumentPassedToFunction($message)
16
+	{
17
+		return new static($message);
18
+	}
19 19
 
20 20
 }
Please login to merge, or discard this patch.
src/Exceptions/NoRecordInsertionException.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@
 block discarded – undo
12 12
 
13 13
 class NoRecordInsertionException extends Exception {
14 14
 
15
-    public static function checkNoRecordAddedException($mesaage)
16
-    {
17
-    	return new static($mesaage);
18
-    }
15
+	public static function checkNoRecordAddedException($mesaage)
16
+	{
17
+		return new static($mesaage);
18
+	}
19 19
 }
Please login to merge, or discard this patch.
src/Exceptions/NoRecordUpdateException.php 1 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 NoRecordUpdateException extends  Exception {
14 14
 	
15
-    public static function checkNoRecordUpdateException($message)
16
-    {
17
-    	return new static($message);
18
-    }
15
+	public static function checkNoRecordUpdateException($message)
16
+	{
17
+		return new static($message);
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,9 +12,9 @@
 block discarded – undo
12 12
 
13 13
 class NullArgumentPassedToFunction extends Exception {
14 14
 
15
-    public static function ckeckNullArgumentPassedToFunction($message)
16
-    {
17
-    	return new static ($message);
18
-    }
15
+	public static function ckeckNullArgumentPassedToFunction($message)
16
+	{
17
+		return new static ($message);
18
+	}
19 19
 
20 20
 }
Please login to merge, or discard this patch.
src/Exceptions/WrongArgumentException.php 1 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 WrongArgumentException extends Exception {
14 14
 
15
-    public function checkWrongArgumentException($message)
16
-    {
17
-    	return new static ($message);
18
-    }
15
+	public function checkWrongArgumentException($message)
16
+	{
17
+		return new static ($message);
18
+	}
19 19
 
20 20
 }
Please login to merge, or discard this patch.
src/Database/DatabaseConnection.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,73 +14,73 @@
 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
26
-    	$this->databaseName     =  getenv('databaseName');
27
-    	$this->databaseHost     =  getenv('databaseHost');
28
-    	$this->databaseDriver   =  getenv('databaseDriver');
29
-    	$this->databaseUsername =  getenv('databaseUsername');
30
-    	$this->databasePassword =  getenv('databasePassword');
23
+	public  function  __construct() 
24
+	{
25
+		$this->loadEnv(); // load the environment variables
26
+		$this->databaseName     =  getenv('databaseName');
27
+		$this->databaseHost     =  getenv('databaseHost');
28
+		$this->databaseDriver   =  getenv('databaseDriver');
29
+		$this->databaseUsername =  getenv('databaseUsername');
30
+		$this->databasePassword =  getenv('databasePassword');
31 31
     	
32
-    	try {
33
-    	    $options = [
34
-    	    	PDO::ATTR_PERSISTENT    => true,
35
-    	    	PDO::ATTR_ERRMODE       => PDO::ERRMODE_EXCEPTION
36
-    	    	];
37
-    	    	parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options);
32
+		try {
33
+			$options = [
34
+				PDO::ATTR_PERSISTENT    => true,
35
+				PDO::ATTR_ERRMODE       => PDO::ERRMODE_EXCEPTION
36
+				];
37
+				parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options);
38 38
     		
39
-    	} catch(PDOException $e) {
40
-    	    return $e->getMessage();
41
-    	}
39
+		} catch(PDOException $e) {
40
+			return $e->getMessage();
41
+		}
42 42
     	
43
-    }
43
+	}
44 44
 
45
-    /**
46
-     * This method determines the driver to be used for appropriate database server
47
-     * @params void
48
-     * @return string dsn
49
-     */
50
-     public function getDatabaseDriver()
51
-     {
52
-     	$dsn = "";
45
+	/**
46
+	 * This method determines the driver to be used for appropriate database server
47
+	 * @params void
48
+	 * @return string dsn
49
+	 */
50
+	 public function getDatabaseDriver()
51
+	 {
52
+	 	$dsn = "";
53 53
      	
54
-     	switch ($this->databaseDriver)
55
-     	{
56
-     	    case 'mysql':
57
-     	    // Set DSN
58
-     	    $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName;
59
-     	    break;
60
-     	    case 'sqlite':
61
-     	    // Set DSN
62
-     	    $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName;
63
-     	    break;
64
-     	    case 'pgsql':
65
-     	    // Set DSN
66
-     	    $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName;
67
-     	    break;
68
-     	    default:
69
-     	    // Set DSN
70
-     	    $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName;
71
-     	}
72
-     	return $dsn;
73
-     }
54
+	 	switch ($this->databaseDriver)
55
+	 	{
56
+	 		case 'mysql':
57
+	 		// Set DSN
58
+	 		$dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName;
59
+	 		break;
60
+	 		case 'sqlite':
61
+	 		// Set DSN
62
+	 		$dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName;
63
+	 		break;
64
+	 		case 'pgsql':
65
+	 		// Set DSN
66
+	 		$dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName;
67
+	 		break;
68
+	 		default:
69
+	 		// Set DSN
70
+	 		$dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName;
71
+	 	}
72
+	 	return $dsn;
73
+	 }
74 74
 
75
-     /**
76
-      * Load Dotenv to grant getenv() access to environment variables in .env file
77
-      */
78
-     public function loadEnv()
79
-     {
80
-     	if (!getenv("APP_ENV")) {
81
-     	    $dotenv = new Dotenv(__DIR__.'/../../');
82
-     	    $dotenv->load();
83
-     	}
84
-     }
75
+	 /**
76
+	  * Load Dotenv to grant getenv() access to environment variables in .env file
77
+	  */
78
+	 public function loadEnv()
79
+	 {
80
+	 	if (!getenv("APP_ENV")) {
81
+	 		$dotenv = new Dotenv(__DIR__.'/../../');
82
+	 		$dotenv->load();
83
+	 	}
84
+	 }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
src/Database/DatabaseHandler.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -14,90 +14,90 @@  discard block
 block discarded – undo
14 14
 use Laztopaz\potatoORM\EmptyArrayException;
15 15
 
16 16
 class DatabaseHandler {
17
-    private $tableFields;
18
-    private $dbHelperInstance;
19
-    private $dbConnection;
20
-    private $model;
17
+	private $tableFields;
18
+	private $dbHelperInstance;
19
+	private $dbConnection;
20
+	private $model;
21 21
     
22
-    /**
23
-     * This is a constructor; a default method  that will be called automatically during class instantiation
24
-     */
25
-     public function __construct($modelClassName, $dbConn = Null)
26
-     {
27
-     	if (is_null($dbConn)) {
28
-     		$this->dbConnection = new DatabaseConnection();
29
-     	} else {
30
-     	    $this->dbConnection = $dbConn;
31
-     	}
32
-     	$this->model = $modelClassName;
33
-     }
22
+	/**
23
+	 * This is a constructor; a default method  that will be called automatically during class instantiation
24
+	 */
25
+	 public function __construct($modelClassName, $dbConn = Null)
26
+	 {
27
+	 	if (is_null($dbConn)) {
28
+	 		$this->dbConnection = new DatabaseConnection();
29
+	 	} else {
30
+	 		$this->dbConnection = $dbConn;
31
+	 	}
32
+	 	$this->model = $modelClassName;
33
+	 }
34 34
      
35
-    /**
36
-     * This method create a record and store it in a table row
37
-     * @params associative array, string tablename
38
-     * @return boolean true or false
39
-     */
40
-    public function create($associative1DArray, $tableName, $dbConn = Null)
41
-    {
42
-    	$tableFields = $this->getColumnNames($this->model, $this->dbConnection);
35
+	/**
36
+	 * This method create a record and store it in a table row
37
+	 * @params associative array, string tablename
38
+	 * @return boolean true or false
39
+	 */
40
+	public function create($associative1DArray, $tableName, $dbConn = Null)
41
+	{
42
+		$tableFields = $this->getColumnNames($this->model, $this->dbConnection);
43 43
     	
44
-    	$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray);
45
-    	if (count($unexpectedFields) > 0) {
46
-    	    throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field");
47
-    	}
48
-    	unset($tableFields[0]);
49
-    	if (is_null($dbConn)) {
50
-    	    $dbConn = $this->dbConnection;
51
-    	}
52
-    	$this->insertRecord($dbConn, $tableName, $associative1DArray);
53
-    }
44
+		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray);
45
+		if (count($unexpectedFields) > 0) {
46
+			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field");
47
+		}
48
+		unset($tableFields[0]);
49
+		if (is_null($dbConn)) {
50
+			$dbConn = $this->dbConnection;
51
+		}
52
+		$this->insertRecord($dbConn, $tableName, $associative1DArray);
53
+	}
54 54
     
55
-    private function  insertRecord($dbConn, $tableName, $associative1DArray) 
56
-    {
57
-    	$insertQuery = 'INSERT INTO '.$tableName;
58
-    	$TableValues = implode(',',array_keys($associative1DArray));
59
-    	foreach ($associative1DArray as $field => $value) {
60
-    	    $FormValues[] = "'".trim(addslashes($value))."'";
61
-    	}
62
-    	$splittedTableValues = implode(',', $FormValues);
63
-    	$insertQuery.= ' ('.$TableValues.')';
64
-    	$insertQuery.= ' VALUES ('.$splittedTableValues.')';
65
-    	$executeQuery = $dbConn->exec($insertQuery);
66
-    	return $executeQuery ? : false;
55
+	private function  insertRecord($dbConn, $tableName, $associative1DArray) 
56
+	{
57
+		$insertQuery = 'INSERT INTO '.$tableName;
58
+		$TableValues = implode(',',array_keys($associative1DArray));
59
+		foreach ($associative1DArray as $field => $value) {
60
+			$FormValues[] = "'".trim(addslashes($value))."'";
61
+		}
62
+		$splittedTableValues = implode(',', $FormValues);
63
+		$insertQuery.= ' ('.$TableValues.')';
64
+		$insertQuery.= ' VALUES ('.$splittedTableValues.')';
65
+		$executeQuery = $dbConn->exec($insertQuery);
66
+		return $executeQuery ? : false;
67 67
     	
68 68
 	}
69 69
 
70
-    /**
71
-     * This method updates any table by supplying 3 parameter
72
-     * @params: $updateParams, $tableName, $associative1DArray
73
-     * @return boolean true or false
74
-     */
75
-    public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null)
76
-    {
77
-    	$sql = "";
78
-    	if (is_null($dbConn)) {
79
-    	    $dbConn = $this->dbConnection;
80
-    	}
81
-    	$updateSql = "UPDATE `$tableName` SET ";
82
-    	unset($associative1DArray['id']);
83
-    	$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray);
70
+	/**
71
+	 * This method updates any table by supplying 3 parameter
72
+	 * @params: $updateParams, $tableName, $associative1DArray
73
+	 * @return boolean true or false
74
+	 */
75
+	public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null)
76
+	{
77
+		$sql = "";
78
+		if (is_null($dbConn)) {
79
+			$dbConn = $this->dbConnection;
80
+		}
81
+		$updateSql = "UPDATE `$tableName` SET ";
82
+		unset($associative1DArray['id']);
83
+		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray);
84 84
     	
85
-    	if (count($unexpectedFields) > 0) {
86
-    		throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field");
87
-    	}
88
-    	foreach($associative1DArray as $field => $value) {
89
-    	    $sql .= "`$field` = '$value'".",";
90
-    	}
85
+		if (count($unexpectedFields) > 0) {
86
+			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field");
87
+		}
88
+		foreach($associative1DArray as $field => $value) {
89
+			$sql .= "`$field` = '$value'".",";
90
+		}
91 91
     	
92
-    	$updateSql .= $this->prepareUpdateQuery($sql);
92
+		$updateSql .= $this->prepareUpdateQuery($sql);
93 93
     	
94
-    	foreach ($updateParams as $key => $val) {
95
-    	    $updateSql .= " WHERE $key = $val";
96
-    	}
97
-    	$stmt = $dbConn->prepare($updateSql);
98
-    	$boolResponse = $stmt->execute();
99
-    	return $boolResponse ?  : false;
100
-    }
94
+		foreach ($updateParams as $key => $val) {
95
+			$updateSql .= " WHERE $key = $val";
96
+		}
97
+		$stmt = $dbConn->prepare($updateSql);
98
+		$boolResponse = $stmt->execute();
99
+		return $boolResponse ?  : false;
100
+	}
101 101
     
102 102
   /**
103 103
    * This method retrieves record from a table
@@ -109,22 +109,22 @@  discard block
 block discarded – undo
109 109
    	$tableData = [];
110 110
    	
111 111
    	if (is_null($dbConn)) {
112
-   	    $dbConn = new DatabaseConnection();
112
+   		$dbConn = new DatabaseConnection();
113 113
    	}
114 114
    	$sql = $id  ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
115 115
    	
116 116
    	try {
117
-   	    $stmt = $dbConn->prepare($sql);
118
-   	    $stmt->bindValue(':table', $tableName);
119
-   	    $stmt->bindValue(':id', $id);
120
-   	    $stmt->execute();
117
+   		$stmt = $dbConn->prepare($sql);
118
+   		$stmt->bindValue(':table', $tableName);
119
+   		$stmt->bindValue(':id', $id);
120
+   		$stmt->execute();
121 121
    	} catch (PDOException $e) {
122
-   	    return  $e->getMessage();
122
+   		return  $e->getMessage();
123 123
    	}
124 124
    	$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
125 125
    	
126 126
    	foreach($results as $result) {
127
-   	    array_push($tableData, $result);
127
+   		array_push($tableData, $result);
128 128
    	}
129 129
    	return $tableData;
130 130
    }
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
    */
137 137
   public static function delete($id, $tableName, $dbConn = Null)
138 138
   {
139
-      if (is_null($dbConn)) {
140
-          $dbConn = new DatabaseConnection();
141
-      }
139
+	  if (is_null($dbConn)) {
140
+		  $dbConn = new DatabaseConnection();
141
+	  }
142 142
       
143
-      $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id;
144
-      $boolResponse = $dbConn->exec($sql);
145
-      return $boolResponse ? : false;
143
+	  $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id;
144
+	  $boolResponse = $dbConn->exec($sql);
145
+	  return $boolResponse ? : false;
146 146
   }
147 147
   
148 148
   /**
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
    */
154 154
   public static function checkIfMagicSetterContainsIsSameAsClassModel(array $tableColumn, array $userSetterArray)
155 155
   {
156
-      $unexpectedFields = [];
157
-      foreach ($userSetterArray as $key => $val) {
158
-          if (!in_array($key,$tableColumn)) {
159
-              $unexpectedFields[] = $key;
160
-          }
161
-      }
162
-      return $unexpectedFields;
156
+	  $unexpectedFields = [];
157
+	  foreach ($userSetterArray as $key => $val) {
158
+		  if (!in_array($key,$tableColumn)) {
159
+			  $unexpectedFields[] = $key;
160
+		  }
161
+	  }
162
+	  return $unexpectedFields;
163 163
   }
164 164
   
165 165
   /**
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
    */
170 170
   public function prepareUpdateQuery($sql)
171 171
   {
172
-      $splittedQuery = explode(",",$sql);
173
-      array_pop($splittedQuery);
174
-      $mergeData = implode(",",$splittedQuery);
175
-      return $mergeData;
172
+	  $splittedQuery = explode(",",$sql);
173
+	  array_pop($splittedQuery);
174
+	  $mergeData = implode(",",$splittedQuery);
175
+	  return $mergeData;
176 176
   }
177 177
   
178 178
   /**
@@ -184,22 +184,22 @@  discard block
 block discarded – undo
184 184
    */
185 185
   public function findAndWhere($params, $tableName, $dbConn)
186 186
   {
187
-      if (is_null($dbConn)) {
188
-          $dbConn = $this->dbConnection;
189
-      }
190
-      if (is_array($params) && !empty($params)) {
191
-          $sql = "SELECT * FROM ".$tableName;
187
+	  if (is_null($dbConn)) {
188
+		  $dbConn = $this->dbConnection;
189
+	  }
190
+	  if (is_array($params) && !empty($params)) {
191
+		  $sql = "SELECT * FROM ".$tableName;
192 192
           
193
-          foreach ($params as $key => $val) {
194
-              $sql .= " WHERE `$key` = '$val'";
195
-          }
196
-          $statement = $dbConn->prepare($sql);
197
-          $statement->execute();
198
-          $returnedRowNumbers = $statement->rowCount();
193
+		  foreach ($params as $key => $val) {
194
+			  $sql .= " WHERE `$key` = '$val'";
195
+		  }
196
+		  $statement = $dbConn->prepare($sql);
197
+		  $statement->execute();
198
+		  $returnedRowNumbers = $statement->rowCount();
199 199
           
200
-          return $returnedRowNumbers  ? true : false;
201
-      }
202
-      throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array");
200
+		  return $returnedRowNumbers  ? true : false;
201
+	  }
202
+	  throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array");
203 203
   }
204 204
   
205 205
   /**
@@ -209,22 +209,22 @@  discard block
 block discarded – undo
209 209
    * @return array
210 210
    */
211 211
  public function getColumnNames($table, $dbConn = Null) {
212
-     $tableFields = [];
212
+	 $tableFields = [];
213 213
      
214
-     if (is_null($dbConn)) {
215
-         $dbConn = $this->dbConnection;
216
-     }
217
-     $sql = "SHOW COLUMNS FROM ".$table;
214
+	 if (is_null($dbConn)) {
215
+		 $dbConn = $this->dbConnection;
216
+	 }
217
+	 $sql = "SHOW COLUMNS FROM ".$table;
218 218
      
219
-     $stmt = $dbConn->prepare($sql);
220
-     $stmt->bindValue(':table', $table, PDO::PARAM_STR);
221
-     $stmt->execute();
222
-     $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
219
+	 $stmt = $dbConn->prepare($sql);
220
+	 $stmt->bindValue(':table', $table, PDO::PARAM_STR);
221
+	 $stmt->execute();
222
+	 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
223 223
      
224
-     foreach($results as $result) {
225
-         array_push($tableFields, $result['Field']);
226
-     }
227
-     return $tableFields;
224
+	 foreach($results as $result) {
225
+		 array_push($tableFields, $result['Field']);
226
+	 }
227
+	 return $tableFields;
228 228
  }
229 229
 
230 230
 }
Please login to merge, or discard this patch.