From 5136750f13326f2b6f576bfa82378886db088e20 Mon Sep 17 00:00:00 2001 From: Lucky Ozoka Date: Fri, 25 Jan 2019 23:07:16 +0100 Subject: [PATCH] Fix return context in modelHasState --- src/Statable/Statable.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Statable/Statable.php b/src/Statable/Statable.php index b5acdd2..0c759a3 100644 --- a/src/Statable/Statable.php +++ b/src/Statable/Statable.php @@ -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() ); @@ -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)) + ); } /**