Skip to content

Commit

Permalink
Fix return context in modelHasState
Browse files Browse the repository at this point in the history
  • Loading branch information
orobogenius committed Jan 25, 2019
1 parent 56753e0 commit 5136750
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Statable/Statable.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ protected function applyStates($states, $relation = null)
$model = $relation ? $relation->getModel() : $this;

foreach (Arr::wrap($states) as $state) {
if ($method = $this->modelHasState($model, $state)) {
$method = $this->getMethodName($state);

if ($this->modelHasState($model, $method)) {
$attributes[] = $this->expandAttributes(
$model->$method()
);
Expand Down Expand Up @@ -76,13 +78,11 @@ protected function getMethodName($state)
*/
protected function modelHasState($model, $state)
{
return tap($this->getMethodName($state), function ($method) use ($model, $state) {
throw_unless(
method_exists($model, $method),
InvalidArgumentException::class,
sprintf('Unable to locate [%s] state for [%s].', $state, static::class)
);
});
return throw_unless(
method_exists($model, $state),
InvalidArgumentException::class,
sprintf('Unable to locate [%s] state for [%s].', $state, get_class($model))
);
}

/**
Expand Down

0 comments on commit 5136750

Please sign in to comment.