Skip to content

Commit

Permalink
review: methods name
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-rahimi committed Apr 11, 2023
1 parent 16d8ef5 commit f96dc5b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
10 changes: 4 additions & 6 deletions src/Controllers/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ public static function make(?string $title = null): Group
return new self($title);
}

public function addInput($input): Group
public function input(Input $input): Group
{
if ($input instanceof Input) {
$this->inputs[] = $input->get();
}
$this->inputs[] = $input->get();

return $this;
}

public function addInputs(array $inputs): Group
public function inputs(array $inputs): Group
{
foreach ($inputs as $input) {
$this->addInput($input);
$this->input($input);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Makers/FormMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(string $routeNameOrUrl, array $routeNeeded, string $
return $this;
}

public function addGroup(Group $group): FormMaker
public function group(Group $group): FormMaker
{
$this->groups[] = $group->get();

Expand Down
20 changes: 10 additions & 10 deletions src/Controllers/Makers/TableMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public function __construct(array $headers, array $config)
return $this;
}

public function addHeader(string $key, string $label): TableMaker
public function header(string $key, string $label): TableMaker
{
$this->headers[$key] = $label;

return $this;
}

public function addHeaders(array $headers): TableMaker
public function headers(array $headers): TableMaker
{
foreach ($headers as $key => $label) {
$this->addHeader($key, $label);
$this->header($key, $label);
}

return $this;
Expand All @@ -48,38 +48,38 @@ public function paginate(LengthAwarePaginator $paginate, callable $mapForRows =

$this->rows = [];
if ($mapForRows) {
$this->addRows($paginate->map($mapForRows));
$this->rows($paginate->map($mapForRows));
} else {
$this->addRows($paginate);
$this->rows($paginate);
}

return $this;
}

public function addAction(Button $button): self
public function action(Button $button): self
{
$this->actions[] = $button->get();

return $this;
}

public function addRows($rows): self
public function rows($rows): self
{
foreach ($rows as $row) {
$this->addRow($row);
$this->row($row);
}

return $this;
}

public function addRow($row): self
public function row($row): self
{
if (!is_array($row)) {
$row = $row->toArray();
}

if (isset($row[0]) && (is_array($row[0]) || is_object($row[0]))) {
$this->addRows($row);
$this->rows($row);
} else {
$this->rows[] = $row;
}
Expand Down
15 changes: 4 additions & 11 deletions src/Traits/InputTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,17 @@ public function step(?string $step = null): self
return $this;
}

public function addOption($option): self
public function option(Option $option): self
{
if ($option instanceof Option) {
$this->options[] = $option->get();
} elseif (is_array($option)) {
$this->options[] = Option::make($option['label'])
->value($option['value'])
->selected($option['selected'] ?? false)
->get();
}
$this->options[] = $option->get();

return $this;
}

public function addOptions(array $options): self
public function options(array $options): self
{
foreach ($options as $option) {
$this->addOption($option);
$this->option($option);
}

return $this;
Expand Down

0 comments on commit f96dc5b

Please sign in to comment.