@@ -72,17 +72,17 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Assign an empty array to force a validation error for empty models |
| 75 | - if(empty($data)) { |
|
| 75 | + if (empty($data)) { |
|
| 76 | 76 | $data = [[]]; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | Db::getDriver()->beginTransaction(); |
| 80 | 80 | |
| 81 | - foreach($data as $i => $datum) { |
|
| 81 | + foreach ($data as $i => $datum) { |
|
| 82 | 82 | $status = $this->saveRecord($datum, $primaryKey); |
| 83 | 83 | $data[$i] = $datum; |
| 84 | 84 | |
| 85 | - if(!$status['success']) { |
|
| 85 | + if (!$status['success']) { |
|
| 86 | 86 | $succesful = false; |
| 87 | 87 | $invalidFields[$i] = $status['invalid_fields']; |
| 88 | 88 | Db::getDriver()->rollback(); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if($succesful) { |
|
| 93 | + if ($succesful) { |
|
| 94 | 94 | Db::getDriver()->commit(); |
| 95 | 95 | } else { |
| 96 | 96 | $this->assignValue($this->invalidFields, $invalidFields); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $this->wrapper->setData($record); |
| 124 | 124 | |
| 125 | 125 | // Run preUpdate or preSave callbacks on models and behaviours |
| 126 | - if($pkSet) { |
|
| 126 | + if ($pkSet) { |
|
| 127 | 127 | $this->wrapper->preUpdateCallback(); |
| 128 | 128 | $record = $this->wrapper->getData(); |
| 129 | 129 | $record = reset($record) === false ? [] : reset($record); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | // Exit if data is invalid |
| 145 | - if($validity !== true) { |
|
| 145 | + if ($validity !== true) { |
|
| 146 | 146 | $status['invalid_fields'] = $validity; |
| 147 | 147 | $status['success'] = false; |
| 148 | 148 | return $status; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $this->wrapper->setData($record); |
| 153 | 153 | |
| 154 | 154 | // Update or save the data and run post callbacks |
| 155 | - if($pkSet) { |
|
| 155 | + if ($pkSet) { |
|
| 156 | 156 | $this->adapter->update($record); |
| 157 | 157 | $this->wrapper->postUpdateCallback(); |
| 158 | 158 | $this->runBehaviours('postUpdateCallback', [$record]); |
@@ -177,15 +177,15 @@ discard block |
||
| 177 | 177 | ['model' => $this->wrapper, 'mode' => $mode] |
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - if(!$validator->validate($data)) { |
|
| 180 | + if (!$validator->validate($data)) { |
|
| 181 | 181 | $valid = false; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if($valid) { |
|
| 184 | + if ($valid) { |
|
| 185 | 185 | $valid = $this->wrapper->onValidate(); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if($valid === false) { |
|
| 188 | + if ($valid === false) { |
|
| 189 | 189 | $valid = $validator->getInvalidFields(); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -195,17 +195,17 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | private function isPrimaryKeySet($primaryKey, $data) |
| 197 | 197 | { |
| 198 | - if(is_string($primaryKey)) { |
|
| 199 | - if(isset($data[$primaryKey])) |
|
| 198 | + if (is_string($primaryKey)) { |
|
| 199 | + if (isset($data[$primaryKey])) |
|
| 200 | 200 | { |
| 201 | 201 | return true; |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | - foreach($primaryKey as $keyField) { |
|
| 205 | - if(!isset($data[$keyField])) { |
|
| 204 | + foreach ($primaryKey as $keyField) { |
|
| 205 | + if (!isset($data[$keyField])) { |
|
| 206 | 206 | break; |
| 207 | 207 | } |
| 208 | - if($data[$keyField] !== '' && $data[$keyField] !== null) { |
|
| 208 | + if ($data[$keyField] !== '' && $data[$keyField] !== null) { |
|
| 209 | 209 | return true; |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | private function assignValue(&$property, $value) |
| 216 | 216 | { |
| 217 | - if($this->hasMultipleData) { |
|
| 217 | + if ($this->hasMultipleData) { |
|
| 218 | 218 | $property = $value; |
| 219 | 219 | } else { |
| 220 | 220 | $property = $value[0]; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | |
| 234 | 234 | public function isItemDeletable($primaryKey, $data) |
| 235 | 235 | { |
| 236 | - if($this->isPrimaryKeySet($primaryKey, $data)) { |
|
| 236 | + if ($this->isPrimaryKeySet($primaryKey, $data)) { |
|
| 237 | 237 | return true; |
| 238 | 238 | } else { |
| 239 | 239 | return false; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | private function runBehaviours($event, $args) |
| 244 | 244 | { |
| 245 | - foreach($this->wrapper->getBehaviours() as $behaviour) { |
|
| 245 | + foreach ($this->wrapper->getBehaviours() as $behaviour) { |
|
| 246 | 246 | $args[0] = call_user_func_array([$behaviour, $event], $args); |
| 247 | 247 | } |
| 248 | 248 | return $args[0]; |