Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Redirector
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 to
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 back
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPreviousUrl
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Http;
6
7class Redirector
8{
9    public function __construct(
10        protected Request $request,
11        protected Response $response,
12        protected UrlGeneratorInterface $url
13    ) {
14    }
15
16    /**
17     * Redirects to a path, generating a full URL
18     */
19    public function to(string $path, int $status = 302, array $headers = []): Response
20    {
21        return $this->response->redirectTo($this->url->to($path), $status, $headers);
22    }
23
24    public function back(int $status = 302, array $headers = []): Response
25    {
26        return $this->to($this->getPreviousUrl(), $status, $headers);
27    }
28
29    protected function getPreviousUrl(): string
30    {
31        if ($header = $this->request->getHeader('referer')) {
32            return array_pop($header);
33        }
34
35        return '/';
36    }
37}