diff --git a/config/anavel-crud.php b/config/anavel-crud.php index 1641a4e..cca22ff 100644 --- a/config/anavel-crud.php +++ b/config/anavel-crud.php @@ -43,7 +43,7 @@ 'date' => 'd/m/Y', 'time' => 'H:i', 'datetime' => 'd/m/Y H:i:s', - 'number' => '%.2f' + 'number' => '%.2f', ], /* @@ -143,7 +143,6 @@ ] */ ], - 'modelsGroups' => - [/*'Blog' => ['Blog Posts', 'Blog Tags']*/] + 'modelsGroups' => [/*'Blog' => ['Blog Posts', 'Blog Tags']*/], ]; diff --git a/lang/ca/messages.php b/lang/ca/messages.php index ea3fe2a..b259f26 100644 --- a/lang/ca/messages.php +++ b/lang/ca/messages.php @@ -22,5 +22,5 @@ 'alert_success_model_destroy_title' => 'Tot bé!', 'alert_success_model_destroy_text' => "L'element fou eliminat correctament", 'modal_delete_title' => 'Estàs segur?', - 'modal_delete_text' => 'Aquesta acció esborrarà permanentment aquest contingut' + 'modal_delete_text' => 'Aquesta acció esborrarà permanentment aquest contingut', ]; diff --git a/lang/en/messages.php b/lang/en/messages.php index 3b3aaea..256f73e 100644 --- a/lang/en/messages.php +++ b/lang/en/messages.php @@ -22,5 +22,5 @@ 'alert_success_model_destroy_title' => 'Everything OK!', 'alert_success_model_destroy_text' => 'The item was deleted successfully', 'modal_delete_title' => 'Are you sure?', - 'modal_delete_text' => 'This will permanently delete this content' + 'modal_delete_text' => 'This will permanently delete this content', ]; diff --git a/lang/es/messages.php b/lang/es/messages.php index e346c12..6b846bb 100644 --- a/lang/es/messages.php +++ b/lang/es/messages.php @@ -22,5 +22,5 @@ 'alert_success_model_destroy_title' => '¡Todo bien!', 'alert_success_model_destroy_text' => 'El elemento ha sido borrado correctamente', 'modal_delete_title' => 'Estás seguro/a?', - 'modal_delete_text' => 'Esto borrará permanentemente este contenido' + 'modal_delete_text' => 'Esto borrará permanentemente este contenido', ]; diff --git a/lang/gl/messages.php b/lang/gl/messages.php index 3588213..00d7768 100644 --- a/lang/gl/messages.php +++ b/lang/gl/messages.php @@ -22,5 +22,5 @@ 'alert_success_model_destroy_title' => 'Todo ben!', 'alert_success_model_destroy_text' => 'Borrouse perfectamente o que querías', 'modal_delete_title' => 'Estás seguro/a?', - 'modal_delete_text' => 'Así borrarás este contido para sempre' + 'modal_delete_text' => 'Así borrarás este contido para sempre', ]; diff --git a/src/Abstractor/ConfigurationReader.php b/src/Abstractor/ConfigurationReader.php index 9cb6ce5..39d3001 100644 --- a/src/Abstractor/ConfigurationReader.php +++ b/src/Abstractor/ConfigurationReader.php @@ -1,12 +1,13 @@ config) || empty($this->config)) { - return null; + if (!property_exists($this, 'config') || !is_array($this->config) || empty($this->config)) { + return; } $params = func_get_args(); @@ -17,9 +18,10 @@ public function getConfigValue() if (is_array($params) && count($params) > 0) { foreach ($params as $configKey) { - if (! array_key_exists($configKey, $nestedConfig)) { - $nestedConfig = array(); - return null; + if (!array_key_exists($configKey, $nestedConfig)) { + $nestedConfig = []; + + return; } $nestedConfig = $nestedConfig[$configKey]; @@ -29,7 +31,5 @@ public function getConfigValue() if (array_key_exists($lastParam, $nestedConfig)) { return $nestedConfig[$lastParam]; } - - return null; } } diff --git a/src/Abstractor/Eloquent/Field.php b/src/Abstractor/Eloquent/Field.php index 3556427..383104b 100644 --- a/src/Abstractor/Eloquent/Field.php +++ b/src/Abstractor/Eloquent/Field.php @@ -1,4 +1,5 @@ formField = $formField; $this->name = $name; $this->presentation = $presentation; - $this->validationRules = array(); - $this->functions = array(); + $this->validationRules = []; + $this->functions = []; $this->options = []; $this->hideValue = false; $this->saveIfEmpty = true; @@ -44,7 +45,7 @@ public function __clone() { $formField = clone $this->formField; $this->formField = $formField; - $field = new Field($this->dbal, $formField, $this->name, $this->presentation); + $field = new self($this->dbal, $formField, $this->name, $this->presentation); return $field; } @@ -106,8 +107,8 @@ public function getValidationRulesArray() public function setFunctions($functions) { - if (! is_array($functions)) { - $functions = array($functions); + if (!is_array($functions)) { + $functions = [$functions]; } $this->functions = $functions; @@ -116,8 +117,8 @@ public function setFunctions($functions) public function applyFunctions($value) { foreach ($this->functions as $function) { - if (! function_exists($function)) { - throw new \Exception("Function ".$function." does not exist"); + if (!function_exists($function)) { + throw new \Exception('Function '.$function.' does not exist'); } $value = call_user_func($function, $value); @@ -128,13 +129,14 @@ public function applyFunctions($value) /** * @param string $value + * * @return void */ public function setValue($value) { $this->value = $value; - if (! $this->hideValue()) { + if (!$this->hideValue()) { $this->formField->val($this->value); } } @@ -149,6 +151,7 @@ public function getValue() /** * @param array $options + * * @return void */ public function setOptions(array $options) @@ -168,7 +171,7 @@ public function getOptions() public function getFormField() { - if (! $this->hideValue()) { + if (!$this->hideValue()) { if (Request::old($this->name)) { $this->formField->val(Request::old($this->name)); } @@ -177,36 +180,30 @@ public function getFormField() return $this->formField; } - /** - * - */ + public function hideValue($value = null) { - if (! is_null($value)) { + if (!is_null($value)) { $this->hideValue = $value; } return $this->hideValue; } - /** - * - */ + public function saveIfEmpty($value = null) { - if (! is_null($value)) { + if (!is_null($value)) { $this->saveIfEmpty = $value; } return $this->saveIfEmpty; } - /** - * - */ + public function noValidate($value = null) { - if (! is_null($value)) { + if (!is_null($value)) { $this->noValidate = $value; } @@ -215,6 +212,7 @@ public function noValidate($value = null) /** * @param array $attributes + * * @return void */ public function setFormElementAttributes(array $attributes) diff --git a/src/Abstractor/Eloquent/FieldFactory.php b/src/Abstractor/Eloquent/FieldFactory.php index 03dbcff..2eace97 100644 --- a/src/Abstractor/Eloquent/FieldFactory.php +++ b/src/Abstractor/Eloquent/FieldFactory.php @@ -1,8 +1,9 @@ 'number', DbalType::SMALLINT => 'number', DbalType::BIGINT => 'number', @@ -44,17 +45,15 @@ class FieldFactory implements FieldAbstractorFactoryContract 'hidden', 'select', 'file', - 'money' - ); + 'money', + ]; public function __construct(FormManagerFactory $factory) { $this->factory = $factory; } - /** - * - */ + public function setColumn(Column $column) { $this->column = $column; @@ -62,9 +61,7 @@ public function setColumn(Column $column) return $this; } - /** - * - */ + public function setConfig(array $config) { $this->config = $config; @@ -72,16 +69,14 @@ public function setConfig(array $config) return $this; } - /** - * - */ + public function get() { $formElement = $this->getFormElement(); $field = new Field($this->column, $formElement, $this->config['name'], $this->config['presentation']); - if (! empty($this->config['validation'])) { + if (!empty($this->config['validation'])) { if ($this->config['validation'] === 'no_validate') { $this->config['no_validate'] = true; } else { @@ -89,11 +84,11 @@ public function get() } } - if (! empty($this->config['functions'])) { + if (!empty($this->config['functions'])) { $field->setFunctions($this->config['functions']); } - if (! empty($this->config['no_validate']) && $this->config['no_validate'] === true) { + if (!empty($this->config['no_validate']) && $this->config['no_validate'] === true) { $field->noValidate(true); } @@ -107,7 +102,7 @@ public function get() if (in_array('required', $rules)) { $field->setFormElementAttributes( [ - 'required' => true + 'required' => true, ] ); } @@ -118,15 +113,15 @@ public function get() protected function getFormElement() { - if (! empty($this->config['form_type'])) { - if (! in_array($this->config['form_type'], $this->databaseTypeToFormType)) { - throw new FactoryException("Unknown form type " . $this->config['form_type']); + if (!empty($this->config['form_type'])) { + if (!in_array($this->config['form_type'], $this->databaseTypeToFormType)) { + throw new FactoryException('Unknown form type '.$this->config['form_type']); } $formElementType = $this->config['form_type']; } else { - if (! array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) { - throw new FactoryException("No form type found for database type " . $this->column->getType()->getName()); + if (!array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) { + throw new FactoryException('No form type found for database type '.$this->column->getType()->getName()); } $formElementType = $this->databaseTypeToFormType[$this->column->getType()->getName()]; @@ -139,7 +134,7 @@ protected function getFormElement() $formElement = $this->factory->get($formElementType, []); - if (! empty($this->config['attr']) && is_array($this->config['attr'])) { + if (!empty($this->config['attr']) && is_array($this->config['attr'])) { $formElement->attr($this->config['attr']); } @@ -150,7 +145,7 @@ protected function getFormElement() } if ($formElementType === 'textarea') { - $formElement->class('form-control ' . config('anavel-crud.text_editor')); + $formElement->class('form-control '.config('anavel-crud.text_editor')); } if ($formElementType === 'checkbox') { @@ -158,7 +153,7 @@ protected function getFormElement() } if (isset($this->config['defaults'])) { - if (! is_array($this->config['defaults'])) { + if (!is_array($this->config['defaults'])) { $formElement->val(transcrud($this->config['defaults'])); } else { $defaults = []; diff --git a/src/Abstractor/Eloquent/Model.php b/src/Abstractor/Eloquent/Model.php index eb0bda5..d05d891 100644 --- a/src/Abstractor/Eloquent/Model.php +++ b/src/Abstractor/Eloquent/Model.php @@ -1,24 +1,23 @@ getConfigValue($action, 'display'); - $customHiddenColumns = $this->getConfigValue($action, 'hide') ? : []; + $customHiddenColumns = $this->getConfigValue($action, 'hide') ?: []; - $columns = array(); - if (! empty($customDisplayedColumns) && is_array($customDisplayedColumns)) { + $columns = []; + if (!empty($customDisplayedColumns) && is_array($customDisplayedColumns)) { foreach ($customDisplayedColumns as $customColumn) { if (strpos($customColumn, '.')) { $customColumnRelation = explode('.', $customColumn); @@ -154,14 +153,14 @@ public function getColumns($action, $withForeignKeys = false) $relationColumns = $nestedRelation->getModelAbstractor()->getColumns($action); - if (! array_key_exists($customColumnRelationFieldName, $relationColumns)) { - throw new AbstractorException("Column " . $customColumnRelationFieldName . " does not exist on relation " . implode('.', $customColumnRelation) . " of model " . $this->getModel()); + if (!array_key_exists($customColumnRelationFieldName, $relationColumns)) { + throw new AbstractorException('Column '.$customColumnRelationFieldName.' does not exist on relation '.implode('.', $customColumnRelation).' of model '.$this->getModel()); } $columns[$customColumn] = $relationColumns[$customColumnRelationFieldName]; } else { - if (! array_key_exists($customColumn, $tableColumns)) { - throw new AbstractorException("Column " . $customColumn . " does not exist on " . $this->getModel()); + if (!array_key_exists($customColumn, $tableColumns)) { + throw new AbstractorException('Column '.$customColumn.' does not exist on '.$this->getModel()); } $columns[$customColumn] = $tableColumns[$customColumn]; @@ -188,8 +187,8 @@ protected function getNestedRelation(Model $modelAbstractor, $relationName) { $relations = $modelAbstractor->getRelations(); - if (! $relations->has($relationName)) { - throw new AbstractorException("Relation " . $relationName . " not configured on " . $modelAbstractor->getModel()); + if (!$relations->has($relationName)) { + throw new AbstractorException('Relation '.$relationName.' not configured on '.$modelAbstractor->getModel()); } $relation = $relations->get($relationName); @@ -210,7 +209,7 @@ public function getRelations() $relations = collect(); - if (! empty($configRelations)) { + if (!empty($configRelations)) { foreach ($configRelations as $relationName => $configRelation) { if (is_int($relationName)) { $relationName = $configRelation; @@ -218,7 +217,7 @@ public function getRelations() $config = []; if ($configRelation !== $relationName) { - if (! is_array($configRelation)) { + if (!is_array($configRelation)) { $config['type'] = $configRelation; } else { $config = $configRelation; @@ -233,7 +232,7 @@ public function getRelations() $secondaryRelations = $relation->getSecondaryRelations(); - if (! $secondaryRelations->isEmpty()) { + if (!$secondaryRelations->isEmpty()) { $relations->put( $relationName, collect(['relation' => $relation, 'secondaryRelations' => $secondaryRelations]) @@ -249,16 +248,18 @@ public function getRelations() /** * @param string|null $arrayKey - * @return array + * * @throws AbstractorException + * + * @return array */ public function getListFields($arrayKey = 'main') { $columns = $this->getColumns('list'); - $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; + $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; - $fields = array(); + $fields = []; foreach ($columns as $name => $column) { $presentation = null; if (array_key_exists($name, $fieldsPresentation)) { @@ -270,7 +271,7 @@ public function getListFields($arrayKey = 'main') 'presentation' => $presentation, 'form_type' => null, 'validation' => null, - 'functions' => null + 'functions' => null, ]; $fields[$arrayKey][] = $this->fieldFactory @@ -284,16 +285,18 @@ public function getListFields($arrayKey = 'main') /** * @param string|null $arrayKey - * @return array + * * @throws AbstractorException + * + * @return array */ public function getDetailFields($arrayKey = 'main') { $columns = $this->getColumns('detail'); - $fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; + $fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; - $fields = array(); + $fields = []; foreach ($columns as $name => $column) { $presentation = null; if (array_key_exists($name, $fieldsPresentation)) { @@ -305,7 +308,7 @@ public function getDetailFields($arrayKey = 'main') 'presentation' => $presentation, 'form_type' => null, 'validation' => null, - 'functions' => null + 'functions' => null, ]; $fields[$arrayKey][] = $this->fieldFactory @@ -318,10 +321,12 @@ public function getDetailFields($arrayKey = 'main') } /** - * @param bool|null $withForeignKeys + * @param bool|null $withForeignKeys * @param string|null $arrayKey - * @return array + * * @throws AbstractorException + * + * @return array */ public function getEditFields($withForeignKeys = false, $arrayKey = 'main') { @@ -329,9 +334,9 @@ public function getEditFields($withForeignKeys = false, $arrayKey = 'main') $this->readConfig('edit'); - $fields = array(); + $fields = []; foreach ($columns as $name => $column) { - if (! in_array($name, $this->getReadOnlyColumns())) { + if (!in_array($name, $this->getReadOnlyColumns())) { $presentation = null; if (array_key_exists($name, $this->fieldsPresentation)) { $presentation = $this->fieldsPresentation[$name]; @@ -342,7 +347,7 @@ public function getEditFields($withForeignKeys = false, $arrayKey = 'main') 'presentation' => $presentation, 'form_type' => null, 'validation' => null, - 'functions' => null + 'functions' => null, ]; $config = $this->setConfig($config, $name); @@ -352,24 +357,24 @@ public function getEditFields($withForeignKeys = false, $arrayKey = 'main') ->setConfig($config) ->get(); - if (! empty($this->instance) && ! empty($this->instance->getAttribute($name))) { + if (!empty($this->instance) && !empty($this->instance->getAttribute($name))) { $field->setValue($this->instance->getAttribute($name)); } $fields[$arrayKey][$name] = $field; - if (! empty($config['form_type']) && $config['form_type'] === 'file') { + if (!empty($config['form_type']) && $config['form_type'] === 'file') { $field = $this->fieldFactory ->setColumn($column) ->setConfig([ - 'name' => $name . '__delete', + 'name' => $name.'__delete', 'presentation' => null, 'form_type' => 'checkbox', 'no_validate' => true, - 'functions' => null + 'functions' => null, ]) ->get(); - $fields[$arrayKey][$name . '__delete'] = $field; + $fields[$arrayKey][$name.'__delete'] = $field; } } } @@ -388,6 +393,7 @@ protected function getReadOnlyColumns() /** * @param string $action + * * @return ElementInterface */ public function getForm($action) @@ -400,13 +406,14 @@ public function getForm($action) /** * @param array $requestForm + * * @return mixed */ public function persist(Request $request) { /** @var \ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager $modelManager */ $modelManager = App::make('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'); - if (! empty($this->instance)) { + if (!empty($this->instance)) { $item = $this->instance; } else { $item = $modelManager->getModelInstance($this->getModel()); @@ -418,10 +425,10 @@ public function persist(Request $request) return; } - if (! empty($fields['main'])) { + if (!empty($fields['main'])) { $skip = null; foreach ($fields['main'] as $key => $field) { - /** @var FieldContract $field */ + /* @var FieldContract $field */ if ($skip === $key) { $skip = null; continue; @@ -443,20 +450,20 @@ public function persist(Request $request) if (get_class($field->getFormField()) === \FormManager\Fields\File::class) { $handleResult = $this->handleField($request, $item, $fields['main'], 'main', $fieldName); - if (! empty($handleResult['skip'])) { + if (!empty($handleResult['skip'])) { $skip = $handleResult['skip']; } - if (! empty($handleResult['requestValue'])) { + if (!empty($handleResult['requestValue'])) { $requestValue = $handleResult['requestValue']; } } - if (! $field->saveIfEmpty() && empty($requestValue)) { + if (!$field->saveIfEmpty() && empty($requestValue)) { continue; } - if (! empty($requestValue) || (empty($requestValue) && ! empty($item->getAttribute($fieldName)))) { + if (!empty($requestValue) || (empty($requestValue) && !empty($item->getAttribute($fieldName)))) { $item->setAttribute( $fieldName, $field->applyFunctions($requestValue) @@ -470,7 +477,7 @@ public function persist(Request $request) $this->setInstance($item); - if (! empty($relations = $this->getRelations())) { + if (!empty($relations = $this->getRelations())) { foreach ($relations as $relationKey => $relation) { if ($relation instanceof Collection) { $input = $request->input($relationKey); @@ -524,7 +531,7 @@ public function getFieldValue($item, $fieldName) } if (empty($relation)) { - return null; + return; } if ($relation instanceof Collection) { diff --git a/src/Abstractor/Eloquent/ModelFactory.php b/src/Abstractor/Eloquent/ModelFactory.php index ba465b0..ac75100 100644 --- a/src/Abstractor/Eloquent/ModelFactory.php +++ b/src/Abstractor/Eloquent/ModelFactory.php @@ -1,13 +1,14 @@ getBySlug($this->slugger->slugify($name)); } - 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); diff --git a/src/Abstractor/Eloquent/Relation/MiniCrud.php b/src/Abstractor/Eloquent/Relation/MiniCrud.php index a2320c5..1def537 100644 --- a/src/Abstractor/Eloquent/Relation/MiniCrud.php +++ b/src/Abstractor/Eloquent/Relation/MiniCrud.php @@ -1,11 +1,11 @@ results)) { return $this->results = $this->eloquentRelation->getResults(); } + return $this->results; } @@ -97,7 +98,7 @@ public function getEditFields($arrayKey = null) } else { $tempFields[$editGroupName] = $editGroup; } - }; + } } } @@ -119,12 +120,12 @@ public function getEditFieldsBase() //Add field for model deletion $config = [ - 'name' => '__delete', + 'name' => '__delete', 'presentation' => 'Delete', - 'form_type' => 'checkbox', - 'no_validate' => true, - 'validation' => null, - 'functions' => null + 'form_type' => 'checkbox', + 'no_validate' => true, + 'validation' => null, + 'functions' => null, ]; /** @var Field $field */ @@ -146,12 +147,12 @@ public function getEditFieldsBase() } $config = [ - 'name' => $columnName, - 'presentation' => $this->name . ' ' . ucfirst(transcrud($columnName)), - 'form_type' => $formType, - 'no_validate' => true, - 'validation' => null, - 'functions' => null + 'name' => $columnName, + 'presentation' => $this->name.' '.ucfirst(transcrud($columnName)), + 'form_type' => $formType, + 'no_validate' => true, + 'validation' => null, + 'functions' => null, ]; $config = $this->setConfig($config, $columnName); @@ -168,15 +169,15 @@ public function getEditFieldsBase() $field = $this->fieldFactory ->setColumn($column) ->setConfig([ - 'name' => $columnName . '__delete', + 'name' => $columnName.'__delete', 'presentation' => null, - 'form_type' => 'checkbox', - 'no_validate' => true, - 'validation' => null, - 'functions' => null + 'form_type' => 'checkbox', + 'no_validate' => true, + 'validation' => null, + 'functions' => null, ]) ->get(); - $fields[$columnName . '__delete'] = $field; + $fields[$columnName.'__delete'] = $field; } } } @@ -186,6 +187,7 @@ public function getEditFieldsBase() /** * @param array|null $relationArray + * * @return mixed */ public function persist(array $relationArray = null, Request $request) @@ -220,12 +222,12 @@ public function persist(array $relationArray = null, Request $request) $fieldName = $field->getName(); if (get_class($field->getFormField()) === \FormManager\Fields\File::class) { - $handleResult = $this->handleField($request, $relationModel, $fieldsBase, $this->name . ".$relationIndex", $fieldName); - if (! empty($handleResult['skip'])) { + $handleResult = $this->handleField($request, $relationModel, $fieldsBase, $this->name.".$relationIndex", $fieldName); + if (!empty($handleResult['skip'])) { $skip = $handleResult['skip']; unset($relationArray[$relationIndex][$skip]); } - if (! empty($handleResult['requestValue'])) { + if (!empty($handleResult['requestValue'])) { $relationArray[$relationIndex][$fieldName] = $handleResult['requestValue']; } } @@ -305,6 +307,7 @@ public function getDisplayType() /** * @param array $fields + * * @return array */ public function addSecondaryRelationFields(array $fields) @@ -317,7 +320,7 @@ public function addSecondaryRelationFields(array $fields) } else { $tempFields[$editGroupName] = $editGroup; } - }; + } } foreach ($fields[$this->name] as $groupKey => $mainFields) { $combinedFields = array_merge($mainFields, $tempFields); diff --git a/src/Abstractor/Eloquent/Relation/MiniCrudPolymorphic.php b/src/Abstractor/Eloquent/Relation/MiniCrudPolymorphic.php index 7c029f2..0a1b704 100644 --- a/src/Abstractor/Eloquent/Relation/MiniCrudPolymorphic.php +++ b/src/Abstractor/Eloquent/Relation/MiniCrudPolymorphic.php @@ -1,14 +1,14 @@ eloquentRelation->getParent()->getKeyName())) { return true; } + return false; } diff --git a/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php b/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php index a614000..81e9eca 100644 --- a/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php +++ b/src/Abstractor/Eloquent/Relation/MiniCrudSingle.php @@ -1,20 +1,19 @@ eloquentRelation->getPlainForeignKey(), $this->eloquentRelation->getPlainMorphType(), - $this->eloquentRelation->getParent()->getKeyName() + $this->eloquentRelation->getParent()->getKeyName(), ]; $this->readConfig('edit'); - if (! empty($columns)) { + if (!empty($columns)) { //Add field for model deletion $config = [ - 'name' => '__delete', + 'name' => '__delete', 'presentation' => 'Delete', - 'form_type' => 'checkbox', - 'no_validate' => true, - 'validation' => null, - 'functions' => null + 'form_type' => 'checkbox', + 'no_validate' => true, + 'validation' => null, + 'functions' => null, ]; /** @var Field $field */ @@ -74,11 +73,11 @@ public function getEditFields($arrayKey = null) $config = [ 'name' => $columnName, - 'presentation' => $this->name . ' ' . ucfirst(transcrud($columnName)), + 'presentation' => $this->name.' '.ucfirst(transcrud($columnName)), 'form_type' => $formType, 'no_validate' => true, 'validation' => null, - 'functions' => null + 'functions' => null, ]; $config = $this->setConfig($config, $columnName); @@ -89,7 +88,7 @@ public function getEditFields($arrayKey = null) ->setConfig($config) ->get(); - if (! empty($result->id)) { + if (!empty($result->id)) { $field->setValue($result->getAttribute($columnName)); } @@ -105,13 +104,14 @@ public function getEditFields($arrayKey = null) /** * @param array|null $relationArray + * * @return mixed */ public function persist(array $relationArray = null, Request $request) { - if (! empty($relationArray)) { + if (!empty($relationArray)) { $currentRelation = $this->eloquentRelation->getResults(); - if (! empty($currentRelation)) { + if (!empty($currentRelation)) { $relationModel = $currentRelation; } else { $relationModel = $this->eloquentRelation->getRelated()->newInstance(); @@ -133,7 +133,7 @@ public function persist(array $relationArray = null, Request $request) $relationModel->setAttribute($fieldKey, $fieldValue); } - if (! $shouldBeSkipped) { + if (!$shouldBeSkipped) { $relationModel->save(); } } diff --git a/src/Abstractor/Eloquent/Relation/Relation.php b/src/Abstractor/Eloquent/Relation/Relation.php index 21df4af..d8715c0 100644 --- a/src/Abstractor/Eloquent/Relation/Relation.php +++ b/src/Abstractor/Eloquent/Relation/Relation.php @@ -1,15 +1,16 @@ setup(); $relatedModelClassName = get_class($this->eloquentRelation->getRelated()); - $relatedmodelRelationsConfig = array(); + $relatedmodelRelationsConfig = []; foreach (config('anavel-crud.models') as $modelConfig) { if (is_array($modelConfig) && array_key_exists('model', $modelConfig) && $relatedModelClassName == $modelConfig['model']) { @@ -79,8 +80,9 @@ public function addSecondaryRelationFields(array $fields) /** @var RelationAbstractorContract $relation */ foreach ($relation->getEditFields($relationKey) as $editGroupName => $editGroup) { $fields[$this->name][$editGroupName] = $editGroup; - }; + } } + return $fields; } @@ -90,14 +92,13 @@ public function getName() } /** - * return null|string + * return null|string. */ public function getDisplay() { - if (! empty($this->config['display'])) { + if (!empty($this->config['display'])) { return $this->config['display']; } - return null; } public function getPresentation() @@ -133,6 +134,7 @@ public function getSecondaryRelations() /** * @param Model $relatedModel + * * @return Relation */ public function setRelatedModel(Model $relatedModel) diff --git a/src/Abstractor/Eloquent/Relation/Select.php b/src/Abstractor/Eloquent/Relation/Select.php index 8a5e79d..e4d9330 100644 --- a/src/Abstractor/Eloquent/Relation/Select.php +++ b/src/Abstractor/Eloquent/Relation/Select.php @@ -1,8 +1,8 @@ getAttribute($display); } + return $displayString; } + return $result->getAttribute($this->config['display']); } @@ -103,11 +109,11 @@ protected function setDisplay($result) protected function getConfig() { return [ - 'name' => $this->eloquentRelation->getForeignKey(), + 'name' => $this->eloquentRelation->getForeignKey(), 'presentation' => $this->getPresentation(), - 'form_type' => 'select', - 'validation' => null, - 'functions' => null + 'form_type' => 'select', + 'validation' => null, + 'functions' => null, ]; } @@ -115,14 +121,16 @@ protected function setFieldValue($field) { $results = $this->eloquentRelation->getResults(); - if (! empty($results)) { + if (!empty($results)) { $field->setValue($results->getKey()); } + return $field; } /** * @param \ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer $dbal + * * @return Column */ protected function getColumn($dbal) diff --git a/src/Abstractor/Eloquent/Relation/SelectMultiple.php b/src/Abstractor/Eloquent/Relation/SelectMultiple.php index da21d05..f1bffcb 100644 --- a/src/Abstractor/Eloquent/Relation/SelectMultiple.php +++ b/src/Abstractor/Eloquent/Relation/SelectMultiple.php @@ -1,10 +1,9 @@ modelManager->getRepository(get_class($this->eloquentRelation->getRelated())); @@ -37,7 +37,7 @@ public function persist(array $relationArray = null, Request $request) $alreadyAssociated = $this->relatedModel->$relationName; $search = []; - if (! empty($relationArray[$relatedKeyName])) { + if (!empty($relationArray[$relatedKeyName])) { $search = $relationArray[$relatedKeyName]; } $results = $repo->pushCriteria( @@ -53,7 +53,7 @@ public function persist(array $relationArray = null, Request $request) $result->save(); } - if (! $missing->isEmpty()) { + if (!$missing->isEmpty()) { foreach ($missing as $result) { $result->$keyName = null; $result->save(); @@ -62,8 +62,6 @@ public function persist(array $relationArray = null, Request $request) } } - - protected function addToArray($arrayKey, $field) { $select = []; @@ -71,6 +69,7 @@ protected function addToArray($arrayKey, $field) $arrayKey = $this->name; } $select[$arrayKey][] = $field; + return $select; } @@ -80,25 +79,23 @@ protected function addToArray($arrayKey, $field) protected function getConfig() { return [ - 'name' => $this->eloquentRelation->getRelated()->getKeyName(), + 'name' => $this->eloquentRelation->getRelated()->getKeyName(), 'presentation' => $this->getPresentation(), - 'form_type' => 'select', - 'attr' => [ - 'multiple' => true + 'form_type' => 'select', + 'attr' => [ + 'multiple' => true, ], 'no_validate' => true, - 'validation' => null, - 'functions' => null + 'validation' => null, + 'functions' => null, ]; } - - protected function setFieldValue($field) { $results = $this->eloquentRelation->getResults(); - if (! $results->isEmpty()) { + if (!$results->isEmpty()) { $values = []; foreach ($results as $result) { @@ -107,12 +104,13 @@ protected function setFieldValue($field) $field->setValue($values); } + return $field; } - /** * @param \ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer $dbal + * * @return Column */ protected function getColumn($dbal) diff --git a/src/Abstractor/Eloquent/Relation/SelectMultipleManyToMany.php b/src/Abstractor/Eloquent/Relation/SelectMultipleManyToMany.php index 05d8a44..2b00fab 100644 --- a/src/Abstractor/Eloquent/Relation/SelectMultipleManyToMany.php +++ b/src/Abstractor/Eloquent/Relation/SelectMultipleManyToMany.php @@ -1,10 +1,8 @@ eloquentRelation->getRelated()->getKeyName()]; if (in_array('', $array)) { $array = []; @@ -39,6 +38,7 @@ public function persist(array $relationArray = null, Request $request) /** * @param \ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer $dbal + * * @return Column */ protected function getColumn($dbal) diff --git a/src/Abstractor/Eloquent/Relation/Traits/CheckRelationCompatibility.php b/src/Abstractor/Eloquent/Relation/Traits/CheckRelationCompatibility.php index d33ea7d..6c6d484 100644 --- a/src/Abstractor/Eloquent/Relation/Traits/CheckRelationCompatibility.php +++ b/src/Abstractor/Eloquent/Relation/Traits/CheckRelationCompatibility.php @@ -1,4 +1,5 @@ eloquentRelation), $this->compatibleEloquentRelations)) { - throw new RelationException(get_class($this->eloquentRelation)." eloquent relation is not compatible with ".$this->getType()." type"); + if (!in_array(get_class($this->eloquentRelation), $this->compatibleEloquentRelations)) { + throw new RelationException(get_class($this->eloquentRelation).' eloquent relation is not compatible with '.$this->getType().' type'); } } } diff --git a/src/Abstractor/Eloquent/Relation/Traits/CheckRelationConfig.php b/src/Abstractor/Eloquent/Relation/Traits/CheckRelationConfig.php index 7cf9482..5d8ba4c 100644 --- a/src/Abstractor/Eloquent/Relation/Traits/CheckRelationConfig.php +++ b/src/Abstractor/Eloquent/Relation/Traits/CheckRelationConfig.php @@ -1,4 +1,5 @@ langs as $key => $lang) { $tempFields = []; foreach ($columns as $columnName => $column) { @@ -66,11 +66,11 @@ public function getEditFields($arrayKey = null) $config = [ 'name' => $columnName, - 'presentation' => ucfirst(transcrud($columnName)) . ' [' . $lang . ']', + 'presentation' => ucfirst(transcrud($columnName)).' ['.$lang.']', 'form_type' => $formType, 'no_validate' => true, 'validation' => null, - 'functions' => null + 'functions' => null, ]; $config = $this->setConfig($config, $columnName); @@ -102,11 +102,12 @@ public function getEditFields($arrayKey = null) /** * @param array|null $relationArray + * * @return mixed */ public function persist(array $relationArray = null, Request $request) { - if (! empty($relationArray)) { + if (!empty($relationArray)) { $currentTranslations = $this->eloquentRelation->getResults(); $currentTranslations = $currentTranslations->keyBy('locale'); diff --git a/src/Abstractor/Eloquent/RelationFactory.php b/src/Abstractor/Eloquent/RelationFactory.php index 8308627..9004787 100644 --- a/src/Abstractor/Eloquent/RelationFactory.php +++ b/src/Abstractor/Eloquent/RelationFactory.php @@ -1,11 +1,12 @@ self::SELECT, 'Illuminate\Database\Eloquent\Relations\BelongsToMany' => self::SELECT_MULTIPLE_MANY_TO_MANY, 'Illuminate\Database\Eloquent\Relations\HasMany' => self::SELECT_MULTIPLE, @@ -26,10 +27,10 @@ class RelationFactory implements RelationAbstractorFactoryContract 'Illuminate\Database\Eloquent\Relations\HasOne' => self::SELECT, 'Illuminate\Database\Eloquent\Relations\HasOneOrMany' => self::SELECT_MULTIPLE, 'Illuminate\Database\Eloquent\Relations\MorphMany' => self::MINI_CRUD_POLYMORPHIC, - 'Illuminate\Database\Eloquent\Relations\MorphOne' => self::MINI_CRUD_SINGLE - ); + 'Illuminate\Database\Eloquent\Relations\MorphOne' => self::MINI_CRUD_SINGLE, + ]; - protected $typesMap = array( + protected $typesMap = [ self::SELECT => 'Anavel\Crud\Abstractor\Eloquent\Relation\Select', self::SELECT_MULTIPLE => 'Anavel\Crud\Abstractor\Eloquent\Relation\SelectMultiple', self::SELECT_MULTIPLE_MANY_TO_MANY => 'Anavel\Crud\Abstractor\Eloquent\Relation\SelectMultipleManyToMany', @@ -37,8 +38,8 @@ class RelationFactory implements RelationAbstractorFactoryContract self::MINI_CRUD => 'Anavel\Crud\Abstractor\Eloquent\Relation\MiniCrud', self::MINI_CRUD_SINGLE => 'Anavel\Crud\Abstractor\Eloquent\Relation\MiniCrudSingle', self::MINI_CRUD_POLYMORPHIC => 'Anavel\Crud\Abstractor\Eloquent\Relation\MiniCrudPolymorphic', - self::TRANSLATION => 'Anavel\Crud\Abstractor\Eloquent\Relation\Translation' - ); + self::TRANSLATION => 'Anavel\Crud\Abstractor\Eloquent\Relation\Translation', + ]; protected $modelManager; protected $fieldFactory; @@ -53,7 +54,7 @@ public function __construct(ModelManager $modelManager, FieldFactoryContract $fi { $this->modelManager = $modelManager; $this->fieldFactory = $fieldFactory; - $this->config = array(); + $this->config = []; } public function setModel($model) @@ -72,11 +73,11 @@ public function setConfig(array $config) public function get($name) { - if (! empty($this->config) && ! empty($this->config['name'])) { + if (!empty($this->config) && !empty($this->config['name'])) { $name = $this->config['name']; } - if (! method_exists($this->model, $name)) { - throw new FactoryException("Relation " . $name . " does not exist on " . get_class($this->model)); + if (!method_exists($this->model, $name)) { + throw new FactoryException('Relation '.$name.' does not exist on '.get_class($this->model)); } $relationInstance = $this->model->$name(); @@ -84,8 +85,8 @@ public function get($name) if (empty($this->config['type'])) { - if (! array_key_exists($relationEloquentType, $this->eloquentTypeToRelationType)) { - throw new FactoryException($relationEloquentType . " relation not supported"); + if (!array_key_exists($relationEloquentType, $this->eloquentTypeToRelationType)) { + throw new FactoryException($relationEloquentType.' relation not supported'); } $type = $this->eloquentTypeToRelationType[$relationEloquentType]; @@ -93,8 +94,8 @@ public function get($name) $type = $this->config['type']; } - if (! array_key_exists($type, $this->typesMap)) { - throw new FactoryException("Unexpected relation type: " . $type); + if (!array_key_exists($type, $this->typesMap)) { + throw new FactoryException('Unexpected relation type: '.$type); } $this->config['name'] = $name; diff --git a/src/Abstractor/Eloquent/Traits/HandleFiles.php b/src/Abstractor/Eloquent/Traits/HandleFiles.php index 2a127d4..687f1e4 100644 --- a/src/Abstractor/Eloquent/Traits/HandleFiles.php +++ b/src/Abstractor/Eloquent/Traits/HandleFiles.php @@ -1,28 +1,27 @@ slug . DIRECTORY_SEPARATOR; - $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR .config('anavel-crud.uploads_path')); - $modelPath = $basePath . $modelFolder; + $modelFolder = $this->slug.DIRECTORY_SEPARATOR; + $basePath = base_path(DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.config('anavel-crud.uploads_path')); + $modelPath = $basePath.$modelFolder; $skip = null; $requestValue = null; - if (! empty($fields["{$fieldName}__delete"])) { + 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"))) { + if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { $adapter = new Local($basePath); $filesystem = new Filesystem($adapter); if ($filesystem->has($item->$fieldName)) { @@ -34,39 +33,40 @@ protected function handleField(Request $request, $item, array $fields, $groupNam $fieldName, null ); + return [ - 'skip' => $skip + 'skip' => $skip, ]; } } - if ($request->hasFile($groupName .'.'.$fieldName)) { - $fileName = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME); - $extension = pathinfo($request->file($groupName .'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); + if ($request->hasFile($groupName.'.'.$fieldName)) { + $fileName = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_FILENAME); + $extension = pathinfo($request->file($groupName.'.'.$fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); - $fileName = uniqid() . '_' . slugify($fileName); - if (! empty($extension)) { - $fileName .= '.' . $extension; + $fileName = uniqid().'_'.slugify($fileName); + if (!empty($extension)) { + $fileName .= '.'.$extension; } - $request->file($groupName .'.'.$fieldName)->move( + $request->file($groupName.'.'.$fieldName)->move( $modelPath, $fileName ); - $requestValue = $modelFolder . $fileName; - } elseif (! empty($request->file($groupName .'.'.$fieldName)) && ! $request->file($groupName .'.'.$fieldName)->isValid()) { - throw new \Exception($request->file($groupName .'.'.$fieldName)->getErrorMessage()); + $requestValue = $modelFolder.$fileName; + } elseif (!empty($request->file($groupName.'.'.$fieldName)) && !$request->file($groupName.'.'.$fieldName)->isValid()) { + throw new \Exception($request->file($groupName.'.'.$fieldName)->getErrorMessage()); } //Avoid losing the existing filename if the user doesn't change it: - if (empty($requestValue) && (! empty($item->$fieldName))) { + if (empty($requestValue) && (!empty($item->$fieldName))) { $requestValue = $item->$fieldName; } return [ 'requestValue' => $requestValue, - 'skip' => $skip + 'skip' => $skip, ]; } } diff --git a/src/Abstractor/Eloquent/Traits/ModelFields.php b/src/Abstractor/Eloquent/Traits/ModelFields.php index 7b1ef1e..7c84e20 100644 --- a/src/Abstractor/Eloquent/Traits/ModelFields.php +++ b/src/Abstractor/Eloquent/Traits/ModelFields.php @@ -1,10 +1,7 @@ fieldsPresentation = $this->getConfigValue('fields_presentation') ? : []; - $this->formTypes = $this->getConfigValue($action, 'form_types') ? : []; - $this->validationRules = $this->getConfigValue($action, 'validation') ? : []; - $this->functions = $this->getConfigValue($action, 'functions') ? : []; - $this->defaults = $this->getConfigValue($action, 'defaults') ? : []; + $this->fieldsPresentation = $this->getConfigValue('fields_presentation') ?: []; + $this->formTypes = $this->getConfigValue($action, 'form_types') ?: []; + $this->validationRules = $this->getConfigValue($action, 'validation') ?: []; + $this->functions = $this->getConfigValue($action, 'functions') ?: []; + $this->defaults = $this->getConfigValue($action, 'defaults') ?: []; } /** - * @param array $config + * @param array $config * @param string $columnName + * * @return array */ public function setConfig(array $config, $columnName) diff --git a/src/Abstractor/Exceptions/AbstractorException.php b/src/Abstractor/Exceptions/AbstractorException.php index 4d93f21..b4765ea 100644 --- a/src/Abstractor/Exceptions/AbstractorException.php +++ b/src/Abstractor/Exceptions/AbstractorException.php @@ -1,4 +1,5 @@ app->bind( 'Anavel\Crud\Contracts\Abstractor\FieldFactory', function () { - return new FieldAbstractorFactory(new FormFactory); + return new FieldAbstractorFactory(new FormFactory()); } ); @@ -79,7 +79,7 @@ function () { $this->app->bind( 'Anavel\Crud\Contracts\Form\Generator', function () { - return new FormGenerator(new FormFactory); + return new FormGenerator(new FormFactory()); } ); @@ -135,7 +135,7 @@ public function isActive() } /** - * Registers types that Doctrine doesn's support by default + * Registers types that Doctrine doesn's support by default. */ protected function registerDoctrineTypeMappings() { diff --git a/src/Http/Controllers/HomeController.php b/src/Http/Controllers/HomeController.php index 6da1df6..214a280 100644 --- a/src/Http/Controllers/HomeController.php +++ b/src/Http/Controllers/HomeController.php @@ -1,11 +1,12 @@ getByName($modelSlug); $config = $modelAbstractor->getConfig(); - if (! array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) { + if (!array_key_exists('authorize', $config) || ($config['authorize'] === true && Gate::allows('adminIndex', $modelAbstractor->getInstance()) || $config['authorize'] === false)) { return new RedirectResponse(route('anavel-crud.model.index', $modelSlug)); } } diff --git a/src/Http/Controllers/ModelController.php b/src/Http/Controllers/ModelController.php index 1da4422..76bf964 100644 --- a/src/Http/Controllers/ModelController.php +++ b/src/Http/Controllers/ModelController.php @@ -1,16 +1,17 @@ getConfig()) && (! empty($config['controller']))) { + if (!$this instanceof CustomController) { //Avoid infinite recursion + if (array_key_exists('controller', $config = $modelAbstractor->getConfig()) && (!empty($config['controller']))) { /** @var CustomController $controller */ $controller = App::make($config['controller']); $controller->setAbstractor($modelAbstractor); + return $controller; } } - return null; } /** * Display a listing of the resource. * * @param Request $request - * @param string $model + * @param string $model + * * @return Response */ public function index(Request $request, $model) @@ -62,14 +65,14 @@ public function index(Request $request, $model) $this->authorizeMethod($modelAbstractor, 'adminIndex'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->index($request, $model); } $repository = $this->modelManager->getRepository($modelAbstractor->getModel()); if ($request->has('search')) { - $searchByColumns = array(); + $searchByColumns = []; foreach ($modelAbstractor->getListFields()['main'] as $field) { $searchByColumns[] = $field->getName(); @@ -86,14 +89,15 @@ public function index(Request $request, $model) return view('anavel-crud::pages.index', [ 'abstractor' => $modelAbstractor, - 'items' => $items + 'items' => $items, ]); } /** * Show the form for creating a new resource. * - * @param string $model + * @param string $model + * * @return Response */ public function create($model) @@ -102,7 +106,7 @@ public function create($model) $this->authorizeMethod($modelAbstractor, 'adminCreate'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->create($model); } @@ -110,8 +114,8 @@ public function create($model) return view('anavel-crud::pages.create', [ 'abstractor' => $modelAbstractor, - 'form' => $form, - 'relations' => $modelAbstractor->getRelations() + 'form' => $form, + 'relations' => $modelAbstractor->getRelations(), ]); } @@ -119,7 +123,8 @@ public function create($model) * Store a newly created resource in storage. * * @param Request $request - * @param string $model + * @param string $model + * * @return Response */ public function store(Request $request, $model) @@ -128,7 +133,7 @@ public function store(Request $request, $model) $this->authorizeMethod($modelAbstractor, 'adminCreate'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->store($request, $model); } @@ -143,7 +148,7 @@ public function store(Request $request, $model) 'type' => 'success', 'icon' => 'fa-check', 'title' => trans('anavel-crud::messages.alert_success_model_store_title'), - 'text' => trans('anavel-crud::messages.alert_success_model_store_text') + 'text' => trans('anavel-crud::messages.alert_success_model_store_text'), ]); return redirect()->route('anavel-crud.model.index', $model); @@ -152,8 +157,9 @@ public function store(Request $request, $model) /** * Display the specified resource. * - * @param string $model - * @param int $id + * @param string $model + * @param int $id + * * @return Response */ public function show($model, $id) @@ -162,7 +168,7 @@ public function show($model, $id) $this->authorizeMethod($modelAbstractor, 'adminShow'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->show($model, $id); } @@ -171,15 +177,16 @@ public function show($model, $id) return view('anavel-crud::pages.show', [ 'abstractor' => $modelAbstractor, - 'item' => $item + 'item' => $item, ]); } /** * Show the form for editing the specified resource. * - * @param string $model - * @param int $id + * @param string $model + * @param int $id + * * @return Response */ public function edit($model, $id) @@ -189,7 +196,7 @@ public function edit($model, $id) $this->authorizeMethod($modelAbstractor, 'adminUpdate'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->edit($model, $id); } @@ -199,9 +206,9 @@ public function edit($model, $id) return view('anavel-crud::pages.edit', [ 'abstractor' => $modelAbstractor, - 'form' => $form, - 'item' => $item, - 'relations' => $modelAbstractor->getRelations() + 'form' => $form, + 'item' => $item, + 'relations' => $modelAbstractor->getRelations(), ]); } @@ -209,8 +216,9 @@ public function edit($model, $id) * Update the specified resource in storage. * * @param Request $request - * @param string $model - * @param int $id + * @param string $model + * @param int $id + * * @return Response */ public function update(Request $request, $model, $id) @@ -219,7 +227,7 @@ public function update(Request $request, $model, $id) $this->authorizeMethod($modelAbstractor, 'adminUpdate'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->update($request, $model, $id); } @@ -234,7 +242,7 @@ public function update(Request $request, $model, $id) 'type' => 'success', 'icon' => 'fa-check', 'title' => trans('anavel-crud::messages.alert_success_model_update_title'), - 'text' => trans('anavel-crud::messages.alert_success_model_update_text') + 'text' => trans('anavel-crud::messages.alert_success_model_update_text'), ]); return redirect()->route('anavel-crud.model.edit', [$model, $id]); @@ -244,8 +252,9 @@ public function update(Request $request, $model, $id) * Remove the specified resource from storage. * * @param Request $request - * @param string $model - * @param int $id + * @param string $model + * @param int $id + * * @return Response */ public function destroy(Request $request, $model, $id) @@ -254,7 +263,7 @@ public function destroy(Request $request, $model, $id) $this->authorizeMethod($modelAbstractor, 'adminDestroy'); - if (! empty($customController = $this->customController($modelAbstractor))) { + if (!empty($customController = $this->customController($modelAbstractor))) { return $customController->destroy($request, $model, $id); } @@ -267,7 +276,7 @@ public function destroy(Request $request, $model, $id) 'type' => 'success', 'icon' => 'fa-check', 'title' => trans('anavel-crud::messages.alert_success_model_destroy_title'), - 'text' => trans('anavel-crud::messages.alert_success_model_destroy_text') + 'text' => trans('anavel-crud::messages.alert_success_model_destroy_text'), ]); return redirect()->route('anavel-crud.model.index', $model); diff --git a/src/Http/Form/Generator.php b/src/Http/Form/Generator.php index 10b96ed..7367902 100644 --- a/src/Http/Form/Generator.php +++ b/src/Http/Form/Generator.php @@ -1,20 +1,14 @@ 'number', DbalType::STRING => 'text', DbalType::TEXT => 'textarea', @@ -43,13 +37,13 @@ class Generator implements GeneratorContract 'email', 'password', 'hidden', - 'select' - ); + 'select', + ]; public function __construct(FactoryInterface $factory) { $this->factory = $factory; - $this->fields = array(); + $this->fields = []; } public function setModelFields(array $fields) @@ -90,11 +84,11 @@ public function getForm($action) 'action' => $action, 'enctype' => 'multipart/form-data', 'method' => 'post', - 'class' => 'form-horizontal' + 'class' => 'form-horizontal', ]); - $formFields = array(); + $formFields = []; foreach ($this->fields as $fieldGroupName => $fieldGroup) { $tempFields = $this->addFormFields($fieldGroup, $fieldGroupName); $formFields[key($tempFields)] = $this->factory->get('group', [$tempFields[key($tempFields)]]); @@ -108,7 +102,7 @@ public function getForm($action) public function getValidationRules() { - $rules = array(); + $rules = []; foreach ($this->fields as $fieldGroupName => $fieldGroup) { foreach ($fieldGroup as $fieldKey => $field) { @@ -126,12 +120,13 @@ public function getValidationRules() /** * @param array $fields * @param $key + * * @return array */ protected function addFormFields(array $fields, $key) { - $formFields = array(); - $tempFields = array(); + $formFields = []; + $tempFields = []; foreach ($fields as $fieldKey => $field) { if (is_array($field)) { @@ -142,13 +137,14 @@ protected function addFormFields(array $fields, $key) } } $formFields[$key] = $tempFields; + return $formFields; } protected function addValidationRules(array $fields, $key) { - $rules = array(); - $tempFields = array(); + $rules = []; + $tempFields = []; foreach ($fields as $fieldKey => $field) { if (is_array($field)) { $group = $this->addValidationRules($field, $fieldKey); @@ -158,6 +154,7 @@ protected function addValidationRules(array $fields, $key) } } $rules[$key] = $tempFields; + return $rules; } } diff --git a/src/Http/routes.php b/src/Http/routes.php index 31a1e61..ad796d9 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -2,49 +2,49 @@ Route::group( [ - 'prefix' => 'crud', - 'namespace' => 'Anavel\Crud\Http\Controllers' + 'prefix' => 'crud', + 'namespace' => 'Anavel\Crud\Http\Controllers', ], function () { Route::get('/', [ 'as' => 'anavel-crud.home', - 'uses' => 'HomeController@index' + 'uses' => 'HomeController@index', ]); // Model CRUD routes Route::get('{model}', [ 'as' => 'anavel-crud.model.index', - 'uses' => 'ModelController@index' + 'uses' => 'ModelController@index', ]); Route::get('{model}/create', [ 'as' => 'anavel-crud.model.create', - 'uses' => 'ModelController@create' + 'uses' => 'ModelController@create', ]); Route::post('{model}', [ 'as' => 'anavel-crud.model.store', - 'uses' => 'ModelController@store' + 'uses' => 'ModelController@store', ]); Route::get('{model}/{id}', [ 'as' => 'anavel-crud.model.show', - 'uses' => 'ModelController@show' + 'uses' => 'ModelController@show', ]); Route::get('{model}/{id}/edit', [ 'as' => 'anavel-crud.model.edit', - 'uses' => 'ModelController@edit' + 'uses' => 'ModelController@edit', ]); Route::put('{model}/{id}', [ 'as' => 'anavel-crud.model.update', - 'uses' => 'ModelController@update' + 'uses' => 'ModelController@update', ]); Route::delete('{model}/{id}', [ 'as' => 'anavel-crud.model.destroy', - 'uses' => 'ModelController@destroy' + 'uses' => 'ModelController@destroy', ]); // Batch actions diff --git a/src/Providers/ViewComposersServiceProvider.php b/src/Providers/ViewComposersServiceProvider.php index 3737143..f82d097 100644 --- a/src/Providers/ViewComposersServiceProvider.php +++ b/src/Providers/ViewComposersServiceProvider.php @@ -1,4 +1,5 @@ getSidebarItems(); $view->with([ - 'menuItems' => $menuItems, - 'headerName' => config('anavel-crud.name') + 'menuItems' => $menuItems, + 'headerName' => config('anavel-crud.name'), ]); } @@ -64,7 +65,7 @@ private function getSidebarItems() } catch (\Exception $e) { continue; } - $menuItems[$modelName]['isActive'] = $item['isActive']; + $menuItems[$modelName]['isActive'] = $item['isActive']; $menuItems[$modelName]['name'] = $item['name']; $menuItems[$modelName]['items'][] = $item; } @@ -73,13 +74,16 @@ private function getSidebarItems() usort($menuItems, function ($itemA, $itemB) { return strcmp($itemA['name'], $itemB['name']); }); + return $menuItems; } /** * @param $modelName - * @return array + * * @throws \Exception + * + * @return array */ private function getModelItem($modelName) { @@ -96,9 +100,9 @@ private function getModelItem($modelName) } $item = [ - 'route' => route('anavel-crud.model.index', $modelAbstractor->getSlug()), - 'name' => $modelAbstractor->getName(), - 'isActive' => $isActive + 'route' => route('anavel-crud.model.index', $modelAbstractor->getSlug()), + 'name' => $modelAbstractor->getName(), + 'isActive' => $isActive, ]; return $item; diff --git a/src/View/Presenters/Paginator.php b/src/View/Presenters/Paginator.php index 1749a90..4c81ca6 100644 --- a/src/View/Presenters/Paginator.php +++ b/src/View/Presenters/Paginator.php @@ -1,4 +1,5 @@ wrongConfig = require __DIR__ . '/../../wrong-config.php'; + $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $this->fieldFactoryMock = $this->mock('Anavel\Crud\Contracts\Abstractor\FieldFactory'); $this->modelManagerMock = Mockery::mock('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'); $this->requestMock = $this->mock('Illuminate\Http\Request'); - $this->modelManagerMock->shouldReceive('getAbstractionLayer')->andReturn($this->dbalMock = $this->mock('ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer')); + $this->modelManagerMock->shouldReceive('getAbstractionLayer')->andReturn($this->dbalMock = $this->mock('ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer')); $this->getClassMock = PHPMockery::mock('Anavel\Crud\Abstractor\Eloquent\Relation\Traits', 'get_class'); @@ -54,7 +52,7 @@ public function setUp() public function buildRelation() { - $config = require __DIR__ . '/../../config.php'; + $config = require __DIR__.'/../../config.php'; $this->sut = new MiniCrudPolymorphic( $config['Users']['relations']['group'], $this->modelManagerMock, @@ -79,7 +77,6 @@ public function test_throws_exception_when_class_not_compatible() $this->buildRelation(); } - public function test_get_edit_fields_returns_array() { $this->modelAbstractorMock->shouldReceive('getColumns')->times(1)->andReturn(['columname' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column'), '__delete' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column')]); @@ -136,7 +133,7 @@ public function test_persist_with_no_old_results() 'field' => 1, 'otherField' => 3, 'someOtherField' => 3, - ] + ], ]; $this->relationMock->shouldReceive('getForeignKey', 'getPlainMorphType', 'getMorphClass'); @@ -182,7 +179,7 @@ public function test_persist_with_old_results() 'id' => 1, 'otherField' => 3, 'someOtherField' => 3, - ] + ], ]; $this->relationMock->shouldReceive('getForeignKey', 'getPlainMorphType', 'getMorphClass'); diff --git a/tests/Abstractor/Eloquent/MiniCrudSingleTest.php b/tests/Abstractor/Eloquent/MiniCrudSingleTest.php index 71940ab..1733699 100644 --- a/tests/Abstractor/Eloquent/MiniCrudSingleTest.php +++ b/tests/Abstractor/Eloquent/MiniCrudSingleTest.php @@ -1,4 +1,5 @@ wrongConfig = require __DIR__ . '/../../wrong-config.php'; + $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $this->fieldFactoryMock = $this->mock('Anavel\Crud\Contracts\Abstractor\FieldFactory'); @@ -50,7 +50,7 @@ public function setUp() //We can not do the construct in the setup because get_class needs to be mocked differently each time public function buildRelation() { - $config = require __DIR__ . '/../../config.php'; + $config = require __DIR__.'/../../config.php'; $this->sut = new MiniCrudSingle( $config['Users']['relations']['group'], $this->modelManagerMock, @@ -76,7 +76,6 @@ public function test_throws_exception_when_class_not_compatible() $this->buildRelation(); } - public function test_get_edit_fields_returns_array() { $this->relationMock->shouldReceive('getRelated', 'getPlainForeignKey', 'getPlainMorphType', 'getParent', @@ -86,7 +85,7 @@ public function test_get_edit_fields_returns_array() $this->modelAbstractorMock->shouldReceive('getColumns')->times(1)->andReturn( [ 'columname' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column'), - '__delete' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column') + '__delete' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column'), ] ); diff --git a/tests/Abstractor/Eloquent/MiniCrudTest.php b/tests/Abstractor/Eloquent/MiniCrudTest.php index 5202bfd..fd5d350 100644 --- a/tests/Abstractor/Eloquent/MiniCrudTest.php +++ b/tests/Abstractor/Eloquent/MiniCrudTest.php @@ -1,4 +1,5 @@ wrongConfig = require __DIR__ . '/../../wrong-config.php'; + $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $this->fieldFactoryMock = $this->mock('Anavel\Crud\Contracts\Abstractor\FieldFactory'); $this->modelManagerMock = Mockery::mock('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'); - $this->modelManagerMock->shouldReceive('getAbstractionLayer')->andReturn($this->dbalMock = $this->mock('ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer')); + $this->modelManagerMock->shouldReceive('getAbstractionLayer')->andReturn($this->dbalMock = $this->mock('ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer')); $this->requestMock = $this->mock('Illuminate\Http\Request'); $this->getClassMock = PHPMockery::mock('Anavel\Crud\Abstractor\Eloquent\Relation\Traits', @@ -52,7 +52,7 @@ public function setUp() //We can not do the construct in the setup because get_class needs to be mocked differently each time public function buildRelation() { - $config = require __DIR__ . '/../../config.php'; + $config = require __DIR__.'/../../config.php'; $this->sut = new MiniCrud( $config['Users']['relations']['group'], $this->modelManagerMock, @@ -77,7 +77,6 @@ public function test_throws_exception_when_class_not_compatible() $this->buildRelation(); } - public function test_get_edit_fields_returns_array() { $this->modelAbstractorMock->shouldReceive('getColumns')->times(1)->andReturn(['columname' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column'), '__delete' => $columnMock = $this->mock('Doctrine\DBAL\Schema\Column')]); @@ -125,18 +124,17 @@ public function test_get_edit_fields_returns_array() $this->assertCount(2, $fields['group']['idValue']); // Mocked field, plus delete checkbox $this->assertArrayHasKey('columname', $fields['group']['idValue']); $this->assertInstanceOf('Anavel\Crud\Contracts\Abstractor\Field', $fields['group']['idValue']['columname']); - } public function test_persist_with_no_old_results() { $inputArray = [ '0' => [ - 'field' => 1, - 'otherField' => 3, + 'field' => 1, + 'otherField' => 3, 'someOtherField' => 3, - 'relationName' => [] - ] + 'relationName' => [], + ], ]; $this->relationMock->shouldReceive('getForeignKey'); @@ -175,15 +173,15 @@ public function test_persist_with_old_results() $inputArray = [ '0' => [ - 'id' => 1, - 'otherField' => 3, + 'id' => 1, + 'otherField' => 3, 'someOtherField' => 3, ], '1' => [ - 'id' => 1, - 'otherField' => 3, + 'id' => 1, + 'otherField' => 3, 'someOtherField' => 3, - ] + ], ]; $this->relationMock->shouldReceive('getForeignKey'); diff --git a/tests/Abstractor/Eloquent/ModelFactoryTest.php b/tests/Abstractor/Eloquent/ModelFactoryTest.php index 38c7b2d..7d7cf3e 100644 --- a/tests/Abstractor/Eloquent/ModelFactoryTest.php +++ b/tests/Abstractor/Eloquent/ModelFactoryTest.php @@ -1,14 +1,14 @@ modelManagerMock = $this->mock('ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'); $this->relationMock = $this->mock('Anavel\Crud\Contracts\Abstractor\RelationFactory'); @@ -41,7 +41,7 @@ public function test_implements_model__factory_interface() public function test_throws_exception_when_model_not_found() { - $this->setExpectedException('Exception', "Model chompy not found on configuration" ); + $this->setExpectedException('Exception', 'Model chompy not found on configuration'); $model = $this->sut->getBySlug('chompy'); } diff --git a/tests/Abstractor/Eloquent/ModelTest.php b/tests/Abstractor/Eloquent/ModelTest.php index 02b8b16..6972f9f 100644 --- a/tests/Abstractor/Eloquent/ModelTest.php +++ b/tests/Abstractor/Eloquent/ModelTest.php @@ -1,16 +1,16 @@ dbalMock = $this->mock('ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer'); $this->relationFactoryMock = $this->mock('Anavel\Crud\Contracts\Abstractor\RelationFactory'); @@ -41,7 +41,7 @@ public function setUp() $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(); + $this->sut = \Mockery::mock(Model::class, [$config['Users'], $this->dbalMock, $this->relationFactoryMock, $this->fieldFactoryMock, $this->generatorMock])->makePartial(); } public function test_implements_model_interface() @@ -57,7 +57,7 @@ public function test_returns_list_fields_as_array() 'id' => $this->columnMock, 'username' => $this->columnMock, 'fullname' => $this->columnMock, - 'active' => $this->columnMock + 'active' => $this->columnMock, ]); $this->dbalMock->shouldReceive('getTableForeignKeys') ->andReturn([]); @@ -90,7 +90,7 @@ public function test_returns_list_fields_as_array_with_key() 'id' => $this->columnMock, 'username' => $this->columnMock, 'fullname' => $this->columnMock, - 'active' => $this->columnMock + 'active' => $this->columnMock, ]); $this->dbalMock->shouldReceive('getTableForeignKeys') ->andReturn([]); @@ -125,7 +125,7 @@ public function test_returns_detail_fields_as_array() 'password' => $this->columnMock, 'fullname' => $this->columnMock, 'info' => $this->columnMock, - 'active' => $this->columnMock + 'active' => $this->columnMock, ]); $this->dbalMock->shouldReceive('getTableForeignKeys') ->andReturn([]); @@ -162,7 +162,7 @@ public function test_returns_detail_fields_as_array_with_key() 'password' => $this->columnMock, 'fullname' => $this->columnMock, 'info' => $this->columnMock, - 'active' => $this->columnMock + 'active' => $this->columnMock, ]); $this->dbalMock->shouldReceive('getTableForeignKeys') ->andReturn([]); @@ -233,7 +233,7 @@ public function test_returns_edit_fields_as_array() 'presentation' => null, 'form_type' => null, 'validation' => null, - 'functions' => null + 'functions' => null, ]) ->andReturn($this->fieldFactoryMock); @@ -245,7 +245,7 @@ public function test_returns_edit_fields_as_array() 'form_type' => 'email', 'validation' => 'required|email', 'functions' => null, - 'defaults' => 'Chompy' + 'defaults' => 'Chompy', ]) ->andReturn($this->fieldFactoryMock); @@ -275,11 +275,11 @@ public function test_returns_edit_fields_as_array() // Wit this one we check that file fields generate an extra __delete one $fielMock5->shouldReceive('setConfig') ->with([ - 'name' => 'image__delete', - 'presentation' => null, - 'form_type' => 'checkbox', + 'name' => 'image__delete', + 'presentation' => null, + 'form_type' => 'checkbox', 'no_validate' => true, - 'functions' => null, + 'functions' => null, ]) ->andReturn($this->fieldFactoryMock); @@ -294,7 +294,6 @@ public function test_returns_edit_fields_as_array() $this->assertArrayHasKey('username', $fields['main']); $this->assertInstanceOf('Anavel\Crud\Contracts\Abstractor\Field', $fields['main']['username']); - } public function test_returns_edit_fields_as_array_with_key() @@ -353,7 +352,6 @@ public function test_returns_relations_as_collection() foreach ($relations as $relation) { $this->assertInstanceOf('Anavel\Crud\Contracts\Abstractor\Relation', $relation); } - } public function test_returns_relations_as_multidimensional_collection() @@ -376,7 +374,6 @@ public function test_returns_relations_as_multidimensional_collection() $this->assertInstanceOf('Anavel\Crud\Contracts\Abstractor\Relation', $secondaryRelation); } } - } public function test_get_form() @@ -420,7 +417,6 @@ public function test_get_form() $this->assertInstanceOf('FormManager\ElementInterface', $form); } - public function test_get_form_with_instance() { $this->generatorMock->shouldReceive('setModelFields', 'setRelatedModelFields') @@ -496,7 +492,7 @@ public function test_persist() $fieldMock, $fieldMock, $fieldMock, - ] + ], ]); $this->sut->shouldReceive('getRelations')->andReturn(collect(['group' => $relationMock = $this->mock('\Anavel\Crud\Abstractor\Eloquent\Relation\Relation')])); diff --git a/tests/Abstractor/Eloquent/RelationFactoryTest.php b/tests/Abstractor/Eloquent/RelationFactoryTest.php index 9c00f67..b95793f 100644 --- a/tests/Abstractor/Eloquent/RelationFactoryTest.php +++ b/tests/Abstractor/Eloquent/RelationFactoryTest.php @@ -1,15 +1,15 @@ sut->setConfig($config['Users']['relations']['translations']); $this->setExpectedException('Anavel\Crud\Abstractor\Exceptions\FactoryException', 'Unexpected relation type: fake'); diff --git a/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php b/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php index 23cf13e..a204b77 100644 --- a/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php +++ b/tests/Abstractor/Eloquent/SelectMultipleManyToManyTest.php @@ -1,30 +1,28 @@ wrongConfig = require __DIR__ . '/../../wrong-config.php'; + $config = require __DIR__.'/../../config.php'; + $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); @@ -96,7 +94,7 @@ public function test_get_edit_fields_returns_array_of_fields_with_proper_key() public function test_persist() { $inputArray = ['id' => [1, 3, 4]]; - $config = require __DIR__ . '/../../config.php'; + $config = require __DIR__.'/../../config.php'; $relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $relationMock->shouldReceive('getRelated')->andReturn($relationMock); @@ -127,8 +125,6 @@ public function test_throws_exception_if_display_is_not_set_in_config() ); } - - public function test_throws_exception_if_name_is_not_set_in_config() { $this->setExpectedException('Anavel\Crud\Abstractor\Exceptions\RelationException', 'Relation name should be set'); diff --git a/tests/Abstractor/Eloquent/SelectMultipleTest.php b/tests/Abstractor/Eloquent/SelectMultipleTest.php index 466894c..fe66c0d 100644 --- a/tests/Abstractor/Eloquent/SelectMultipleTest.php +++ b/tests/Abstractor/Eloquent/SelectMultipleTest.php @@ -1,29 +1,27 @@ wrongConfig = require __DIR__ . '/../../wrong-config.php'; + $config = require __DIR__.'/../../config.php'; + $this->wrongConfig = require __DIR__.'/../../wrong-config.php'; $this->relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); @@ -119,8 +117,6 @@ public function test_throws_exception_if_display_is_not_set_in_config() ); } - - public function test_throws_exception_if_name_is_not_set_in_config() { $this->setExpectedException('Anavel\Crud\Abstractor\Exceptions\RelationException', 'Relation name should be set'); diff --git a/tests/Abstractor/Eloquent/SelectTest.php b/tests/Abstractor/Eloquent/SelectTest.php index dc84891..91065d0 100644 --- a/tests/Abstractor/Eloquent/SelectTest.php +++ b/tests/Abstractor/Eloquent/SelectTest.php @@ -1,4 +1,5 @@ wrongConfig = require __DIR__ . '/../../wrong-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'); diff --git a/tests/Abstractor/Eloquent/TranslationTest.php b/tests/Abstractor/Eloquent/TranslationTest.php index be684d0..4547f78 100644 --- a/tests/Abstractor/Eloquent/TranslationTest.php +++ b/tests/Abstractor/Eloquent/TranslationTest.php @@ -1,4 +1,5 @@ relationMock = $this->mock('Illuminate\Database\Eloquent\Relations\Relation'); $this->fieldFactoryMock = $this->mock('Anavel\Crud\Contracts\Abstractor\FieldFactory'); @@ -86,7 +85,7 @@ public function test_get_edit_fields_returns_array_of_fields_with_proper_key() 'id' => $columnMock, 'user_id' => $columnMock, 'locale' => $columnMock, - 'bio' => $columnMock + 'bio' => $columnMock, ]); $fields = $this->sut->getEditFields(); @@ -99,7 +98,7 @@ public function test_get_edit_fields_returns_array_of_fields_with_proper_key() $this->assertArrayHasKey('en', $fields['translations']); $this->assertInternalType('array', $fields['translations']['gl']); - foreach($fields['translations']['gl'] as $element) { + foreach ($fields['translations']['gl'] as $element) { $this->assertInstanceOf('Anavel\Crud\Contracts\Abstractor\Field', $element); } } @@ -108,13 +107,13 @@ public function test_persist_with_no_results() { $inputArray = [ 'es' => [ - 'locale' => 'es', + 'locale' => 'es', 'otherField' => 'something', ], 'en' => [ - 'locale' => 'en', + 'locale' => 'en', 'otherField' => '', - ] + ], ]; $this->relationMock->shouldReceive('getResults')->andReturn(collect()); @@ -132,13 +131,13 @@ public function test_persist_with_old_results() { $inputArray = [ 'es' => [ - 'locale' => 'es', + 'locale' => 'es', 'otherField' => 'something', ], 'en' => [ - 'locale' => 'en', + 'locale' => 'en', 'otherField' => '', - ] + ], ]; $modelMock = $this->mock(UserTranslations::class); diff --git a/tests/Http/Form/GeneratorTest.php b/tests/Http/Form/GeneratorTest.php index fedfa36..b101682 100644 --- a/tests/Http/Form/GeneratorTest.php +++ b/tests/Http/Form/GeneratorTest.php @@ -1,9 +1,10 @@ morphTo(); } -} \ No newline at end of file +} diff --git a/tests/Models/Post.php b/tests/Models/Post.php index 12be00b..ac187aa 100644 --- a/tests/Models/Post.php +++ b/tests/Models/Post.php @@ -1,9 +1,7 @@ belongsTo(User::class, 'user_id'); } -} \ No newline at end of file +} diff --git a/tests/Models/Role.php b/tests/Models/Role.php index d0dea55..7918c85 100644 --- a/tests/Models/Role.php +++ b/tests/Models/Role.php @@ -1,9 +1,7 @@ belongsToMany(User::class, 'roles_users'); } -} \ No newline at end of file +} diff --git a/tests/Models/User.php b/tests/Models/User.php index da22068..adbba9f 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -1,9 +1,7 @@ belongsToMany(Role::class, 'roles_users'); } -} \ No newline at end of file +} diff --git a/tests/Models/UserGroup.php b/tests/Models/UserGroup.php index 1ceeddc..8490d46 100644 --- a/tests/Models/UserGroup.php +++ b/tests/Models/UserGroup.php @@ -1,9 +1,7 @@ hasMany(User::class, 'user_group_id'); } -} \ No newline at end of file +} diff --git a/tests/Models/UserTranslations.php b/tests/Models/UserTranslations.php index 27bba0d..932607e 100644 --- a/tests/Models/UserTranslations.php +++ b/tests/Models/UserTranslations.php @@ -1,12 +1,9 @@ set('database.default', 'sqlite'); $app['config']->set('database.connections.sqlite', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'prefix' => '' + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', ]); $app['config']->set('anavel.translation_languages', ['gl', 'en', 'es']); @@ -63,7 +63,6 @@ protected function getPackageProviders($app) return []; } - public function mock($className) { return Mockery::mock($className); @@ -78,7 +77,7 @@ public function test_running_migration() { $migrations = \DB::select('SELECT * FROM migrations'); - $fi = new \FilesystemIterator(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR .self::MIGRATIONS_PATH, \FilesystemIterator::SKIP_DOTS); + $fi = new \FilesystemIterator(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.self::MIGRATIONS_PATH, \FilesystemIterator::SKIP_DOTS); $this->assertCount(iterator_count($fi), $migrations); } diff --git a/tests/config.php b/tests/config.php index b2a5ac9..c65810f 100644 --- a/tests/config.php +++ b/tests/config.php @@ -9,45 +9,45 @@ 'soft_deletes' => true, 'fields_presentation' => [ 'active' => 'Is Active?', - 'role_id' => 'Role' + 'role_id' => 'Role', ], 'relations_presentation' => [ 'translations' => 'Translations', - 'posts' => 'Published posts' + 'posts' => 'Published posts', ], 'relations' => [ 'translations' => [ 'type' => 'translation', - 'name' => 'translations' + 'name' => 'translations', ], 'group' => [ 'type' => 'select', 'name' => 'group', - 'display' => 'title' + 'display' => 'title', ], 'posts' => [ 'type' => 'select-multiple', 'name' => 'posts', - 'display' => 'title' + 'display' => 'title', ], 'photos' => [ 'type' => 'select-multiple', 'name' => 'photos', - 'display' => 'title' + 'display' => 'title', ], 'roles' => [ 'type' => 'select-multiple-many-to-many', 'name' => 'roles', - 'display' => 'name' - ] + 'display' => 'name', + ], ], 'list' => [ 'display' => ['id', 'username', 'fullname', 'active'], - 'hide' => [] + 'hide' => [], ], 'detail' => [ 'display' => ['id', 'username', 'password', 'fullname', 'info', 'active'], - 'hide' => [] + 'hide' => [], ], 'edit' => [ 'display' => ['id', 'username', 'password', 'image'], @@ -56,22 +56,22 @@ 'username' => 'Chompy', 'info' => [ 'key' => 'Value', - 'otherKey' => 'Other value' - ] + 'otherKey' => 'Other value', + ], ], 'form_types' => [ 'username' => 'email', 'password' => 'password', - 'image' => 'file' + 'image' => 'file', ], 'validation' => [ 'username' => 'required|email', - 'password' => 'required|min:8' + 'password' => 'required|min:8', ], 'functions' => [ 'fullname' => 'slugify', - 'password' => 'bcrypt' - ] - ] - ] + 'password' => 'bcrypt', + ], + ], + ], ]; diff --git a/tests/migrations/2015_11_12_155600_create_tables.php b/tests/migrations/2015_11_12_155600_create_tables.php index 57ef8d8..900623e 100644 --- a/tests/migrations/2015_11_12_155600_create_tables.php +++ b/tests/migrations/2015_11_12_155600_create_tables.php @@ -1,4 +1,5 @@ 'App\Post', 'Users' => [ - 'model' => 'App\User', - 'icon' => 'fa-database', - 'soft_deletes' => true, + 'model' => 'App\User', + 'icon' => 'fa-database', + 'soft_deletes' => true, 'fields_presentation' => [ - 'active' => 'Is Active?', - 'role_id' => 'Role' + 'active' => 'Is Active?', + 'role_id' => 'Role', ], 'relations_presentation' => [ 'translations' => 'Translations', - 'posts' => 'Published posts' + 'posts' => 'Published posts', ], 'relations' => [ 'translations' => [ @@ -33,32 +33,32 @@ ], 'roles' => [ 'type' => 'select-multiple-many-to-many', - 'name' => 'roles' - ] + 'name' => 'roles', + ], ], 'list' => [ 'display' => ['id', 'username', 'fullname', 'active'], - 'hide' => [] + 'hide' => [], ], 'detail' => [ 'display' => ['id', 'username', 'password', 'fullname', 'info', 'active'], - 'hide' => [] + 'hide' => [], ], 'edit' => [ - 'display' => ['id', 'username', 'password'], - 'hide' => [], + 'display' => ['id', 'username', 'password'], + 'hide' => [], 'form_types' => [ 'username' => 'email', - 'password' => 'password' + 'password' => 'password', ], 'validation' => [ 'username' => 'required|email', - 'password' => 'required|min:8' + 'password' => 'required|min:8', ], 'functions' => [ 'fullname' => 'slugify', - 'password' => 'bcrypt' - ] - ] - ] + 'password' => 'bcrypt', + ], + ], + ], ];