Skip to content

Commit

Permalink
Applied fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
ablunier authored and StyleCIBot committed Oct 24, 2016
1 parent 997b9aa commit 540228e
Show file tree
Hide file tree
Showing 68 changed files with 589 additions and 570 deletions.
5 changes: 2 additions & 3 deletions config/anavel-crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'date' => 'd/m/Y',
'time' => 'H:i',
'datetime' => 'd/m/Y H:i:s',
'number' => '%.2f'
'number' => '%.2f',
],

/*
Expand Down Expand Up @@ -143,7 +143,6 @@
]
*/
],
'modelsGroups' =>
[/*'Blog' => ['Blog Posts', 'Blog Tags']*/]
'modelsGroups' => [/*'Blog' => ['Blog Posts', 'Blog Tags']*/],

];
2 changes: 1 addition & 1 deletion lang/ca/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
2 changes: 1 addition & 1 deletion lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
2 changes: 1 addition & 1 deletion lang/es/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
2 changes: 1 addition & 1 deletion lang/gl/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
14 changes: 7 additions & 7 deletions src/Abstractor/ConfigurationReader.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Anavel\Crud\Abstractor;

trait ConfigurationReader
{
public function getConfigValue()
{
if (! property_exists($this, 'config') || ! is_array($this->config) || empty($this->config)) {
return null;
if (!property_exists($this, 'config') || !is_array($this->config) || empty($this->config)) {
return;
}

$params = func_get_args();
Expand All @@ -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];
Expand All @@ -29,7 +31,5 @@ public function getConfigValue()
if (array_key_exists($lastParam, $nestedConfig)) {
return $nestedConfig[$lastParam];
}

return null;
}
}
40 changes: 19 additions & 21 deletions src/Abstractor/Eloquent/Field.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Anavel\Crud\Abstractor\Eloquent;

use Anavel\Crud\Contracts\Abstractor\Field as FieldAbstractorContract;
Expand Down Expand Up @@ -32,8 +33,8 @@ public function __construct(Column $column, FormManagerField $formField, $name,
$this->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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
}
Expand All @@ -149,6 +151,7 @@ public function getValue()

/**
* @param array $options
*
* @return void
*/
public function setOptions(array $options)
Expand All @@ -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));
}
Expand All @@ -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;
}

Expand All @@ -215,6 +212,7 @@ public function noValidate($value = null)

/**
* @param array $attributes
*
* @return void
*/
public function setFormElementAttributes(array $attributes)
Expand Down
45 changes: 20 additions & 25 deletions src/Abstractor/Eloquent/FieldFactory.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Anavel\Crud\Abstractor\Eloquent;

use Anavel\Crud\Contracts\Abstractor\FieldFactory as FieldAbstractorFactoryContract;
use Anavel\Crud\Abstractor\Exceptions\FactoryException;
use Anavel\Crud\Contracts\Abstractor\FieldFactory as FieldAbstractorFactoryContract;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type as DbalType;
use FormManager\FactoryInterface as FormManagerFactory;
Expand All @@ -27,7 +28,7 @@ class FieldFactory implements FieldAbstractorFactoryContract
/**
* @var array
*/
protected $databaseTypeToFormType = array(
protected $databaseTypeToFormType = [
DbalType::INTEGER => 'number',
DbalType::SMALLINT => 'number',
DbalType::BIGINT => 'number',
Expand All @@ -44,56 +45,50 @@ 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;

return $this;
}

/**
*
*/

public function setConfig(array $config)
{
$this->config = $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 {
$field->setValidationRules($this->config['validation']);
}
}

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);
}

Expand All @@ -107,7 +102,7 @@ public function get()
if (in_array('required', $rules)) {
$field->setFormElementAttributes(
[
'required' => true
'required' => true,
]
);
}
Expand All @@ -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()];
Expand All @@ -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']);
}

Expand All @@ -150,15 +145,15 @@ 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') {
$formElement->class('checkbox');
}

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 = [];
Expand Down
Loading

0 comments on commit 540228e

Please sign in to comment.