@@ -21,6 +21,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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) { |
@@ -9,10 +9,8 @@ |
||
| 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 | - |
|
| 16 | 14 | use Laztopaz\potatoORM\NoRecordDeletionException; |
| 17 | 15 | use Laztopaz\potatoORM\NoRecordInsertionException; |
| 18 | 16 | use Laztopaz\potatoORM\NoRecordUpdateException; |
@@ -18,98 +18,98 @@ discard block |
||
| 18 | 18 | use Laztopaz\potatoORM\NoRecordUpdateException; |
| 19 | 19 | |
| 20 | 20 | class DatabaseHandler { |
| 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 | - if (is_null($dbConn)) { |
|
| 31 | - $this->dbConnection = new DatabaseConnection(); |
|
| 32 | - } else { |
|
| 33 | - $this->dbConnection = $dbConn; |
|
| 34 | - } |
|
| 35 | - $this->model = $modelClassName; |
|
| 36 | - } |
|
| 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 | + if (is_null($dbConn)) { |
|
| 31 | + $this->dbConnection = new DatabaseConnection(); |
|
| 32 | + } else { |
|
| 33 | + $this->dbConnection = $dbConn; |
|
| 34 | + } |
|
| 35 | + $this->model = $modelClassName; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * This method create a record and store it in a table row |
|
| 40 | - * @params associative array, string tablename |
|
| 41 | - * @return boolean true or false |
|
| 42 | - */ |
|
| 43 | - public function create($associative1DArray, $tableName, $dbConn = Null) { |
|
| 44 | - $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
|
| 45 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray); |
|
| 46 | - if (count($unexpectedFields) > 0) { |
|
| 47 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as table field"); |
|
| 48 | - } |
|
| 49 | - unset($associative1DArray[0]); |
|
| 50 | - if (is_null($dbConn)) { |
|
| 51 | - $dbConn = $this->dbConnection; |
|
| 52 | - } |
|
| 53 | - return $this->insertRecord($dbConn, $tableName, $associative1DArray); |
|
| 54 | - } |
|
| 38 | + /** |
|
| 39 | + * This method create a record and store it in a table row |
|
| 40 | + * @params associative array, string tablename |
|
| 41 | + * @return boolean true or false |
|
| 42 | + */ |
|
| 43 | + public function create($associative1DArray, $tableName, $dbConn = Null) { |
|
| 44 | + $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
|
| 45 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray); |
|
| 46 | + if (count($unexpectedFields) > 0) { |
|
| 47 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as table field"); |
|
| 48 | + } |
|
| 49 | + unset($associative1DArray[0]); |
|
| 50 | + if (is_null($dbConn)) { |
|
| 51 | + $dbConn = $this->dbConnection; |
|
| 52 | + } |
|
| 53 | + return $this->insertRecord($dbConn, $tableName, $associative1DArray); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - private function insertRecord($dbConn, $tableName, $associative1DArray) { |
|
| 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 | - |
|
| 67 | - if ($executeQuery) { |
|
| 68 | - return true; |
|
| 69 | - } |
|
| 70 | - return false; |
|
| 71 | - |
|
| 72 | - throw NoRecordInsertionException::checkNoRecordAddedException("Record not inserted successfully"); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * This method updates any table by supplying 3 parameter |
|
| 77 | - * @params: $updateParams, $tableName, $associative1DArray |
|
| 78 | - * @return boolean true or false |
|
| 79 | - */ |
|
| 80 | - public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) |
|
| 81 | - { |
|
| 82 | - $sql = ""; |
|
| 83 | - if (is_null($dbConn)) { |
|
| 84 | - $dbConn = $this->dbConnection; |
|
| 85 | - } |
|
| 86 | - $updateSql = "UPDATE `$tableName` SET "; |
|
| 87 | - unset($associative1DArray['id']); |
|
| 88 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
| 56 | + private function insertRecord($dbConn, $tableName, $associative1DArray) { |
|
| 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 | + |
|
| 67 | + if ($executeQuery) { |
|
| 68 | + return true; |
|
| 69 | + } |
|
| 70 | + return false; |
|
| 71 | + |
|
| 72 | + throw NoRecordInsertionException::checkNoRecordAddedException("Record not inserted successfully"); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * This method updates any table by supplying 3 parameter |
|
| 77 | + * @params: $updateParams, $tableName, $associative1DArray |
|
| 78 | + * @return boolean true or false |
|
| 79 | + */ |
|
| 80 | + public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) |
|
| 81 | + { |
|
| 82 | + $sql = ""; |
|
| 83 | + if (is_null($dbConn)) { |
|
| 84 | + $dbConn = $this->dbConnection; |
|
| 85 | + } |
|
| 86 | + $updateSql = "UPDATE `$tableName` SET "; |
|
| 87 | + unset($associative1DArray['id']); |
|
| 88 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
| 89 | 89 | |
| 90 | - if (count($unexpectedFields) > 0) { |
|
| 91 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as table field"); |
|
| 92 | - } |
|
| 93 | - foreach($associative1DArray as $field => $value) { |
|
| 94 | - $sql .= "`$field` = '$value'".","; |
|
| 95 | - } |
|
| 90 | + if (count($unexpectedFields) > 0) { |
|
| 91 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as table field"); |
|
| 92 | + } |
|
| 93 | + foreach($associative1DArray as $field => $value) { |
|
| 94 | + $sql .= "`$field` = '$value'".","; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $updateSql .= $this->prepareUpdateQuery($sql); |
|
| 97 | + $updateSql .= $this->prepareUpdateQuery($sql); |
|
| 98 | 98 | |
| 99 | - foreach ($updateParams as $key => $val) { |
|
| 100 | - $updateSql .= " WHERE $key = $val"; |
|
| 101 | - } |
|
| 102 | - $stmt = $dbConn->prepare($updateSql); |
|
| 99 | + foreach ($updateParams as $key => $val) { |
|
| 100 | + $updateSql .= " WHERE $key = $val"; |
|
| 101 | + } |
|
| 102 | + $stmt = $dbConn->prepare($updateSql); |
|
| 103 | 103 | |
| 104 | - $boolResponse = $stmt->execute(); |
|
| 104 | + $boolResponse = $stmt->execute(); |
|
| 105 | 105 | |
| 106 | - if ($boolResponse) { |
|
| 107 | - return true; |
|
| 108 | - } |
|
| 109 | - return false; |
|
| 106 | + if ($boolResponse) { |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 109 | + return false; |
|
| 110 | 110 | |
| 111 | - throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
| 112 | - } |
|
| 111 | + throw NoRecordUpdateException::checkNoRecordUpdateException("Record not updated successfully"); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * This method retrieves record from a table |
@@ -121,22 +121,22 @@ discard block |
||
| 121 | 121 | $tableData = []; |
| 122 | 122 | |
| 123 | 123 | if (is_null($dbConn)) { |
| 124 | - $dbConn = new DatabaseConnection(); |
|
| 124 | + $dbConn = new DatabaseConnection(); |
|
| 125 | 125 | } |
| 126 | 126 | $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
| 127 | 127 | |
| 128 | 128 | try { |
| 129 | - $stmt = $dbConn->prepare($sql); |
|
| 130 | - $stmt->bindValue(':table', $tableName); |
|
| 131 | - $stmt->bindValue(':id', $id); |
|
| 132 | - $stmt->execute(); |
|
| 129 | + $stmt = $dbConn->prepare($sql); |
|
| 130 | + $stmt->bindValue(':table', $tableName); |
|
| 131 | + $stmt->bindValue(':id', $id); |
|
| 132 | + $stmt->execute(); |
|
| 133 | 133 | } catch (PDOException $e) { |
| 134 | - return $e->getMessage(); |
|
| 134 | + return $e->getMessage(); |
|
| 135 | 135 | } |
| 136 | 136 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 137 | 137 | |
| 138 | 138 | foreach($results as $result) { |
| 139 | - array_push($tableData, $result); |
|
| 139 | + array_push($tableData, $result); |
|
| 140 | 140 | } |
| 141 | 141 | return $tableData; |
| 142 | 142 | } |
@@ -148,20 +148,20 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public static function delete($id, $tableName, $dbConn = Null) |
| 150 | 150 | { |
| 151 | - if (is_null($dbConn)) { |
|
| 152 | - $dbConn = new DatabaseConnection(); |
|
| 153 | - } |
|
| 151 | + if (is_null($dbConn)) { |
|
| 152 | + $dbConn = new DatabaseConnection(); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id; |
|
| 155 | + $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id; |
|
| 156 | 156 | |
| 157 | - $boolResponse = $dbConn->exec($sql); |
|
| 157 | + $boolResponse = $dbConn->exec($sql); |
|
| 158 | 158 | |
| 159 | - if ($boolResponse) { |
|
| 159 | + if ($boolResponse) { |
|
| 160 | 160 | |
| 161 | - return true; |
|
| 162 | - } |
|
| 161 | + return true; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - throw NoRecordDeletionException::checkNoRecordDeleteException("Record not deleted successfully"); |
|
| 164 | + throw NoRecordDeletionException::checkNoRecordDeleteException("Record not deleted successfully"); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -172,13 +172,13 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public static function checkIfMagicSetterContainsIsSameAsClassModel(array $tableColumn, array $userSetterArray) |
| 174 | 174 | { |
| 175 | - $unexpectedFields = []; |
|
| 176 | - foreach ($userSetterArray as $key => $val) { |
|
| 177 | - if (!in_array($key,$tableColumn)) { |
|
| 178 | - $unexpectedFields[] = $key; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - return $unexpectedFields; |
|
| 175 | + $unexpectedFields = []; |
|
| 176 | + foreach ($userSetterArray as $key => $val) { |
|
| 177 | + if (!in_array($key,$tableColumn)) { |
|
| 178 | + $unexpectedFields[] = $key; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + return $unexpectedFields; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function prepareUpdateQuery($sql) |
| 190 | 190 | { |
| 191 | - $splittedQuery = explode(",",$sql); |
|
| 192 | - array_pop($splittedQuery); |
|
| 193 | - $mergeData = implode(",",$splittedQuery); |
|
| 194 | - return $mergeData; |
|
| 191 | + $splittedQuery = explode(",",$sql); |
|
| 192 | + array_pop($splittedQuery); |
|
| 193 | + $mergeData = implode(",",$splittedQuery); |
|
| 194 | + return $mergeData; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -203,21 +203,21 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | public function findAndWhere($params, $tableName, $dbConn = Null) |
| 205 | 205 | { |
| 206 | - if (is_null($dbConn)) { |
|
| 207 | - $dbConn = $this->dbConnection; |
|
| 208 | - } |
|
| 209 | - if (is_array($params) && !empty($params)) { |
|
| 210 | - $sql = "SELECT * FROM ".$tableName; |
|
| 211 | - foreach ($params as $key => $val) { |
|
| 212 | - $sql .= " WHERE `$key` = '$val'"; |
|
| 213 | - } |
|
| 214 | - $statement = $dbConn->prepare($sql); |
|
| 215 | - $statement->execute(); |
|
| 216 | - $returnedRowNumbers = $statement->rowCount(); |
|
| 206 | + if (is_null($dbConn)) { |
|
| 207 | + $dbConn = $this->dbConnection; |
|
| 208 | + } |
|
| 209 | + if (is_array($params) && !empty($params)) { |
|
| 210 | + $sql = "SELECT * FROM ".$tableName; |
|
| 211 | + foreach ($params as $key => $val) { |
|
| 212 | + $sql .= " WHERE `$key` = '$val'"; |
|
| 213 | + } |
|
| 214 | + $statement = $dbConn->prepare($sql); |
|
| 215 | + $statement->execute(); |
|
| 216 | + $returnedRowNumbers = $statement->rowCount(); |
|
| 217 | 217 | |
| 218 | - return $returnedRowNumbers ? true : false; |
|
| 219 | - } |
|
| 220 | - throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
|
| 218 | + return $returnedRowNumbers ? true : false; |
|
| 219 | + } |
|
| 220 | + throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -227,22 +227,22 @@ discard block |
||
| 227 | 227 | * @return array |
| 228 | 228 | */ |
| 229 | 229 | public function getColumnNames($table, $dbConn = Null) { |
| 230 | - $tableFields = []; |
|
| 230 | + $tableFields = []; |
|
| 231 | 231 | |
| 232 | - if (is_null($dbConn)) { |
|
| 233 | - $dbConn = $this->dbConnection; |
|
| 234 | - } |
|
| 235 | - $sql = "SHOW COLUMNS FROM ".$table; |
|
| 232 | + if (is_null($dbConn)) { |
|
| 233 | + $dbConn = $this->dbConnection; |
|
| 234 | + } |
|
| 235 | + $sql = "SHOW COLUMNS FROM ".$table; |
|
| 236 | 236 | |
| 237 | - $stmt = $dbConn->prepare($sql); |
|
| 238 | - $stmt->bindValue(':table', $table, PDO::PARAM_STR); |
|
| 239 | - $stmt->execute(); |
|
| 240 | - $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 237 | + $stmt = $dbConn->prepare($sql); |
|
| 238 | + $stmt->bindValue(':table', $table, PDO::PARAM_STR); |
|
| 239 | + $stmt->execute(); |
|
| 240 | + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 241 | 241 | |
| 242 | - foreach($results as $result) { |
|
| 243 | - array_push($tableFields, $result['Field']); |
|
| 244 | - } |
|
| 245 | - return $tableFields; |
|
| 242 | + foreach($results as $result) { |
|
| 243 | + array_push($tableFields, $result['Field']); |
|
| 244 | + } |
|
| 245 | + return $tableFields; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | } |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function create($associative1DArray, $tableName, $dbConn = Null) { |
| 44 | 44 | $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
| 45 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray); |
|
| 45 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
|
| 46 | 46 | if (count($unexpectedFields) > 0) { |
| 47 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as table field"); |
|
| 47 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as table field"); |
|
| 48 | 48 | } |
| 49 | 49 | unset($associative1DArray[0]); |
| 50 | 50 | if (is_null($dbConn)) { |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | private function insertRecord($dbConn, $tableName, $associative1DArray) { |
| 57 | 57 | $insertQuery = 'INSERT INTO '.$tableName; |
| 58 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
| 58 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
| 59 | 59 | foreach ($associative1DArray as $field => $value) { |
| 60 | 60 | $FormValues[] = "'".trim(addslashes($value))."'"; |
| 61 | 61 | } |
| 62 | 62 | $splittedTableValues = implode(',', $FormValues); |
| 63 | - $insertQuery.= ' ('.$TableValues.')'; |
|
| 64 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
| 63 | + $insertQuery .= ' ('.$TableValues.')'; |
|
| 64 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
| 65 | 65 | $executeQuery = $dbConn->exec($insertQuery); |
| 66 | 66 | |
| 67 | 67 | if ($executeQuery) { |
@@ -85,12 +85,12 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | $updateSql = "UPDATE `$tableName` SET "; |
| 87 | 87 | unset($associative1DArray['id']); |
| 88 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
| 88 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
| 89 | 89 | |
| 90 | 90 | if (count($unexpectedFields) > 0) { |
| 91 | 91 | throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as table field"); |
| 92 | 92 | } |
| 93 | - foreach($associative1DArray as $field => $value) { |
|
| 93 | + foreach ($associative1DArray as $field => $value) { |
|
| 94 | 94 | $sql .= "`$field` = '$value'".","; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | if (is_null($dbConn)) { |
| 124 | 124 | $dbConn = new DatabaseConnection(); |
| 125 | 125 | } |
| 126 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
| 126 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
| 127 | 127 | |
| 128 | 128 | try { |
| 129 | 129 | $stmt = $dbConn->prepare($sql); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 137 | 137 | |
| 138 | - foreach($results as $result) { |
|
| 138 | + foreach ($results as $result) { |
|
| 139 | 139 | array_push($tableData, $result); |
| 140 | 140 | } |
| 141 | 141 | return $tableData; |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | { |
| 175 | 175 | $unexpectedFields = []; |
| 176 | 176 | foreach ($userSetterArray as $key => $val) { |
| 177 | - if (!in_array($key,$tableColumn)) { |
|
| 177 | + if (!in_array($key, $tableColumn)) { |
|
| 178 | 178 | $unexpectedFields[] = $key; |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function prepareUpdateQuery($sql) |
| 190 | 190 | { |
| 191 | - $splittedQuery = explode(",",$sql); |
|
| 191 | + $splittedQuery = explode(",", $sql); |
|
| 192 | 192 | array_pop($splittedQuery); |
| 193 | - $mergeData = implode(",",$splittedQuery); |
|
| 193 | + $mergeData = implode(",", $splittedQuery); |
|
| 194 | 194 | return $mergeData; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $statement->execute(); |
| 216 | 216 | $returnedRowNumbers = $statement->rowCount(); |
| 217 | 217 | |
| 218 | - return $returnedRowNumbers ? true : false; |
|
| 218 | + return $returnedRowNumbers ? true : false; |
|
| 219 | 219 | } |
| 220 | 220 | throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
| 221 | 221 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | $stmt->execute(); |
| 240 | 240 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 241 | 241 | |
| 242 | - foreach($results as $result) { |
|
| 242 | + foreach ($results as $result) { |
|
| 243 | 243 | array_push($tableFields, $result['Field']); |
| 244 | 244 | } |
| 245 | 245 | return $tableFields; |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | public static function reportUnknownTableField($unExpectedFields, $message) |
| 16 | 16 | { |
| 17 | - $fields = implode(", ",$unExpectedFields); |
|
| 17 | + $fields = implode(", ", $unExpectedFields); |
|
| 18 | 18 | |
| 19 | 19 | //var_dump($fields); |
| 20 | 20 | |
@@ -12,8 +12,8 @@ |
||
| 12 | 12 | |
| 13 | 13 | class NoRecordDeletionException extends Exception |
| 14 | 14 | { |
| 15 | - public static function checkNoRecordDeleteException($message) |
|
| 16 | - { |
|
| 17 | - return new static($message); |
|
| 18 | - } |
|
| 15 | + public static function checkNoRecordDeleteException($message) |
|
| 16 | + { |
|
| 17 | + return new static($message); |
|
| 18 | + } |
|
| 19 | 19 | } |
@@ -74,14 +74,14 @@ |
||
| 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) { |