for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Jasny\Router\Middleware;
use Jasny\Router;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Route to error page on error
*/
class ErrorPage
{
* Router
* @var Router
protected $router = null;
* Class constructor
*
* @param Router $routes
$routes
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter $italy is not defined by the method finale(...).
$italy
finale(...)
/** * @param array $germany * @param array $island * @param array $italy */ function finale($germany, $island) { return "2:1"; }
The most likely cause is that the parameter was removed, but the annotation was not.
public function __construct(Router $router)
$this->router = $router;
}
* Get router connected to middleware
* @return Router
public function getRouter()
return $this->router;
* Run middleware action
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callback $next
* @return ResponseInterface
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null)
if ($next && !is_callable($next)) {
throw new \InvalidArgumentException("'next' should be a callback");
$response = $next ? call_user_func($next, $request, $response) : $response;
$status = $response->getStatusCode();
if (!$this->isErrorStatus($status)) return $response;
Adding braces to control structures avoids accidental mistakes as your code changes:
// Without braces (not recommended) if (true) doSomething(); // Recommended if (true) { doSomething(); }
$uri = $request->getUri()->withPath("/$status");
$request = $request->withUri($uri, true);
return $this->getRouter()->run($request, $response);
* Detect if response has error status code
* @param int $status
* @return boolean
protected function isErrorStatus($status)
return $status >= 400 && $status < 600;