Completed
Push — test ( 2ec062...3a08db )
by Temitope
02:38
created
src/Database/DatabaseHandler.php 2 patches
Doc Comments   +12 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,6 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 	/**
24 24
 	 * This is a constructor; a default method  that will be called automatically during class instantiation
25
+	 * @param string|false $modelClassName
25 26
 	 */
26 27
 	public function __construct($modelClassName, $dbConn = Null)
27 28
 	{
@@ -36,7 +37,8 @@  discard block
 block discarded – undo
36 37
 	/**
37 38
 	 * This method create a record and store it in a table row
38 39
 	 * @params associative array, string tablename
39
-	 * @return boolean true or false
40
+	 * @param string|false $tableName
41
+	 * @return boolean|null true or false
40 42
 	 */
41 43
 	public function create($associative1DArray, $tableName, $dbConn = Null)
42 44
 	{
@@ -79,6 +81,10 @@  discard block
 block discarded – undo
79 81
 	 * @params: $updateParams, $tableName, $associative1DArray
80 82
 	 * @return boolean true or false
81 83
 	 */
84
+
85
+	/**
86
+	 * @param string|false $tableName
87
+	 */
82 88
 	public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null)
83 89
 	{
84 90
 		$sql = "";
@@ -112,6 +118,7 @@  discard block
 block discarded – undo
112 118
 	/**
113 119
 	 * This method retrieves record from a table
114 120
 	 * @params int id, string tableName
121
+	 * @param string|false $tableName
115 122
 	 * @return array
116 123
 	 */
117 124
 	public static function read($id, $tableName, $dbConn = Null)
@@ -143,6 +150,7 @@  discard block
 block discarded – undo
143 150
 	/**
144 151
 	 * This method deletes a record  from a table row
145 152
 	 * @params int id, string tableName
153
+	 * @param string|false $tableName
146 154
 	 * @return boolean true or false
147 155
 	 */
148 156
 	public static function delete($id, $tableName, $dbConn = Null)
@@ -177,7 +185,7 @@  discard block
 block discarded – undo
177 185
 
178 186
 	/**
179 187
 	 * This method returns sql query
180
-	 * @param $sql
188
+	 * @param string $sql
181 189
 	 * @return string
182 190
 	 */
183 191
 	public function prepareUpdateQuery($sql)
@@ -192,7 +200,7 @@  discard block
 block discarded – undo
192 200
 	/**
193 201
 	 * @param array $params
194 202
 	 * @param $tableName
195
-	 * @param $dbConn
203
+	 * @param DatabaseConnection $dbConn
196 204
 	 * @return bool
197 205
 	 * @throws EmptyArrayException
198 206
 	 */
@@ -219,6 +227,7 @@  discard block
 block discarded – undo
219 227
 	 * This method returns column fields of a particular table
220 228
 	 * @param $table
221 229
 	 * @param $conn
230
+	 * @param DatabaseConnection $dbConn
222 231
 	 * @return array
223 232
 	 */
224 233
 	public function getColumnNames($table, $dbConn = Null) {
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public function create($associative1DArray, $tableName, $dbConn = Null)
42 42
 	{
43
-		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray);
43
+		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray);
44 44
 
45 45
 		if (count($unexpectedFields) > 0) {
46
-			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field");
46
+			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field");
47 47
 		}
48 48
 		if ($this->findAndWhere(['alias' => $associative1DArray['alias']], $this->model, $this->dbConnection)) {
49 49
 			throw NoRecordInsertionException::checkNoRecordAddedException("Insertion Error: Record already exist");
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 	private function  insertRecord($dbConn, $tableName, $associative1DArray) {
62 62
 
63 63
 		$insertQuery = 'INSERT INTO '.$tableName;
64
-		$TableValues = implode(',',array_keys($associative1DArray));
64
+		$TableValues = implode(',', array_keys($associative1DArray));
65 65
 		foreach ($associative1DArray as $field => $value) {
66 66
 
67 67
 			$FormValues[] = "'".trim(addslashes($value))."'";
68 68
 		}
69 69
 		$splittedTableValues = implode(',', $FormValues);
70
-		$insertQuery.= ' ('.$TableValues.')';
71
-		$insertQuery.= ' VALUES ('.$splittedTableValues.')';
70
+		$insertQuery .= ' ('.$TableValues.')';
71
+		$insertQuery .= ' VALUES ('.$splittedTableValues.')';
72 72
 		$executeQuery = $dbConn->exec($insertQuery);
73 73
 
74
-		return $executeQuery ? : false;
74
+		return $executeQuery ?: false;
75 75
 	}
76 76
 
77 77
 	/*
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 
89 89
 		$updateSql = "UPDATE `$tableName` SET ";
90 90
 		unset($associative1DArray['id']);
91
-		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray);
91
+		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray);
92 92
 
93 93
 		if (count($unexpectedFields) > 0) {
94 94
 			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field");
95 95
 		}
96 96
 
97
-		foreach($associative1DArray as $field => $value) {
97
+		foreach ($associative1DArray as $field => $value) {
98 98
 			$sql .= "`$field` = '$value'".",";
99 99
 		}
100 100
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 		$stmt = $dbConn->prepare($updateSql);
107 107
 		$boolResponse = $stmt->execute();
108 108
 
109
-		return $boolResponse ?  : false;
109
+		return $boolResponse ?: false;
110 110
 	}
111 111
 
112 112
 	/**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		if (is_null($dbConn)) {
122 122
 			$dbConn = new DatabaseConnection();
123 123
 		}
124
-		$sql = $id  ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
124
+		$sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
125 125
 
126 126
 		try {
127 127
 			$stmt = $dbConn->prepare($sql);
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		}
134 134
 		$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
135 135
 
136
-		foreach($results as $result) {
136
+		foreach ($results as $result) {
137 137
 			array_push($tableData, $result);
138 138
 		}
139 139
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		$sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id;
154 154
 		$boolResponse = $dbConn->exec($sql);
155 155
 
156
-		return $boolResponse ? : false;
156
+		return $boolResponse ?: false;
157 157
 	}
158 158
 
159 159
 	/**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		$unexpectedFields = [];
168 168
 
169 169
 		foreach ($userSetterArray as $key => $val) {
170
-			if (!in_array($key,$tableColumn)) {
170
+			if (!in_array($key, $tableColumn)) {
171 171
 
172 172
 				$unexpectedFields[] = $key;
173 173
 			}
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function prepareUpdateQuery($sql)
184 184
 	{
185
-		$splittedQuery = explode(",",$sql);
185
+		$splittedQuery = explode(",", $sql);
186 186
 		array_pop($splittedQuery);
187
-		$mergeData = implode(",",$splittedQuery);
187
+		$mergeData = implode(",", $splittedQuery);
188 188
 
189 189
 		return $mergeData;
190 190
 	}
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			$statement = $dbConn->prepare($sql);
210 210
 			$statement->execute();
211 211
 			$returnedRowNumbers = $statement->rowCount();
212
-			return $returnedRowNumbers  ? true : false;
212
+			return $returnedRowNumbers ? true : false;
213 213
 		}
214 214
 
215 215
 		throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array");
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 		$stmt->execute();
236 236
 		$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
237 237
 
238
-		foreach($results as $result) {
238
+		foreach ($results as $result) {
239 239
 			array_push($tableFields, $result['Field']);
240 240
 		}
241 241
 			return $tableFields;
Please login to merge, or discard this patch.
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.