Lines 0.00% 0 / 6
Methods 0.00% 0 / 1
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 withRedirect 0.00% 0 / 6 0.00% 0 / 1 12
14class Response extends \Slim\Psr7\Response
15{
16    /**
17     * This method prepares the response object to return an HTTP Redirect
18     * response to the client.
19     *
20     * @param  string|UriInterface $url    The redirect destination.
21     * @param  int|null            $status The redirect HTTP status code.
22     *
23     * @return Response
24     */
25    public function withRedirect($url, ?int $status = null): Response
26    {
27        /** @var Response $redirectResponse */
28        $redirectResponse = $this->withHeader('Location', (string) $url);
29
30        if ($status !== null) {
31            return $redirectResponse->withStatus($status);
32        }
33
34        if ($this->getStatusCode() === StatusCodeInterface::STATUS_OK) {
35            return $redirectResponse->withStatus(StatusCodeInterface::STATUS_FOUND);
36        }
37
38        // return with a former defined status code
39        return $redirectResponse;
40    }
41}