@@ -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 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | return Nibii::getModelTable($this); |
| 53 | 53 | } |
| 54 | 54 | ); |
| 55 | - foreach($this->behaviours as $behaviour) { |
|
| 55 | + foreach ($this->behaviours as $behaviour) { |
|
| 56 | 56 | $behaviourInstance = $this->loadDependency($behaviour); |
| 57 | 57 | $behaviourInstance->setModel($this); |
| 58 | 58 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | protected function getDataAdapter() |
| 66 | 66 | { |
| 67 | - if(!$this->adapter) |
|
| 67 | + if (!$this->adapter) |
|
| 68 | 68 | { |
| 69 | 69 | $this->adapter = DriverAdapter::getDefaultInstance(); |
| 70 | 70 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | public function getDescription() |
| 79 | 79 | { |
| 80 | 80 | return Cache::read( |
| 81 | - (new \ReflectionClass($this))->getName() . '::desc', |
|
| 81 | + (new \ReflectionClass($this))->getName().'::desc', |
|
| 82 | 82 | function() |
| 83 | 83 | { |
| 84 | 84 | return new ModelDescription($this); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | private function retrieveItem($key) |
| 99 | 99 | { |
| 100 | 100 | $relationships = $this->getDescription()->getRelationships(); |
| 101 | - if(isset($relationships[$key])) { |
|
| 101 | + if (isset($relationships[$key])) { |
|
| 102 | 102 | return $this->fetchRelatedFields($relationships[$key]); |
| 103 | 103 | } else { |
| 104 | 104 | return isset($this->modelData[$key]) ? $this->modelData[$key] : null; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
| 155 | 155 | { |
| 156 | - foreach($relationships as $name => $relationship) { |
|
| 156 | + foreach ($relationships as $name => $relationship) { |
|
| 157 | 157 | $array[$name] = $this->fetchRelatedFields($relationship, $index)->toArray($depth); |
| 158 | 158 | } |
| 159 | 159 | return $array; |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $relationships = $this->getDescription()->getRelationships(); |
| 165 | 165 | $array = $this->modelData; |
| 166 | - if($depth > 0) { |
|
| 167 | - if($this->hasMultipleData()) { |
|
| 168 | - foreach($array as $i => $value) { |
|
| 166 | + if ($depth > 0) { |
|
| 167 | + if ($this->hasMultipleData()) { |
|
| 168 | + foreach ($array as $i => $value) { |
|
| 169 | 169 | $array[$i] = $this->expandArrayValue($value, $relationships, $depth - 1, $i); |
| 170 | 170 | } |
| 171 | 171 | } else { |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | private function hasMultipleData() |
| 191 | 191 | { |
| 192 | - if(count($this->modelData) > 0) { |
|
| 192 | + if (count($this->modelData) > 0) { |
|
| 193 | 193 | return is_numeric(array_keys($this->modelData)[0]); |
| 194 | 194 | } else { |
| 195 | 195 | return false; |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $data = []; |
| 202 | 202 | |
| 203 | - if(count($this->modelData) == 0) { |
|
| 203 | + if (count($this->modelData) == 0) { |
|
| 204 | 204 | $data = $this->modelData; |
| 205 | - } else if($this->hasMultipleData()) { |
|
| 205 | + } else if ($this->hasMultipleData()) { |
|
| 206 | 206 | $data = $this->modelData; |
| 207 | - } else if(count($this->modelData) > 0) { |
|
| 207 | + } else if (count($this->modelData) > 0) { |
|
| 208 | 208 | $data[] = $this->modelData; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | public function mergeData($data) |
| 221 | 221 | { |
| 222 | - foreach($data as $key => $value) { |
|
| 222 | + foreach ($data as $key => $value) { |
|
| 223 | 223 | $this->modelData[$key] = $value; |
| 224 | 224 | } |
| 225 | 225 | $this->dataSet = true; |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | private function wrap($offset) |
| 254 | 254 | { |
| 255 | - if(isset($this->modelData[$offset])) { |
|
| 255 | + if (isset($this->modelData[$offset])) { |
|
| 256 | 256 | $newInstance = $this->createNew(); |
| 257 | 257 | $newInstance->setData($this->modelData[$offset]); |
| 258 | 258 | return $newInstance; |
@@ -303,13 +303,13 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | private function fetchRelatedFields($relationship, $index = null) |
| 305 | 305 | { |
| 306 | - if($index === null) { |
|
| 306 | + if ($index === null) { |
|
| 307 | 307 | $data = $this->modelData; |
| 308 | 308 | } else { |
| 309 | 309 | $data = $this->modelData[$index]; |
| 310 | 310 | } |
| 311 | 311 | $model = $relationship->getModelInstance(); |
| 312 | - if(empty($data)) { |
|
| 312 | + if (empty($data)) { |
|
| 313 | 313 | return $model; |
| 314 | 314 | } else { |
| 315 | 315 | return $model->fetch($relationship->getQuery($data)); |
@@ -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 | { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | public function insert($record) |
| 80 | 80 | { |
| 81 | - if($this->insertQuery === null) { |
|
| 81 | + if ($this->insertQuery === null) { |
|
| 82 | 82 | $this->initInsert(); |
| 83 | 83 | } |
| 84 | 84 | return Db::getDriver()->query($this->insertQuery, $record); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function update($record) |
| 88 | 88 | { |
| 89 | - if($this->updateQuery === null) { |
|
| 89 | + if ($this->updateQuery === null) { |
|
| 90 | 90 | $this->initUpdate(); |
| 91 | 91 | } |
| 92 | 92 | return Db::getDriver()->query($this->updateQuery, $record); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | $driver = Db::getDefaultSettings()['driver']; |
| 122 | 122 | if ($driver) { |
| 123 | - $class = "\\ntentan\\nibii\\adapters\\" . Text::ucamelize($driver) . "Adapter"; |
|
| 123 | + $class = "\\ntentan\\nibii\\adapters\\".Text::ucamelize($driver)."Adapter"; |
|
| 124 | 124 | $instance = new $class(); |
| 125 | 125 | } else { |
| 126 | 126 | throw new \Exception("No datastore specified"); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | public function getClassName($default, $context) |
| 24 | 24 | { |
| 25 | - if(self::$classResolver !== null && $model[0] !== "\\") { |
|
| 25 | + if (self::$classResolver !== null && $model[0] !== "\\") { |
|
| 26 | 26 | $resolver = self::$classResolver; |
| 27 | 27 | $className = $resolver($model, $context); |
| 28 | 28 | } else { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $arrayed = explode('\\', $className); |
| 37 | 37 | $class = array_pop($arrayed); |
| 38 | - if($arrayed[0] == '') { |
|
| 38 | + if ($arrayed[0] == '') { |
|
| 39 | 39 | array_shift($arrayed); |
| 40 | 40 | } |
| 41 | 41 | return ['class' => $class, 'namespace' => implode('\\', $arrayed)]; |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $classA = $this->getClassFileDetails($classA); |
| 47 | 47 | $classB = $this->getClassFileDetails($classB); |
| 48 | - if($classA['namespace'] != $classB['namespace']) { |
|
| 48 | + if ($classA['namespace'] != $classB['namespace']) { |
|
| 49 | 49 | throw new NibiiException( |
| 50 | 50 | "Cannot automatically join two classes of different " |
| 51 | 51 | . "namespaces. Please provide a model joiner or " |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | $classes = [$classA['class'], $classB['class']]; |
| 56 | 56 | sort($classes); |
| 57 | - return "{$classA['namespace']}\\" . implode('', $classes); |
|
| 57 | + return "{$classA['namespace']}\\".implode('', $classes); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function getTableName($instance) |