@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ->filterBy($this->options['junction_local_key'], $data[$this->options['local_key']]) |
47 | 47 | ->fetch(); |
48 | 48 | $foreignKeys = []; |
49 | - foreach($filter->toArray() as $foreignItem) { |
|
49 | + foreach ($filter->toArray() as $foreignItem) { |
|
50 | 50 | $foreignKeys[] = $foreignItem[$this->options['junction_foreign_key']]; |
51 | 51 | } |
52 | 52 | $query = (new \ntentan\nibii\QueryParameters($this->getModelInstance())) |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | public function runSetup() |
58 | 58 | { |
59 | - if(isset($this->options['through'])) { |
|
59 | + if (isset($this->options['through'])) { |
|
60 | 60 | $junctionModelName = $this->options['through']; |
61 | 61 | } else { |
62 | 62 | $junctionModelName = Nibii::joinModels($this->setupName, $this->options['model']); |
@@ -64,22 +64,22 @@ discard block |
||
64 | 64 | $this->options['junction_model'] = $junctionModelName; |
65 | 65 | |
66 | 66 | $foreignModel = Nibii::load($this->options['model']); |
67 | - if($this->options['foreign_key'] == null) { |
|
67 | + if ($this->options['foreign_key'] == null) { |
|
68 | 68 | $this->options['foreign_key'] = $foreignModel->getDescription()->getPrimaryKey()[0]; |
69 | 69 | } |
70 | 70 | |
71 | - if($this->options['local_key'] == null) { |
|
71 | + if ($this->options['local_key'] == null) { |
|
72 | 72 | $this->options['local_key'] = $this->setupPrimaryKey[0]; |
73 | 73 | } |
74 | 74 | |
75 | - if(!isset($this->options['junction_local_key'])) { |
|
75 | + if (!isset($this->options['junction_local_key'])) { |
|
76 | 76 | $this->options['junction_local_key'] = |
77 | - Text::singularize($this->setupTable) . '_id'; |
|
77 | + Text::singularize($this->setupTable).'_id'; |
|
78 | 78 | } |
79 | 79 | |
80 | - if(!isset($this->options['junction_foreign_key'])) { |
|
80 | + if (!isset($this->options['junction_foreign_key'])) { |
|
81 | 81 | $this->options['junction_foreign_key'] = |
82 | - Text::singularize($foreignModel->getTable()) . '_id'; |
|
82 | + Text::singularize($foreignModel->getTable()).'_id'; |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
@@ -45,11 +45,11 @@ |
||
45 | 45 | public function runSetup() |
46 | 46 | { |
47 | 47 | $model = (new \ReflectionClass(Nibii::getClassName($this->options['model'], self::BELONGS_TO)))->newInstance(); |
48 | - if($this->options['foreign_key'] == null) { |
|
48 | + if ($this->options['foreign_key'] == null) { |
|
49 | 49 | $this->options['foreign_key'] = $model->getDescription()->getPrimaryKey()[0]; |
50 | 50 | } |
51 | - if($this->options['local_key'] == null) { |
|
52 | - $this->options['local_key'] = Text::singularize($model->getTable()) . '_id'; |
|
51 | + if ($this->options['local_key'] == null) { |
|
52 | + $this->options['local_key'] = Text::singularize($model->getTable()).'_id'; |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | } |
@@ -42,10 +42,10 @@ |
||
42 | 42 | |
43 | 43 | public function runSetup() |
44 | 44 | { |
45 | - if($this->options['foreign_key'] == null) { |
|
46 | - $this->options['foreign_key'] = Text::singularize($this->setupTable) . '_id'; |
|
45 | + if ($this->options['foreign_key'] == null) { |
|
46 | + $this->options['foreign_key'] = Text::singularize($this->setupTable).'_id'; |
|
47 | 47 | } |
48 | - if($this->options['local_key'] == null) { |
|
48 | + if ($this->options['local_key'] == null) { |
|
49 | 49 | $this->options['local_key'] = $this->setupPrimaryKey[0]; |
50 | 50 | } |
51 | 51 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | public function getSorts() |
82 | 82 | { |
83 | - return count($this->sorts) ? " ORDER BY " . implode(", ", $this->sorts) : null; |
|
83 | + return count($this->sorts) ? " ORDER BY ".implode(", ", $this->sorts) : null; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public function addFilter($field, $values = []) |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | if ($numValues === 1) { |
93 | 93 | $key = "filter_{$startIndex}"; |
94 | - if($values[0] === null) { |
|
94 | + if ($values[0] === null) { |
|
95 | 95 | $this->whereClause .= "{$field} is NULL"; |
96 | 96 | } else { |
97 | 97 | $this->whereClause .= "{$field} = :$key"; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $this->whereClause .= "{$field} IN ("; |
102 | 102 | $comma = ''; |
103 | 103 | for ($i = 0; $i < $numValues; $i++) { |
104 | - $key = "filter_" . ($startIndex + $i); |
|
104 | + $key = "filter_".($startIndex + $i); |
|
105 | 105 | $this->whereClause .= "$comma:$key"; |
106 | 106 | $this->boundData[$key] = $values[$i]; |
107 | 107 | $comma = ' ,'; |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | public function run($field, $data) |
46 | 46 | { |
47 | 47 | $test = []; |
48 | - foreach($field['name'] as $name) { |
|
48 | + foreach ($field['name'] as $name) { |
|
49 | 49 | $test[$name] = isset($data[$name]) ? $data[$name] : null; |
50 | 50 | } |
51 | 51 | |
52 | - if($this->mode == \ntentan\nibii\DataOperations::MODE_UPDATE) { |
|
52 | + if ($this->mode == \ntentan\nibii\DataOperations::MODE_UPDATE) { |
|
53 | 53 | $primaryKeyFields = $this->model->getDescription()->getPrimaryKey(); |
54 | 54 | $keys = []; |
55 | - foreach($primaryKeyFields as $name) { |
|
55 | + foreach ($primaryKeyFields as $name) { |
|
56 | 56 | $keys[$name] = $data[$name]; |
57 | 57 | } |
58 | 58 | $testItem = $this->model->createNew()->fetchFirst($test); |
59 | 59 | $intersection = array_intersect($testItem->toArray(), $keys); |
60 | - if(!empty($intersection)) { |
|
60 | + if (!empty($intersection)) { |
|
61 | 61 | return true; |
62 | 62 | } |
63 | 63 | } else { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | return $this->evaluateResult( |
68 | 68 | $field, |
69 | 69 | $testItem->count() === 0, |
70 | - "The value of " . implode(', ', $field['name']) . " must be unique" |
|
70 | + "The value of ".implode(', ', $field['name'])." must be unique" |
|
71 | 71 | ); |
72 | 72 | } |
73 | 73 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $this->getToken(); |
61 | 61 | $expression = $this->parseExpression(); |
62 | 62 | if ($this->token !== false) { |
63 | - throw new FilterCompilerException("Unexpected '" . $this->token . "' in filter [$filter]"); |
|
63 | + throw new FilterCompilerException("Unexpected '".$this->token."' in filter [$filter]"); |
|
64 | 64 | } |
65 | 65 | $parsed = $this->renderExpression($expression); |
66 | 66 | return $parsed; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | private function renderExpression($expression) |
70 | 70 | { |
71 | 71 | if (is_array($expression)) { |
72 | - $expression = $this->renderExpression($expression['left']) . " {$expression['opr']} " . $this->renderExpression($expression['right']); |
|
72 | + $expression = $this->renderExpression($expression['left'])." {$expression['opr']} ".$this->renderExpression($expression['right']); |
|
73 | 73 | } |
74 | 74 | return $expression; |
75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $tokens = [$tokens]; |
81 | 81 | } |
82 | 82 | if (array_search($this->lookahead, $tokens) === false) { |
83 | - throw new FilterCompilerException("Expected " . implode(' or ', $tokens) . " but found " . $this->lookahead); |
|
83 | + throw new FilterCompilerException("Expected ".implode(' or ', $tokens)." but found ".$this->lookahead); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | private function returnPositionTag() |
174 | 174 | { |
175 | - return ":filter_bind_" . (++$this->numPositions); |
|
175 | + return ":filter_bind_".(++$this->numPositions); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | private function parseObracket() |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | 'obracket' => 'parseObracket' |
196 | 196 | ]; |
197 | 197 | |
198 | - if(isset($methods[$this->lookahead])) { |
|
198 | + if (isset($methods[$this->lookahead])) { |
|
199 | 199 | $method = $methods[$this->lookahead]; |
200 | 200 | $return = $this->$method(); |
201 | 201 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | if ($this->token === false && strlen($this->filter) > 0) { |
257 | - throw new FilterCompilerException("Unexpected character [" . $this->filter[0] . "] begining " . $this->filter . "."); |
|
257 | + throw new FilterCompilerException("Unexpected character [".$this->filter[0]."] begining ".$this->filter."."); |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | |
268 | 268 | public function rewriteBoundData($data) { |
269 | 269 | $rewritten = []; |
270 | - foreach($data as $key => $value) { |
|
271 | - if(is_numeric($key)) |
|
270 | + foreach ($data as $key => $value) { |
|
271 | + if (is_numeric($key)) |
|
272 | 272 | { |
273 | - $rewritten["filter_bind_" . ($key + 1)] = $value; |
|
273 | + $rewritten["filter_bind_".($key + 1)] = $value; |
|
274 | 274 | } |
275 | 275 | else |
276 | 276 | { |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $this->table = Nibii::getModelTable($this); |
51 | 51 | $this->adapter = $adapter; |
52 | - foreach($this->behaviours as $behaviour) { |
|
52 | + foreach ($this->behaviours as $behaviour) { |
|
53 | 53 | $behaviourInstance = $this->getComponentInstance($behaviour); |
54 | 54 | $behaviourInstance->setModel($this); |
55 | 55 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function getDescription() |
77 | 77 | { |
78 | 78 | return Cache::read( |
79 | - (new \ReflectionClass($this))->getName() . '::desc', |
|
79 | + (new \ReflectionClass($this))->getName().'::desc', |
|
80 | 80 | function() |
81 | 81 | { |
82 | 82 | return new ModelDescription($this); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | private function retrieveItem($key) |
97 | 97 | { |
98 | 98 | $relationships = $this->getDescription()->getRelationships(); |
99 | - if(isset($relationships[$key])) { |
|
99 | + if (isset($relationships[$key])) { |
|
100 | 100 | return $this->fetchRelatedFields($relationships[$key]); |
101 | 101 | } else { |
102 | 102 | return isset($this->modelData[$key]) ? $this->modelData[$key] : null; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function __call($name, $arguments) |
123 | 123 | { |
124 | - if($this->dynamicOperations === null) { |
|
124 | + if ($this->dynamicOperations === null) { |
|
125 | 125 | $this->dynamicOperations = new Operations($this, InjectionContainer::singleton(DriverAdapter::class)); |
126 | 126 | } |
127 | 127 | return $this->dynamicOperations->perform($name, $arguments); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
152 | 152 | { |
153 | - foreach($relationships as $name => $relationship) { |
|
153 | + foreach ($relationships as $name => $relationship) { |
|
154 | 154 | $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth); |
155 | 155 | } |
156 | 156 | return $array; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | { |
161 | 161 | $relationships = $this->getDescription()->getRelationships(); |
162 | 162 | $array = $this->modelData; |
163 | - if($depth > 0) { |
|
164 | - if($this->hasMultipleData()) { |
|
165 | - foreach($array as $i => $value) { |
|
163 | + if ($depth > 0) { |
|
164 | + if ($this->hasMultipleData()) { |
|
165 | + foreach ($array as $i => $value) { |
|
166 | 166 | $array[$i] = $this->expandArrayValue($value, $relationships, $depth - 1, $i); |
167 | 167 | } |
168 | 168 | } else { |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | private function hasMultipleData() |
188 | 188 | { |
189 | - if(count($this->modelData) > 0) { |
|
189 | + if (count($this->modelData) > 0) { |
|
190 | 190 | return is_numeric(array_keys($this->modelData)[0]); |
191 | 191 | } else { |
192 | 192 | return false; |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | { |
198 | 198 | $data = []; |
199 | 199 | |
200 | - if(count($this->modelData) == 0) { |
|
200 | + if (count($this->modelData) == 0) { |
|
201 | 201 | $data = $this->modelData; |
202 | - } else if($this->hasMultipleData()) { |
|
202 | + } else if ($this->hasMultipleData()) { |
|
203 | 203 | $data = $this->modelData; |
204 | - } else if(count($this->modelData) > 0) { |
|
204 | + } else if (count($this->modelData) > 0) { |
|
205 | 205 | $data[] = $this->modelData; |
206 | 206 | } |
207 | 207 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | public function mergeData($data) |
218 | 218 | { |
219 | - foreach($data as $key => $value) { |
|
219 | + foreach ($data as $key => $value) { |
|
220 | 220 | $this->modelData[$key] = $value; |
221 | 221 | } |
222 | 222 | $this->dataSet = true; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | private function wrap($offset) |
251 | 251 | { |
252 | - if(isset($this->modelData[$offset])) { |
|
252 | + if (isset($this->modelData[$offset])) { |
|
253 | 253 | $newInstance = $this->createNew(); |
254 | 254 | $newInstance->setData($this->modelData[$offset]); |
255 | 255 | return $newInstance; |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | |
301 | 301 | private function fetchRelatedFields($relationship, $index = null) |
302 | 302 | { |
303 | - if($index === null) { |
|
303 | + if ($index === null) { |
|
304 | 304 | $data = $this->modelData; |
305 | 305 | } else { |
306 | 306 | $data = $this->modelData[$index]; |
307 | 307 | } |
308 | 308 | $model = $relationship->getModelInstance(); |
309 | - if(empty($data)) { |
|
309 | + if (empty($data)) { |
|
310 | 310 | return $model; |
311 | 311 | } else { |
312 | 312 | return $model->fetch($relationship->getQuery($data)); |
@@ -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]; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | { |
32 | 32 | $arrayed = explode('\\', $className); |
33 | 33 | $class = array_pop($arrayed); |
34 | - if($arrayed[0] == '') { |
|
34 | + if ($arrayed[0] == '') { |
|
35 | 35 | array_shift($arrayed); |
36 | 36 | } |
37 | 37 | return ['class' => $class, 'namespace' => implode('\\', $arrayed)]; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | { |
42 | 42 | $classA = $this->getClassFileDetails($classA); |
43 | 43 | $classB = $this->getClassFileDetails($classB); |
44 | - if($classA['namespace'] != $classB['namespace']) { |
|
44 | + if ($classA['namespace'] != $classB['namespace']) { |
|
45 | 45 | throw new NibiiException( |
46 | 46 | "Cannot automatically join two classes of different " |
47 | 47 | . "namespaces. Please provide a model joiner or " |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | $classes = [$classA['class'], $classB['class']]; |
52 | 52 | sort($classes); |
53 | - return "{$classA['namespace']}\\" . implode('', $classes); |
|
53 | + return "{$classA['namespace']}\\".implode('', $classes); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public function getTableName($instance) |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | public static function getDriverAdapterClassName() |
64 | 64 | { |
65 | 65 | $driver = Config::get('ntentan:db.driver', false); |
66 | - if($driver) { |
|
67 | - return __NAMESPACE__ . '\adapters\\' . Text::ucamelize(Config::get('ntentan:db.driver')) . 'Adapter'; |
|
66 | + if ($driver) { |
|
67 | + return __NAMESPACE__.'\adapters\\'.Text::ucamelize(Config::get('ntentan:db.driver')).'Adapter'; |
|
68 | 68 | } |
69 | 69 | throw new NibiiException("Please specify a driver"); |
70 | 70 | } |