| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | |
| 27 | 27 | namespace ntentan\nibii\relationships; | 
| 28 | 28 | |
| 29 | -use ntentan\nibii\exceptions\FieldNotFoundException; | |
| 30 | 29 | use ntentan\nibii\ORMContext; | 
| 31 | 30 | use ntentan\nibii\Relationship; | 
| 31 | +use ntentan\nibii\exceptions\FieldNotFoundException; | |
| 32 | 32 | use ntentan\utils\Text; | 
| 33 | 33 | |
| 34 | 34 | /** | 
| @@ -74,7 +74,7 @@ | ||
| 74 | 74 | |
| 75 | 75 | public function preSave(&$wrapper, $value) | 
| 76 | 76 |      { | 
| 77 | -        if(!$value->save()) { | |
| 77 | +        if (!$value->save()) { | |
| 78 | 78 | $this->invalidFields = $value->getInvalidFields(); | 
| 79 | 79 | } | 
| 80 | 80 | $wrapper[$this->options['local_key']] = $value[$this->options['foreign_key']]; | 
| @@ -139,7 +139,7 @@ | ||
| 139 | 139 | public function describe($model, $relationships) | 
| 140 | 140 |      { | 
| 141 | 141 | return new ModelDescription( | 
| 142 | -            $this->driver->describeTable($table)[$table], $relationships, function ($type) { | |
| 142 | +            $this->driver->describeTable($table)[$table], $relationships, function($type) { | |
| 143 | 143 | return $this->mapDataTypes($type); | 
| 144 | 144 | } | 
| 145 | 145 | ); | 
| @@ -26,7 +26,6 @@ | ||
| 26 | 26 | |
| 27 | 27 | namespace ntentan\nibii\relationships; | 
| 28 | 28 | |
| 29 | -use ntentan\nibii\exceptions\NibiiException; | |
| 30 | 29 | use ntentan\nibii\Relationship; | 
| 31 | 30 | use ntentan\utils\Text; | 
| 32 | 31 | |
| @@ -39,13 +39,13 @@ discard block | ||
| 39 | 39 |      { | 
| 40 | 40 | // @todo throw an exception when the data doesn't have the local key | 
| 41 | 41 | $query = $this->createQuery(); | 
| 42 | -        if(!$this->queryPrepared) { | |
| 42 | +        if (!$this->queryPrepared) { | |
| 43 | 43 | $query->setTable($this->getModelInstance()->getDBStoreInformation()['quoted_table']) | 
| 44 | 44 | ->addFilter($this->options['foreign_key'], $data[$this->options['local_key']] ?? null); | 
| 45 | 45 | $this->queryPrepared = true; | 
| 46 | 46 | return $query; | 
| 47 | 47 | } | 
| 48 | -        if(isset($data[$this->options['local_key']])) { | |
| 48 | +        if (isset($data[$this->options['local_key']])) { | |
| 49 | 49 | $query->setBoundData($this->options['foreign_key'], $data[$this->options['local_key']]); | 
| 50 | 50 | } | 
| 51 | 51 | return $query; | 
| @@ -70,11 +70,11 @@ discard block | ||
| 70 | 70 | public function postSave(&$wrapper) | 
| 71 | 71 |      { | 
| 72 | 72 | $records = $this->tempData->getData(); | 
| 73 | -        foreach($records as $i => $relatedRecord) { | |
| 73 | +        foreach ($records as $i => $relatedRecord) { | |
| 74 | 74 | $records[$i][$this->options['foreign_key']] = $wrapper[$this->options['local_key']]; | 
| 75 | 75 | } | 
| 76 | 76 | $this->tempData->setData($records); | 
| 77 | -        if(!$this->tempData->save()) { | |
| 77 | +        if (!$this->tempData->save()) { | |
| 78 | 78 | $this->invalidFields = $this->tempData->getInvalidFields(); | 
| 79 | 79 | } | 
| 80 | 80 | $wrapper[$this->options['model']] = $this->tempData; | 
| @@ -26,7 +26,6 @@ | ||
| 26 | 26 | |
| 27 | 27 | namespace ntentan\nibii\relationships; | 
| 28 | 28 | |
| 29 | -use ntentan\nibii\exceptions\NibiiException; | |
| 30 | 29 | use ntentan\nibii\ORMContext; | 
| 31 | 30 | use ntentan\nibii\Relationship; | 
| 32 | 31 | use ntentan\utils\Text; | 
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | $jointModelRecords = []; | 
| 111 | 111 |          foreach ($this->tempdata as $relatedRecord) { | 
| 112 | 112 |              if (!$relatedRecord->save()) { | 
| 113 | - $this->invalidFields =$this->tempdata->getInvalidFields(); | |
| 113 | + $this->invalidFields = $this->tempdata->getInvalidFields(); | |
| 114 | 114 | } | 
| 115 | 115 | $jointModelRecords[] = [ | 
| 116 | 116 | $this->options['junction_local_key'] => $wrapper[$this->options['local_key']], | 
| @@ -239,7 +239,7 @@ discard block | ||
| 239 | 239 |          foreach ($relationshipsWithData as $model => $relationship) { | 
| 240 | 240 | $relationship->postSave($record); | 
| 241 | 241 | $invalidRelatedFields = $relationship->getInvalidFields(); | 
| 242 | -            if(!empty($invalidRelatedFields)) { | |
| 242 | +            if (!empty($invalidRelatedFields)) { | |
| 243 | 243 | $status['success'] = false; | 
| 244 | 244 | $status['invalid_fields'][$model] = $invalidRelatedFields; | 
| 245 | 245 | } | 
| @@ -265,10 +265,10 @@ discard block | ||
| 265 | 265 | $mainValidatorErrors = $validator->getInvalidFields(); | 
| 266 | 266 | } | 
| 267 | 267 | |
| 268 | -        if(!empty($this->wrapper->getValidationRules())) { | |
| 268 | +        if (!empty($this->wrapper->getValidationRules())) { | |
| 269 | 269 | $modelValidator = new Validator(); | 
| 270 | 270 | $modelValidator->setRules($this->wrapper->getValidationRules()); | 
| 271 | -            if(!$modelValidator->validate($data)) { | |
| 271 | +            if (!$modelValidator->validate($data)) { | |
| 272 | 272 | $modelValidatorErrors = $modelValidator->getInvalidFields(); | 
| 273 | 273 | } | 
| 274 | 274 | } | 
| @@ -28,8 +28,8 @@ | ||
| 28 | 28 | |
| 29 | 29 | use ntentan\atiaa\Driver; | 
| 30 | 30 | use ntentan\atiaa\exceptions\ConnectionException; | 
| 31 | -use ntentan\utils\exceptions\ValidatorNotFoundException; | |
| 32 | 31 | use ntentan\utils\Validator; | 
| 32 | +use ntentan\utils\exceptions\ValidatorNotFoundException; | |
| 33 | 33 | |
| 34 | 34 | /** | 
| 35 | 35 | * Description of DataOperations. | 
| @@ -28,10 +28,10 @@ | ||
| 28 | 28 | |
| 29 | 29 | use ntentan\atiaa\DbContext; | 
| 30 | 30 | use ntentan\kaikai\Cache; | 
| 31 | +use ntentan\nibii\exceptions\NibiiException; | |
| 31 | 32 | use ntentan\nibii\interfaces\DriverAdapterFactoryInterface; | 
| 32 | 33 | use ntentan\nibii\interfaces\ModelFactoryInterface; | 
| 33 | 34 | use ntentan\nibii\interfaces\ValidatorFactoryInterface; | 
| 34 | -use ntentan\nibii\exceptions\NibiiException; | |
| 35 | 35 | use ntentan\panie\exceptions\ResolutionException; | 
| 36 | 36 | |
| 37 | 37 | /** | 
| @@ -211,7 +211,7 @@ discard block | ||
| 211 | 211 | $this->initialize(); | 
| 212 | 212 | |
| 213 | 213 | return $this->context->getCache()->read( | 
| 214 | -            "{$this->className}::desc", function () { | |
| 214 | +            "{$this->className}::desc", function() { | |
| 215 | 215 | return $this->context->getModelDescription($this); | 
| 216 | 216 | } | 
| 217 | 217 | ); | 
| @@ -449,13 +449,13 @@ discard block | ||
| 449 | 449 | return null; | 
| 450 | 450 | } | 
| 451 | 451 | $name = $relationship->getOptions()['name']; | 
| 452 | - if(isset($data[$name])) | |
| 452 | + if (isset($data[$name])) | |
| 453 | 453 |          { | 
| 454 | 454 | return $data[$name]; | 
| 455 | 455 | } | 
| 456 | 456 | $query = $relationship->prepareQuery($data); | 
| 457 | 457 | |
| 458 | -        if($query) { | |
| 458 | +        if ($query) { | |
| 459 | 459 | $model = $relationship->getModelInstance(); | 
| 460 | 460 | return $model->fetch($query); | 
| 461 | 461 |          } else { | 
| @@ -555,7 +555,7 @@ discard block | ||
| 555 | 555 | $allExpandableModels = empty($expandableModels) ? array_keys($relationships) : $expandableModels; | 
| 556 | 556 |          foreach ($allExpandableModels as $name) { | 
| 557 | 557 | $value = $this->fetchRelatedFields($relationships[$name], $index); | 
| 558 | -            if($value) { | |
| 558 | +            if ($value) { | |
| 559 | 559 | $array[$name] = $value->toArray($depth, $expandableModels); | 
| 560 | 560 |              } else { | 
| 561 | 561 | $array[$name] = null; | 
| @@ -595,7 +595,7 @@ discard block | ||
| 595 | 595 | public function fromArray($data) | 
| 596 | 596 |      { | 
| 597 | 597 | // Create a new instance if this model already has data. | 
| 598 | -        if($this->hasDataBeenSet) { | |
| 598 | +        if ($this->hasDataBeenSet) { | |
| 599 | 599 | $instance = new $this->className(); | 
| 600 | 600 |          } else { | 
| 601 | 601 | $instance = $this; |