@@ -237,6 +237,9 @@ |
||
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | + /** |
|
| 241 | + * @param string $event |
|
| 242 | + */ |
|
| 240 | 243 | private function runBehaviours($event, $args) |
| 241 | 244 | { |
| 242 | 245 | foreach($this->wrapper->getBehaviours() as $behaviour) { |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Assign an empty array to force a validation error for empty models |
| 74 | - if(empty($data)) { |
|
| 74 | + if (empty($data)) { |
|
| 75 | 75 | $data = [[]]; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $this->adapter->getDriver()->beginTransaction(); |
| 79 | 79 | |
| 80 | - foreach($data as $i => $datum) { |
|
| 80 | + foreach ($data as $i => $datum) { |
|
| 81 | 81 | $status = $this->saveRecord($datum, $primaryKey); |
| 82 | 82 | $data[$i] = $datum; |
| 83 | 83 | |
| 84 | - if(!$status['success']) { |
|
| 84 | + if (!$status['success']) { |
|
| 85 | 85 | $succesful = false; |
| 86 | 86 | $invalidFields[$i] = $status['invalid_fields']; |
| 87 | 87 | $this->adapter->getDriver()->rollback(); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if($succesful) { |
|
| 92 | + if ($succesful) { |
|
| 93 | 93 | //$this->assignValue($this->data, $data); |
| 94 | 94 | $this->adapter->getDriver()->commit(); |
| 95 | 95 | } else { |
@@ -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]); |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | ); |
| 180 | 180 | |
| 181 | - if(!$validator->validate($data)) { |
|
| 181 | + if (!$validator->validate($data)) { |
|
| 182 | 182 | $valid = false; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($valid === false) { |
|
| 185 | + if ($valid === false) { |
|
| 186 | 186 | $valid = $validator->getInvalidFields(); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -192,17 +192,17 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | private function isPrimaryKeySet($primaryKey, $data) |
| 194 | 194 | { |
| 195 | - if(is_string($primaryKey)) { |
|
| 196 | - if(isset($data[$primaryKey])) |
|
| 195 | + if (is_string($primaryKey)) { |
|
| 196 | + if (isset($data[$primaryKey])) |
|
| 197 | 197 | { |
| 198 | 198 | return true; |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | - foreach($primaryKey as $keyField) { |
|
| 202 | - if(!isset($data[$keyField])) { |
|
| 201 | + foreach ($primaryKey as $keyField) { |
|
| 202 | + if (!isset($data[$keyField])) { |
|
| 203 | 203 | break; |
| 204 | 204 | } |
| 205 | - if($data[$keyField] !== '' && $data[$keyField] !== null) { |
|
| 205 | + if ($data[$keyField] !== '' && $data[$keyField] !== null) { |
|
| 206 | 206 | return true; |
| 207 | 207 | } |
| 208 | 208 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | private function assignValue(&$property, $value) |
| 213 | 213 | { |
| 214 | - if($this->hasMultipleData) { |
|
| 214 | + if ($this->hasMultipleData) { |
|
| 215 | 215 | $property = $value; |
| 216 | 216 | } else { |
| 217 | 217 | $property = $value[0]; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | public function isItemDeletable($primaryKey, $data) |
| 232 | 232 | { |
| 233 | - if($this->isPrimaryKeySet($primaryKey, $data)) { |
|
| 233 | + if ($this->isPrimaryKeySet($primaryKey, $data)) { |
|
| 234 | 234 | return true; |
| 235 | 235 | } else { |
| 236 | 236 | return false; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | private function runBehaviours($event, $args) |
| 241 | 241 | { |
| 242 | - foreach($this->wrapper->getBehaviours() as $behaviour) { |
|
| 242 | + foreach ($this->wrapper->getBehaviours() as $behaviour) { |
|
| 243 | 243 | $args[0] = call_user_func_array([$behaviour, $event], $args); |
| 244 | 244 | } |
| 245 | 245 | return $args[0]; |
@@ -25,8 +25,8 @@ |
||
| 25 | 25 | |
| 26 | 26 | namespace ntentan\nibii; |
| 27 | 27 | |
| 28 | -use ntentan\utils\Utils; |
|
| 29 | 28 | use ntentan\kaikai\Cache; |
| 29 | +use ntentan\utils\Utils; |
|
| 30 | 30 | |
| 31 | 31 | class RecordWrapper implements \ArrayAccess, \Countable, \Iterator |
| 32 | 32 | { |
@@ -204,6 +204,10 @@ |
||
| 204 | 204 | return $return; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | + /** |
|
| 208 | + * @param integer $level |
|
| 209 | + * @param string $opr |
|
| 210 | + */ |
|
| 207 | 211 | private function parseRightExpression($level, $opr) |
| 208 | 212 | { |
| 209 | 213 | switch ($opr) { |
@@ -271,8 +271,7 @@ |
||
| 271 | 271 | if(is_numeric($key)) |
| 272 | 272 | { |
| 273 | 273 | $rewritten["filter_bind_" . ($key + 1)] = $value; |
| 274 | - } |
|
| 275 | - else |
|
| 274 | + } else |
|
| 276 | 275 | { |
| 277 | 276 | $rewritten[$key] = $value; |
| 278 | 277 | } |
@@ -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 | { |
@@ -45,6 +45,9 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | + /** |
|
| 49 | + * @param RecordWrapper $instance |
|
| 50 | + */ |
|
| 48 | 51 | public static function getModelTable($instance) |
| 49 | 52 | { |
| 50 | 53 | if(self::$tableResolver) { |
@@ -68,6 +71,9 @@ discard block |
||
| 68 | 71 | return $className; |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + /** |
|
| 75 | + * @param string $class |
|
| 76 | + */ |
|
| 71 | 77 | public static function getModelName($class) |
| 72 | 78 | { |
| 73 | 79 | if(self::$modelResolver) { |
@@ -6,11 +6,17 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | private $db; |
| 8 | 8 | |
| 9 | + /** |
|
| 10 | + * @param \ntentan\atiaa\Driver $driver |
|
| 11 | + */ |
|
| 9 | 12 | public function setDriver($driver) |
| 10 | 13 | { |
| 11 | 14 | $this->db = $driver; |
| 12 | 15 | } |
| 13 | 16 | |
| 17 | + /** |
|
| 18 | + * @param string $query |
|
| 19 | + */ |
|
| 14 | 20 | private function filter($query) |
| 15 | 21 | { |
| 16 | 22 | return $query; |
@@ -34,6 +40,9 @@ discard block |
||
| 34 | 40 | ); |
| 35 | 41 | } |
| 36 | 42 | |
| 43 | + /** |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 37 | 46 | public function getBulkUpdateQuery($data, $parameters) |
| 38 | 47 | { |
| 39 | 48 | $updateData = []; |
@@ -74,6 +83,9 @@ discard block |
||
| 74 | 83 | ); |
| 75 | 84 | } |
| 76 | 85 | |
| 86 | + /** |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 77 | 89 | public function getSelectQuery($parameters) |
| 78 | 90 | { |
| 79 | 91 | return $this->filter(sprintf( |
@@ -88,6 +100,9 @@ discard block |
||
| 88 | 100 | ); |
| 89 | 101 | } |
| 90 | 102 | |
| 103 | + /** |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 91 | 106 | public function getCountQuery($parameters) |
| 92 | 107 | { |
| 93 | 108 | return $this->filter(sprintf( |
@@ -98,6 +113,9 @@ discard block |
||
| 98 | 113 | ); |
| 99 | 114 | } |
| 100 | 115 | |
| 116 | + /** |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 101 | 119 | public function getDeleteQuery($parameters) |
| 102 | 120 | { |
| 103 | 121 | return $this->filter(sprintf( |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | return $this->filter( |
| 32 | - "INSERT INTO " . $this->db->quoteIdentifier($model->getTable()) . |
|
| 33 | - " (" . implode(", ", $quotedFields) . ") VALUES (" . implode(', ', $valueFields) . ")" |
|
| 32 | + "INSERT INTO ".$this->db->quoteIdentifier($model->getTable()). |
|
| 33 | + " (".implode(", ", $quotedFields).") VALUES (".implode(', ', $valueFields).")" |
|
| 34 | 34 | ); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function getBulkUpdateQuery($data, $parameters) |
| 38 | 38 | { |
| 39 | 39 | $updateData = []; |
| 40 | - foreach($data as $field => $value) { |
|
| 40 | + foreach ($data as $field => $value) { |
|
| 41 | 41 | $updateData[] = "{$this->db->quoteIdentifier($field)} = :$field"; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -60,17 +60,17 @@ discard block |
||
| 60 | 60 | foreach ($fields as $field) { |
| 61 | 61 | $quotedField = $this->db->quoteIdentifier($field); |
| 62 | 62 | |
| 63 | - if(array_search($field, $primaryKey) !== false) { |
|
| 63 | + if (array_search($field, $primaryKey) !== false) { |
|
| 64 | 64 | $conditions[] = "{$quotedField} = :{$field}"; |
| 65 | 65 | } else { |
| 66 | 66 | $valueFields[] = "{$quotedField} = :{$field}"; |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - return $this->filter("UPDATE " . |
|
| 71 | - $this->db->quoteIdentifier($model->getTable()) . |
|
| 72 | - " SET " . implode(', ', $valueFields) . |
|
| 73 | - " WHERE " . implode(' AND ', $conditions) |
|
| 70 | + return $this->filter("UPDATE ". |
|
| 71 | + $this->db->quoteIdentifier($model->getTable()). |
|
| 72 | + " SET ".implode(', ', $valueFields). |
|
| 73 | + " WHERE ".implode(' AND ', $conditions) |
|
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -23,7 +23,6 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * |
| 26 | - * @param \ $model |
|
| 27 | 26 | */ |
| 28 | 27 | public function __construct($wrapper) |
| 29 | 28 | { |
@@ -118,6 +117,9 @@ discard block |
||
| 118 | 117 | $this->boundData += $values; |
| 119 | 118 | } |
| 120 | 119 | |
| 120 | + /** |
|
| 121 | + * @param boolean $firstOnly |
|
| 122 | + */ |
|
| 121 | 123 | public function setFirstOnly($firstOnly) |
| 122 | 124 | { |
| 123 | 125 | $this->firstOnly = $firstOnly; |
@@ -139,6 +141,9 @@ discard block |
||
| 139 | 141 | $this->offset = $offset; |
| 140 | 142 | } |
| 141 | 143 | |
| 144 | + /** |
|
| 145 | + * @param string $field |
|
| 146 | + */ |
|
| 142 | 147 | public function addSort($field, $direction = 'ASC') |
| 143 | 148 | { |
| 144 | 149 | $this->sorts[] = "$field $direction"; |
@@ -92,10 +92,10 @@ |
||
| 92 | 92 | if ($numValues === 1) { |
| 93 | 93 | $key = "filter_{$startIndex}"; |
| 94 | 94 | if($values[0] === null) { |
| 95 | - $this->whereClause .= "{$field} is NULL"; |
|
| 95 | + $this->whereClause .= "{$field} is NULL"; |
|
| 96 | 96 | } else { |
| 97 | - $this->whereClause .= "{$field} = :$key"; |
|
| 98 | - $this->boundData[$key] = reset($values); |
|
| 97 | + $this->whereClause .= "{$field} = :$key"; |
|
| 98 | + $this->boundData[$key] = reset($values); |
|
| 99 | 99 | } |
| 100 | 100 | } else { |
| 101 | 101 | $this->whereClause .= "{$field} IN ("; |
@@ -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 = ' ,'; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * @method |
| 126 | - * @param type $name |
|
| 126 | + * @param string $name |
|
| 127 | 127 | * @param type $arguments |
| 128 | 128 | * @return type |
| 129 | 129 | */ |
@@ -157,6 +157,9 @@ discard block |
||
| 157 | 157 | return $this->table; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | + /** |
|
| 161 | + * @param integer $depth |
|
| 162 | + */ |
|
| 160 | 163 | private function expandArrayValue($array, $relationships, $depth, $index = null) |
| 161 | 164 | { |
| 162 | 165 | foreach($relationships as $name => $relationship) { |
@@ -25,7 +25,6 @@ |
||
| 25 | 25 | |
| 26 | 26 | namespace ntentan\nibii; |
| 27 | 27 | |
| 28 | -use ntentan\utils\Utils; |
|
| 29 | 28 | use ntentan\kaikai\Cache; |
| 30 | 29 | |
| 31 | 30 | class RecordWrapper implements \ArrayAccess, \Countable, \Iterator |
@@ -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)); |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | 'default' => $details['default'], |
| 29 | 29 | 'name' => $field |
| 30 | 30 | ]; |
| 31 | - if(isset($details['default'])) { |
|
| 31 | + if (isset($details['default'])) { |
|
| 32 | 32 | $this->fields[$field]['default'] = $details['default']; |
| 33 | 33 | } |
| 34 | - if(isset($details['length'])) { |
|
| 34 | + if (isset($details['length'])) { |
|
| 35 | 35 | $this->fields[$field]['length'] = $details['length']; |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $this->appendConstraints($schema['primary_key'], $this->primaryKey, true); |
| 40 | 40 | $this->appendConstraints($schema['unique_keys'], $this->uniqueKeys); |
| 41 | 41 | |
| 42 | - foreach($relationships as $type => $relations) { |
|
| 42 | + foreach ($relationships as $type => $relations) { |
|
| 43 | 43 | $this->createRelationships($type, $relations); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | private function getRelationshipDetails($relationship) |
| 63 | 63 | { |
| 64 | - if(is_string($relationship)) |
|
| 64 | + if (is_string($relationship)) |
|
| 65 | 65 | { |
| 66 | 66 | return [ |
| 67 | 67 | 'model' => $relationship, |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | private function createRelationships($type, $relationships) |
| 83 | 83 | { |
| 84 | - foreach($relationships as $relationship) |
|
| 84 | + foreach ($relationships as $relationship) |
|
| 85 | 85 | { |
| 86 | 86 | $relationship = $this->getRelationshipDetails($relationship); |
| 87 | 87 | $class = "\\ntentan\\nibii\\relationships\\{$type}Relationship"; |
@@ -15,17 +15,17 @@ discard block |
||
| 15 | 15 | $this->model = $model; |
| 16 | 16 | $description = $model->getDescription(); |
| 17 | 17 | |
| 18 | - if($description->getAutoPrimaryKey()) { |
|
| 18 | + if ($description->getAutoPrimaryKey()) { |
|
| 19 | 19 | $pk = $description->getPrimaryKey()[0]; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | $fields = $description->getFields(); |
| 23 | - foreach($fields as $field) { |
|
| 23 | + foreach ($fields as $field) { |
|
| 24 | 24 | $this->getFieldRules($rules, $field, $pk); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | $unique = $description->getUniqueKeys(); |
| 28 | - foreach($unique as $constraints) { |
|
| 28 | + foreach ($unique as $constraints) { |
|
| 29 | 29 | $rules['unique'][] = [$constraints['fields']]; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | private function getFieldRules(&$rules, $field, $pk) |
| 41 | 41 | { |
| 42 | - if($field['required'] && $field['name'] != $pk && $field['default'] === null) { |
|
| 42 | + if ($field['required'] && $field['name'] != $pk && $field['default'] === null) { |
|
| 43 | 43 | $rules['required'][] = $field['name']; |
| 44 | 44 | } |
| 45 | - if($field['type'] === 'integer' || $field['type'] === 'double') { |
|
| 45 | + if ($field['type'] === 'integer' || $field['type'] === 'double') { |
|
| 46 | 46 | $rules['numeric'][] = $field['name']; |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | private $dataOperations; |
| 15 | 15 | |
| 16 | 16 | private $queryOperationMethods = [ |
| 17 | - 'fetch', 'fetchFirst', 'filter', 'query', 'fields', |
|
| 18 | - 'cover', 'limit', 'offset', 'filterBy', 'sortBy', |
|
| 19 | - 'delete', 'count', 'update' |
|
| 17 | + 'fetch', 'fetchFirst', 'filter', 'query', 'fields', |
|
| 18 | + 'cover', 'limit', 'offset', 'filterBy', 'sortBy', |
|
| 19 | + 'delete', 'count', 'update' |
|
| 20 | 20 | ]; |
| 21 | 21 | |
| 22 | 22 | private $dataOperationMethods = [ |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | if (array_search($name, $this->queryOperationMethods) !== false) { |
| 37 | 37 | return call_user_func_array([$this->queryOperations, "do$name"], $arguments); |
| 38 | - } else if (array_search($name, $this->dataOperationMethods) !== false){ |
|
| 38 | + } else if (array_search($name, $this->dataOperationMethods) !== false) { |
|
| 39 | 39 | return call_user_func_array([$this->dataOperations, "do$name"], $arguments); |
| 40 | - } else if($this->queryOperations->initDynamicMethod($name)) { |
|
| 40 | + } else if ($this->queryOperations->initDynamicMethod($name)) { |
|
| 41 | 41 | return $this->queryOperations->runDynamicMethod($arguments); |
| 42 | 42 | } else { |
| 43 | 43 | throw new NibiiException("Method {$name} not found"); |
@@ -23,6 +23,9 @@ |
||
| 23 | 23 | 'save' |
| 24 | 24 | ]; |
| 25 | 25 | |
| 26 | + /** |
|
| 27 | + * @param RecordWrapper $wrapper |
|
| 28 | + */ |
|
| 26 | 29 | public function __construct($wrapper, $adapter) |
| 27 | 30 | { |
| 28 | 31 | $this->wrapper = $wrapper; |