| @@ -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]; | 
| @@ -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"); | 
| @@ -79,7 +79,7 @@ discard block | ||
| 79 | 79 |          } else if ($arg instanceof \ntentan\nibii\QueryParameters) { | 
| 80 | 80 | $parameters = $arg; | 
| 81 | 81 |          } else if (is_array($arg)) { | 
| 82 | -            foreach($arg as $field => $value) { | |
| 82 | +            foreach ($arg as $field => $value) { | |
| 83 | 83 | $parameters->addFilter($field, [$value]); | 
| 84 | 84 | } | 
| 85 | 85 | } | 
| @@ -113,11 +113,11 @@ discard block | ||
| 113 | 113 |      { | 
| 114 | 114 | $fields = []; | 
| 115 | 115 | $arguments = func_get_args(); | 
| 116 | -        foreach($arguments as $argument) { | |
| 117 | -            if(is_array($argument)) { | |
| 116 | +        foreach ($arguments as $argument) { | |
| 117 | +            if (is_array($argument)) { | |
| 118 | 118 | $fields = array_merge($fields, $argument); | 
| 119 | 119 |              } else { | 
| 120 | - $fields[]=$argument; | |
| 120 | + $fields[] = $argument; | |
| 121 | 121 | } | 
| 122 | 122 | } | 
| 123 | 123 | $this->getQueryParameters()->setFields($fields); | 
| @@ -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 = ' ,'; | 
| @@ -47,7 +47,7 @@ | ||
| 47 | 47 | |
| 48 | 48 | public function getModelInstance() | 
| 49 | 49 |      { | 
| 50 | -        if(!$this->setup) { | |
| 50 | +        if (!$this->setup) { | |
| 51 | 51 | $this->runSetup(); | 
| 52 | 52 | $this->setup = true; | 
| 53 | 53 | } | 
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | */ | 
| 13 | 13 | public function mapDataTypes($nativeType) | 
| 14 | 14 |      { | 
| 15 | - switch($nativeType) | |
| 15 | + switch ($nativeType) | |
| 16 | 16 |          { | 
| 17 | 17 | case 'character varying': | 
| 18 | 18 | return 'string'; | 
| @@ -16,7 +16,7 @@ discard block | ||
| 16 | 16 | |
| 17 | 17 | public function preSaveCallback($data) | 
| 18 | 18 |      { | 
| 19 | - if(isset($this->model->getDescription()->getFields()['created'])) | |
| 19 | + if (isset($this->model->getDescription()->getFields()['created'])) | |
| 20 | 20 |          { | 
| 21 | 21 |              $data['created'] = date('Y-m-d H:i:s'); | 
| 22 | 22 | } | 
| @@ -25,7 +25,7 @@ discard block | ||
| 25 | 25 | |
| 26 | 26 | public function preUpdateCallback($data) | 
| 27 | 27 |      { | 
| 28 | - if(isset($this->model->getDescription()->getFields()['updated'])) | |
| 28 | + if (isset($this->model->getDescription()->getFields()['updated'])) | |
| 29 | 29 |          { | 
| 30 | 30 |              $data['updated'] = date('Y-m-d H:i:s'); | 
| 31 | 31 | } |