Skip to content

Commit

Permalink
fix components initialize arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-aliraqi committed Sep 15, 2020
1 parent 0257de7 commit b2a1e94
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 43 deletions.
5 changes: 2 additions & 3 deletions src/Components/BaseComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ public function __construct($resource)
/**
* Initialized the input arguments.
*
* @param null $name
* @param null $value
* @param mixed ...$arguments
* @return $this
*/
abstract public function init($name = null, $value = null);
abstract public function init(...$arguments);

/**
* Set the default label for the input.
Expand Down
12 changes: 5 additions & 7 deletions src/Components/CheckboxComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ public function __construct($resource)
/**
* Initialized the input arguments.
*
* @param null $name
* @param null $value
* @param bool $checked
* @param mixed ...$arguments
* @return $this
*/
public function init($name = null, $value = null, $checked = false)
public function init(...$arguments)
{
$this->name($name);
$this->name($name = $arguments[0] ?? null);

$this->value($value ?: old($name));
$this->value($arguments[1] ?? null ?: old($name));

$this->checked = $checked;
$this->checked = $arguments[2] ?? false;

$this->setDefaultLabel();

Expand Down
9 changes: 4 additions & 5 deletions src/Components/FileComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ class FileComponent extends BaseComponent
/**
* Initialized the input arguments.
*
* @param null $name
* @param null $value
* @param mixed ...$arguments
* @return $this
*/
public function init($name = null)
public function init(...$arguments)
{
$this->name($name);
$this->name($name = $arguments[0] ?? null);

$this->setDefaultLabel($name);

Expand All @@ -41,4 +40,4 @@ public function multiple($multiple = true)

return $this;
}
}
}
14 changes: 6 additions & 8 deletions src/Components/RadioComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ class RadioComponent extends BaseComponent
/**
* Initialized the input arguments.
*
* @param null $name
* @param null $value
* @param bool $checked
* @param mixed ...$arguments
* @return $this
*/
public function init($name = null, $value = null, $checked = false)
public function init(...$arguments)
{
$this->name($name);
$this->name($name = $arguments[0] ?? null);

$this->value($value ?: old($name));
$this->value($arguments[1] ?? null ?: old($name));

$this->checked = $checked;
$this->checked = $arguments[2] ?? false;

$this->setDefaultLabel($name);

Expand Down Expand Up @@ -63,4 +61,4 @@ protected function viewComposer()
'checked' => $this->checked,
];
}
}
}
13 changes: 6 additions & 7 deletions src/Components/SelectComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ class SelectComponent extends BaseComponent
/**
* Initialized the input arguments.
*
* @param null $name
* @param null $value
* @param mixed ...$arguments
* @return $this
*/
public function init($name = null, $options = [], $value = null)
public function init(...$arguments)
{
$this->name($name);
$this->name($name = $arguments[0] ?? null);

$this->value($value ?: old($name) ?: request($name));
$this->value($arguments[2] ?? null ?: old($name) ?: request($name));

$this->options = $options;
$this->options = $arguments[1] ?? [];

$this->setDefaultLabel($name);

Expand Down Expand Up @@ -79,4 +78,4 @@ protected function viewComposer()
'options' => $this->options,
];
}
}
}
12 changes: 5 additions & 7 deletions src/Components/SubmitComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ class SubmitComponent extends BaseComponent
/**
* Initialized the input arguments.
*
* @param null $label
* @param null $name
* @param null $value
* @param mixed ...$arguments
* @return $this
*/
public function init($label = null, $name = null)
public function init(...$arguments)
{
$this->name($name);
$this->label($label);
$this->name($arguments[1] ?? null);
$this->label($arguments[0] ?? null);

return $this;
}
Expand Down Expand Up @@ -105,4 +103,4 @@ protected function viewComposer()
'className' => $this->className,
];
}
}
}
11 changes: 5 additions & 6 deletions src/Components/TextualComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ abstract class TextualComponent extends BaseComponent
/**
* Initialized the input arguments.
*
* @param null $name
* @param null $value
* @param mixed ...$arguments
* @return $this
*/
public function init($name = null, $value = null)
public function init(...$arguments)
{
$this->name($name);
$this->name($name = $arguments[0] ?? null);

$this->value($value ?: old($name));
$this->value($arguments[1] ?? null ?: old($name));

$this->setDefaultLabel();

Expand All @@ -29,4 +28,4 @@ public function init($name = null, $value = null)

return $this;
}
}
}

0 comments on commit b2a1e94

Please sign in to comment.