Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
khanzadimahdi committed Jun 21, 2019
1 parent d33c4a5 commit f7ed296
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Traits/HasStamps.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public function scopeUnstamped($query, $stampName)
private function getStampBehavior($method)
{
$behavior = null;
$stampName = null;
$lowerCaseMethod = strtolower($method);

$prefixes = [
'is' => 'isStampedBy',
Expand All @@ -149,26 +151,28 @@ private function getStampBehavior($method)

foreach ($stampsName as $key => $name) {
foreach ($prefixes as $prefix => $methodName) {
if ($prefix.$key == $method) {
if (strtolower($prefix.$name) == $lowerCaseMethod) {
$behavior = $methodName;
$stampName = $name;
break;
}
}
}

return $behavior;
return empty($behavior) ? false : [$behavior, $stampName];
}

private function getStampScope($method)
{
$scope = null;
$lowerCaseMethod = strtolower($method);

$stampKeys = array_keys($this->getStamps());

foreach ($stampKeys as $key) {
if ($method == $key) {
if ($lowerCaseMethod == $key) {
$scope = 'stamped';
} elseif ($method == 'un'.strtolower($key)) {
} elseif ($lowerCaseMethod == strtolower('un'.$key)) {
$scope = 'unstamped';
}
}
Expand All @@ -189,8 +193,10 @@ public function __call($method, $parameters)
return $this->$method(...$parameters);
}

if ($methodName = $this->getStampBehavior($method)) {
return $this->$methodName(...$parameters);
if ($info = $this->getStampBehavior($method)) {
$methodName = $info[0];
$stampName = $info[1];
return $this->$methodName($stampName);
}

if ($methodName = $this->getStampScope($method)) {
Expand Down

0 comments on commit f7ed296

Please sign in to comment.