@@ -22,6 +22,7 @@ discard block |
||
| 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) |
| 27 | 28 | { |
@@ -37,6 +38,7 @@ discard block |
||
| 37 | 38 | /** |
| 38 | 39 | * This method create a record and store it in a table row |
| 39 | 40 | * @params associative array, string tablename |
| 41 | + * @param string|false $tableName |
|
| 40 | 42 | * @return boolean true or false |
| 41 | 43 | */ |
| 42 | 44 | public function create($associative1DArray, $tableName, $dbConn = Null) |
@@ -80,6 +82,10 @@ discard block |
||
| 80 | 82 | * @params: $updateParams, $tableName, $associative1DArray |
| 81 | 83 | * @return boolean true or false |
| 82 | 84 | */ |
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param string|false $tableName |
|
| 88 | + */ |
|
| 83 | 89 | public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) |
| 84 | 90 | { |
| 85 | 91 | $counter = 0; |
@@ -124,6 +130,7 @@ discard block |
||
| 124 | 130 | /** |
| 125 | 131 | * This method retrieves record from a table |
| 126 | 132 | * @params int id, string tableName |
| 133 | + * @param string|false $tableName |
|
| 127 | 134 | * @return array |
| 128 | 135 | */ |
| 129 | 136 | public static function read($id, $tableName, $dbConn = Null) |
@@ -162,6 +169,7 @@ discard block |
||
| 162 | 169 | /** |
| 163 | 170 | * This method deletes a record from a table row |
| 164 | 171 | * @params int id, string tableName |
| 172 | + * @param string|false $tableName |
|
| 165 | 173 | * @return boolean true or false |
| 166 | 174 | */ |
| 167 | 175 | public static function delete($id, $tableName, $dbConn = Null) |
@@ -204,7 +212,7 @@ discard block |
||
| 204 | 212 | |
| 205 | 213 | /** |
| 206 | 214 | * This method returns sql query |
| 207 | - * @param $sql |
|
| 215 | + * @param string $sql |
|
| 208 | 216 | * @return string |
| 209 | 217 | */ |
| 210 | 218 | private function prepareUpdateQuery($sql) |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use Laztopaz\potatoORM\TableFieldUndefinedException; |
| 14 | 14 | use Laztopaz\potatoORM\EmptyArrayException; |
| 15 | 15 | |
| 16 | -class DatabaseHandler { |
|
| 16 | +class DatabaseHandler { |
|
| 17 | 17 | |
| 18 | 18 | private |
| 19 | 19 | $tableFields, |
@@ -41,11 +41,11 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function create($associative1DArray, $tableName, $dbConn = Null) |
| 43 | 43 | { |
| 44 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields,$associative1DArray); |
|
| 44 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields, $associative1DArray); |
|
| 45 | 45 | |
| 46 | 46 | if (count($unexpectedFields) > 0) |
| 47 | 47 | { |
| 48 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); |
|
| 48 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | unset($this->tableFields[0]); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | $insertQuery = 'INSERT INTO '.$tableName; |
| 60 | 60 | |
| 61 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
| 61 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
| 62 | 62 | |
| 63 | 63 | foreach ($associative1DArray as $field => $value) { |
| 64 | 64 | |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | $splittedTableValues = implode(',', $FormValues); |
| 68 | 68 | |
| 69 | - $insertQuery.= ' ('.$TableValues.')'; |
|
| 69 | + $insertQuery .= ' ('.$TableValues.')'; |
|
| 70 | 70 | |
| 71 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
| 71 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
| 72 | 72 | |
| 73 | 73 | $executeQuery = $dbConn->exec($insertQuery); |
| 74 | 74 | |
| 75 | - return $executeQuery ? : false; |
|
| 75 | + return $executeQuery ?: false; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /* |
@@ -95,19 +95,19 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | unset($associative1DArray['id']); |
| 97 | 97 | |
| 98 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields,$associative1DArray); |
|
| 98 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields, $associative1DArray); |
|
| 99 | 99 | |
| 100 | 100 | if (count($unexpectedFields) > 0) { |
| 101 | 101 | |
| 102 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); |
|
| 102 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - foreach($associative1DArray as $field => $value) |
|
| 105 | + foreach ($associative1DArray as $field => $value) |
|
| 106 | 106 | { |
| 107 | - $sql.= "`$field` = '$value'".","; |
|
| 107 | + $sql .= "`$field` = '$value'".","; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $updateSql.= $this->prepareUpdateQuery($sql); |
|
| 110 | + $updateSql .= $this->prepareUpdateQuery($sql); |
|
| 111 | 111 | |
| 112 | 112 | foreach ($updateParams as $key => $val) { |
| 113 | 113 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $boolResponse = $stmt->execute(); |
| 120 | 120 | |
| 121 | - return $boolResponse ? : false; |
|
| 121 | + return $boolResponse ?: false; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $dbConn = $dhl->connect(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
| 140 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
| 141 | 141 | |
| 142 | 142 | try { |
| 143 | 143 | $stmt = $dbConn->prepare($sql); |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 153 | 153 | |
| 154 | - foreach($results as $result) { |
|
| 154 | + foreach ($results as $result) { |
|
| 155 | 155 | |
| 156 | 156 | array_push($tableData, $result); |
| 157 | 157 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $boolResponse = $dbConn->exec($sql); |
| 180 | 180 | |
| 181 | - return $boolResponse ? : false; |
|
| 181 | + return $boolResponse ?: false; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | foreach ($userSetterArray as $key => $val) |
| 195 | 195 | { |
| 196 | - if (!in_array($key,$tableColumn)) { |
|
| 196 | + if (!in_array($key, $tableColumn)) { |
|
| 197 | 197 | |
| 198 | 198 | $unexpectedFields[] = $key; |
| 199 | 199 | } |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | private function prepareUpdateQuery($sql) |
| 211 | 211 | { |
| 212 | - $splittedQuery = explode(",",$sql); |
|
| 212 | + $splittedQuery = explode(",", $sql); |
|
| 213 | 213 | |
| 214 | 214 | array_pop($splittedQuery); |
| 215 | 215 | |
| 216 | - $mergeData = implode(",",$splittedQuery); |
|
| 216 | + $mergeData = implode(",", $splittedQuery); |
|
| 217 | 217 | |
| 218 | 218 | return $mergeData; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - public function findAndWhere(array $params,$tableName) |
|
| 221 | + public function findAndWhere(array $params, $tableName) |
|
| 222 | 222 | { |
| 223 | 223 | if (is_array($params) && !empty($params)) { |
| 224 | 224 | |