Skip to content

Commit

Permalink
refactor: use private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 18, 2023
1 parent cdb3bf1 commit a54095b
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,55 +302,24 @@ public function runRequired(string $position = 'before')
}
}

foreach ($filtersClass[$position] as $className) {
$class = new $className();

if (! $class instanceof FilterInterface) {
throw FilterException::forIncorrectInterface(get_class($class));
}

if ($position === 'before') {
$result = $class->before(
$this->request,
$this->argumentsClass[$className] ?? null
);

if ($result instanceof RequestInterface) {
$this->request = $result;

continue;
}

// If the response object was sent back,
// then send it and quit.
if ($result instanceof ResponseInterface) {
// short circuit - bypass any other filters
return $result;
}
// Ignore an empty result
if (empty($result)) {
continue;
}
if ($position === 'before') {
$result = $this->runBefore($filtersClass);

// If the response object was sent back,
// then send it and quit.
if ($result instanceof ResponseInterface) {
// short circuit - bypass any other filters
return $result;
}

if ($position === 'after') {
$result = $class->after(
$this->request,
$this->response,
$this->argumentsClass[$className] ?? null
);

if ($result instanceof ResponseInterface) {
$this->response = $result;
return $result;
}

continue;
}
}
if ($position === 'after') {
$result = $this->runAfter($filtersClass);
}

return $position === 'before' ? $this->request : $this->response;
return $result;
}

/**
Expand Down

0 comments on commit a54095b

Please sign in to comment.