diff --git a/src/Abstractor/Eloquent/FieldFactory.php b/src/Abstractor/Eloquent/FieldFactory.php index 46935f6..31041a2 100644 --- a/src/Abstractor/Eloquent/FieldFactory.php +++ b/src/Abstractor/Eloquent/FieldFactory.php @@ -128,7 +128,6 @@ protected function getFormElement() $formElementType = 'select'; } - $formElement = $this->factory->get($formElementType, []); if (!empty($this->config['attr']) && is_array($this->config['attr'])) { diff --git a/src/Abstractor/Eloquent/Model.php b/src/Abstractor/Eloquent/Model.php index 2e338d5..0454491 100644 --- a/src/Abstractor/Eloquent/Model.php +++ b/src/Abstractor/Eloquent/Model.php @@ -129,7 +129,6 @@ public function getColumns($action, $withForeignKeys = false) } $tableColumns = $filteredColumns; - $foreignKeysName = []; if ($withForeignKeys === false) { $foreignKeys = $this->dbal->getTableForeignKeys(); @@ -238,7 +237,6 @@ public function getRelations() $secondaryRelations = $relation->getSecondaryRelations(); - if (!$secondaryRelations->isEmpty()) { $relations->put( $relationName, @@ -426,7 +424,6 @@ public function persist(Request $request) $item = $modelManager->getModelInstance($this->getModel()); } - $fields = $this->getEditFields(true); if (empty($fields['main']) && $this->getRelations()->isEmpty()) { return; @@ -465,7 +462,6 @@ public function persist(Request $request) } } - if (!$field->saveIfEmpty() && empty($requestValue)) { continue; } @@ -483,7 +479,6 @@ public function persist(Request $request) $this->setInstance($item); - if (!empty($relations = $this->getRelations())) { foreach ($relations as $relationKey => $relation) { if ($relation instanceof Collection) { diff --git a/src/Abstractor/Eloquent/ModelFactory.php b/src/Abstractor/Eloquent/ModelFactory.php index 6d120e7..536798c 100644 --- a/src/Abstractor/Eloquent/ModelFactory.php +++ b/src/Abstractor/Eloquent/ModelFactory.php @@ -114,7 +114,6 @@ public function getByClassName($classname, array $config, $id = null) $model = new Model(array_merge(['model' => $classname], $config), $this->modelManager->getAbstractionLayer($classname), $this->relationFactory, $this->fieldFactory, $this->generator); $model->setSlug($this->slugger->slugify((new ReflectionClass($classname))->getShortName())); - if (is_null($id)) { $model->setInstance($this->modelManager->getModelInstance($classname)); } else { diff --git a/src/Abstractor/Eloquent/Relation/MiniCrud.php b/src/Abstractor/Eloquent/Relation/MiniCrud.php index 626a65d..d22d711 100644 --- a/src/Abstractor/Eloquent/Relation/MiniCrud.php +++ b/src/Abstractor/Eloquent/Relation/MiniCrud.php @@ -54,11 +54,9 @@ public function getEditFields($arrayKey = null) $fieldsBase = $this->getEditFieldsBase(); - /** @var Collection $results */ $results = $this->getResults(); - $results->put('emptyResult', ''); if (!empty($fieldsBase)) { foreach ($results as $key => $result) { @@ -81,7 +79,6 @@ public function getEditFields($arrayKey = null) $tempFields[$columnName] = $field; } - $relationModel = $this->eloquentRelation->getRelated()->newInstance(); if (!empty($result)) { $relationModel = $result; @@ -135,7 +132,6 @@ public function getEditFieldsBase() ->get(); $fields['__delete'] = $field; - foreach ($columns as $columnName => $column) { if (in_array($columnName, $readOnly, true)) { continue; @@ -211,7 +207,6 @@ public function persist(array $relationArray = null, Request $request) $this->modelAbstractor->setInstance($relationModel); $secondaryRelations = $this->getSecondaryRelations(); - $this->setKeys($relationModel); $shouldBeSkipped = true; @@ -243,7 +238,6 @@ public function persist(array $relationArray = null, Request $request) } } - foreach ($relation as $fieldKey => $fieldValue) { if ($secondaryRelations->has($fieldKey)) { $delayedRelations->put($fieldKey, $fieldValue); diff --git a/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php b/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php index 81e9eca..7ce945d 100644 --- a/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php +++ b/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php @@ -44,7 +44,6 @@ public function getEditFields($arrayKey = null) $this->eloquentRelation->getParent()->getKeyName(), ]; - $this->readConfig('edit'); if (!empty($columns)) { @@ -98,7 +97,6 @@ public function getEditFields($arrayKey = null) $fields = $this->addSecondaryRelationFields($fields); - return $fields; } diff --git a/src/Abstractor/Eloquent/Relation/Relation.php b/src/Abstractor/Eloquent/Relation/Relation.php index 28ef086..9d56291 100644 --- a/src/Abstractor/Eloquent/Relation/Relation.php +++ b/src/Abstractor/Eloquent/Relation/Relation.php @@ -71,7 +71,7 @@ public function __construct(array $config, ModelManager $modelManager, Model $mo } } - $config = array_merge($this->config,$relatedmodelRelationsConfig); + $config = array_merge($this->config, $relatedmodelRelationsConfig); $this->modelAbstractor = \App::make('Anavel\Crud\Contracts\Abstractor\ModelFactory')->getByClassName(get_class($this->eloquentRelation->getRelated()), $config); } diff --git a/src/Abstractor/Eloquent/Relation/SelectMultiple.php b/src/Abstractor/Eloquent/Relation/SelectMultiple.php index f1bffcb..95ab262 100644 --- a/src/Abstractor/Eloquent/Relation/SelectMultiple.php +++ b/src/Abstractor/Eloquent/Relation/SelectMultiple.php @@ -46,7 +46,6 @@ public function persist(array $relationArray = null, Request $request) $missing = $alreadyAssociated->diff($results); - $keyName = $this->eloquentRelation->getPlainForeignKey(); foreach ($results as $result) { $result->$keyName = $this->relatedModel->getKey(); diff --git a/src/Abstractor/Eloquent/RelationFactory.php b/src/Abstractor/Eloquent/RelationFactory.php index 9004787..633c655 100644 --- a/src/Abstractor/Eloquent/RelationFactory.php +++ b/src/Abstractor/Eloquent/RelationFactory.php @@ -83,7 +83,6 @@ public function get($name) $relationInstance = $this->model->$name(); $relationEloquentType = get_class($relationInstance); - if (empty($this->config['type'])) { if (!array_key_exists($relationEloquentType, $this->eloquentTypeToRelationType)) { throw new FactoryException($relationEloquentType.' relation not supported'); diff --git a/src/Abstractor/Eloquent/Traits/HandleFiles.php b/src/Abstractor/Eloquent/Traits/HandleFiles.php index 038b419..cd31a0a 100644 --- a/src/Abstractor/Eloquent/Traits/HandleFiles.php +++ b/src/Abstractor/Eloquent/Traits/HandleFiles.php @@ -31,12 +31,10 @@ protected function handleField(Request $request, $item, array $fields, $groupNam $skip = null; $requestValue = null; - if (!empty($fields["{$fieldName}__delete"])) { //We never want to save this field, it doesn't exist in the DB $skip = "{$fieldName}__delete"; - //If user wants to delete the existing file if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { $adapter = new Local($basePath); @@ -45,7 +43,6 @@ protected function handleField(Request $request, $item, array $fields, $groupNam $filesystem->delete($item->$fieldName); } - $item->setAttribute( $fieldName, null @@ -68,7 +65,6 @@ protected function handleField(Request $request, $item, array $fields, $groupNam $fileName .= '.'.$extension; } - $request->file($groupName.'.'.$fieldName)->move( $modelPath, $fileName diff --git a/src/Http/Controllers/HomeController.php b/src/Http/Controllers/HomeController.php index 214a280..877ffc5 100644 --- a/src/Http/Controllers/HomeController.php +++ b/src/Http/Controllers/HomeController.php @@ -18,7 +18,6 @@ public function index(ModelAbstractorFactory $modelFactory) throw new \Exception('No models configured.'); } - foreach ($models as $modelName => $model) { $modelSlug = Slugger::slugify($modelName); $modelAbstractor = $modelFactory->getByName($modelSlug); diff --git a/src/Http/Form/Generator.php b/src/Http/Form/Generator.php index 7367902..f2acab0 100644 --- a/src/Http/Form/Generator.php +++ b/src/Http/Form/Generator.php @@ -87,7 +87,6 @@ public function getForm($action) 'class' => 'form-horizontal', ]); - $formFields = []; foreach ($this->fields as $fieldGroupName => $fieldGroup) { $tempFields = $this->addFormFields($fieldGroup, $fieldGroupName); @@ -96,7 +95,6 @@ public function getForm($action) $form->add($formFields); - return $form; } diff --git a/tests/Abstractor/Eloquent/FieldTest.php b/tests/Abstractor/Eloquent/FieldTest.php index 8ec650a..09ac966 100644 --- a/tests/Abstractor/Eloquent/FieldTest.php +++ b/tests/Abstractor/Eloquent/FieldTest.php @@ -43,7 +43,6 @@ public function test_returns_type() $type = $this->sut->type(); - $this->assertInstanceOf('Doctrine\DBAL\Types\Type', $type); } diff --git a/tests/Abstractor/Eloquent/MiniCrudPolymorphicTest.php b/tests/Abstractor/Eloquent/MiniCrudPolymorphicTest.php index 2e45830..a1639e8 100644 --- a/tests/Abstractor/Eloquent/MiniCrudPolymorphicTest.php +++ b/tests/Abstractor/Eloquent/MiniCrudPolymorphicTest.php @@ -95,7 +95,6 @@ public function test_get_edit_fields_returns_array() $postMock->shouldReceive('getAttribute')->andReturn('idValue'); - $fieldMock->shouldReceive('setOptions'); $fieldMock->shouldReceive('setValue')->times(1); @@ -103,8 +102,6 @@ public function test_get_edit_fields_returns_array() $this->modelAbstractorMock->shouldReceive('getRelations')->times(2)->andReturn([$this->secondaryRelationMock = $this->mock('Anavel\Crud\Abstractor\Eloquent\Relation\Select')]); $this->secondaryRelationMock->shouldReceive('getEditFields')->andReturn([]); - - $this->getClassMock->andReturn('Illuminate\Database\Eloquent\Relations\MorphMany'); $this->buildRelation(); $fields = $this->sut->getEditFields(); @@ -191,7 +188,6 @@ public function test_persist_with_old_results() $this->modelAbstractorMock->shouldReceive('setInstance')->with($modelMock); - $modelMock->shouldReceive('getKey')->andReturn(1); $modelMock->shouldReceive('setAttribute')->times(10); $modelMock->shouldReceive('save')->times(2); diff --git a/tests/Abstractor/Eloquent/MiniCrudSingleTest.php b/tests/Abstractor/Eloquent/MiniCrudSingleTest.php index 1733699..c3a7e54 100644 --- a/tests/Abstractor/Eloquent/MiniCrudSingleTest.php +++ b/tests/Abstractor/Eloquent/MiniCrudSingleTest.php @@ -93,7 +93,6 @@ public function test_get_edit_fields_returns_array() $postMock->shouldReceive('getAttributeValue')->andReturn('1'); $postMock->shouldReceive('getAttribute')->andReturn('chompy'); - $this->fieldFactoryMock->shouldReceive('setColumn', 'setConfig')->andReturn($this->fieldFactoryMock); $this->fieldFactoryMock->shouldReceive('get')->andReturn($fieldMock = $this->mock('Anavel\Crud\Contracts\Abstractor\Field')); $fieldMock->shouldReceive('setOptions'); @@ -103,7 +102,6 @@ public function test_get_edit_fields_returns_array() $this->modelAbstractorMock->shouldReceive('getRelations')->times(1)->andReturn([$secondaryRelationMock = $this->mock('Anavel\Crud\Abstractor\Eloquent\Relation\Select')]); $secondaryRelationMock->shouldReceive('getEditFields')->andReturn([]); - $this->getClassMock->andReturn('Illuminate\Database\Eloquent\Relations\MorphOne'); $this->buildRelation(); $fields = $this->sut->getEditFields(); diff --git a/tests/Abstractor/Eloquent/MiniCrudTest.php b/tests/Abstractor/Eloquent/MiniCrudTest.php index fd5d350..228fd25 100644 --- a/tests/Abstractor/Eloquent/MiniCrudTest.php +++ b/tests/Abstractor/Eloquent/MiniCrudTest.php @@ -89,7 +89,6 @@ public function test_get_edit_fields_returns_array() $this->fieldFactoryMock->shouldReceive('setColumn', 'setConfig')->andReturn($this->fieldFactoryMock); $this->fieldFactoryMock->shouldReceive('get')->andReturn($fieldMock = $this->mock('Anavel\Crud\Contracts\Abstractor\Field')); - $this->relationMock->shouldReceive('newInstance')->andReturn($postMock); $this->modelAbstractorMock->shouldReceive('setInstance')->with($postMock); @@ -98,7 +97,6 @@ public function test_get_edit_fields_returns_array() $secondaryRelationMock->shouldReceive('getEditFields')->andReturn([]); - $postMock->shouldReceive('getAttribute')->andReturn('idValue'); $fieldMock->shouldReceive('setOptions'); @@ -154,7 +152,6 @@ public function test_persist_with_no_old_results() $this->fieldFactoryMock->shouldReceive('get')->andReturn($fieldMock = $this->mock('Anavel\Crud\Contracts\Abstractor\Field')); //////// - $fieldMock->shouldReceive('getName'); $fieldMock->shouldReceive('getFormField'); $modelMock->shouldReceive('getKey')->andReturn(1); @@ -191,8 +188,6 @@ public function test_persist_with_old_results() $this->relationMock->shouldReceive('getKeyName')->andReturn('id'); $this->modelAbstractorMock->shouldReceive('getRelations')->andReturn(collect()); - - $this->relationMock->shouldReceive('getResults')->andReturn($this->relationMock, collect([1 => $modelMock = $this->mock('Anavel\Crud\Tests\Models\Post')])); // This, basically, re-tests getEditFields... It shouldn't be re-tested, but I can't figure out how to partially mock that method $this->relationMock->shouldReceive('getRelated', 'getPlainForeignKey', 'getParent', diff --git a/tests/Abstractor/Eloquent/ModelTest.php b/tests/Abstractor/Eloquent/ModelTest.php index 6972f9f..bb403af 100644 --- a/tests/Abstractor/Eloquent/ModelTest.php +++ b/tests/Abstractor/Eloquent/ModelTest.php @@ -38,7 +38,6 @@ public function setUp() $this->columnMock = $this->mock('Doctrine\DBAL\Schema\Column'); $this->generatorMock = $this->mock('Anavel\Crud\Contracts\Form\Generator'); - $this->getClassMock = PHPMockery::mock('Anavel\Crud\Abstractor\Eloquent', 'get_class'); $this->sut = \Mockery::mock(Model::class, [$config['Users'], $this->dbalMock, $this->relationFactoryMock, $this->fieldFactoryMock, $this->generatorMock])->makePartial(); @@ -458,7 +457,6 @@ public function test_get_form_with_instance() $this->sut->setInstance($modelMock); - $form = $this->sut->getForm('crudoado.model.store', 'users'); $this->assertInstanceOf('FormManager\ElementInterface', $form); @@ -508,8 +506,6 @@ public function test_persist() $this->getClassMock->andReturn('nomatch'); - - $result = $this->sut->persist($requestMock); $this->assertInstanceOf('Anavel\Crud\Tests\Models\User', $result); diff --git a/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php b/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php index a204b77..e4f7ce3 100644 --- a/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php +++ b/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php @@ -34,7 +34,6 @@ public function setUp() $config = require __DIR__.'/../../config.php'; $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; - $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $this->fieldMock = $this->mock('Anavel\Crud\Contracts\Abstractor\FieldFactory'); $this->requestMock = $this->mock('Illuminate\Http\Request'); diff --git a/tests/Abstractor/Eloquent/SelectMultipleTest.php b/tests/Abstractor/Eloquent/SelectMultipleTest.php index fe66c0d..73468c0 100644 --- a/tests/Abstractor/Eloquent/SelectMultipleTest.php +++ b/tests/Abstractor/Eloquent/SelectMultipleTest.php @@ -33,7 +33,6 @@ public function setUp() $config = require __DIR__.'/../../config.php'; $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; - $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $this->fieldMock = $this->mock('Anavel\Crud\Contracts\Abstractor\FieldFactory'); $this->requestMock = $this->mock('Illuminate\Http\Request'); diff --git a/tests/Abstractor/Eloquent/SelectTest.php b/tests/Abstractor/Eloquent/SelectTest.php index 91065d0..ef3d246 100644 --- a/tests/Abstractor/Eloquent/SelectTest.php +++ b/tests/Abstractor/Eloquent/SelectTest.php @@ -64,7 +64,6 @@ public function test_get_edit_fields_return_array_with_one_field() $field->shouldReceive('setOptions'); - $fields = $this->sut->getEditFields(); $this->assertInternalType('array', $fields, 'getEditFields should return an array'); @@ -84,7 +83,6 @@ public function test_get_edit_fields_return_array_with_one_field_with_key() $field->shouldReceive('setOptions'); - $fields = $this->sut->getEditFields('chompy'); $this->assertInternalType('array', $fields, 'getEditFields should return an array'); diff --git a/tests/Abstractor/Eloquent/TranslationTest.php b/tests/Abstractor/Eloquent/TranslationTest.php index 4547f78..a1ab240 100644 --- a/tests/Abstractor/Eloquent/TranslationTest.php +++ b/tests/Abstractor/Eloquent/TranslationTest.php @@ -123,7 +123,6 @@ public function test_persist_with_no_results() $modelMock->shouldReceive('setAttribute')->times(3); // Should pass the language with only locale $modelMock->shouldReceive('save')->once(); - $this->sut->persist($inputArray, $this->requestMock); } @@ -151,7 +150,6 @@ public function test_persist_with_old_results() $modelMock->shouldReceive('delete')->once(); // Should delete the already existing language, since it's empty $modelMock->shouldReceive('save')->once(); - $this->sut->persist($inputArray, $this->requestMock); } }