Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
Home | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
5.03 | |
0.00% |
0 / 1 |
readResponse | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getHomeUrl | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | * @package Zmsticketprinter |
6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
7 | * |
8 | */ |
9 | |
10 | namespace BO\Zmsticketprinter; |
11 | |
12 | use BO\Slim\Render; |
13 | use BO\Zmsclient\Ticketprinter as TicketprinterClient; |
14 | use Psr\Http\Message\RequestInterface; |
15 | use Psr\Http\Message\ResponseInterface; |
16 | |
17 | class Home extends BaseController |
18 | { |
19 | /** |
20 | * @SuppressWarnings(UnusedFormalParameter) |
21 | * @return ResponseInterface |
22 | */ |
23 | public function readResponse( |
24 | RequestInterface $request, |
25 | ResponseInterface $response, |
26 | array $args |
27 | ) { |
28 | $homeUrl = static::getHomeUrl($request); |
29 | if (! $homeUrl) { |
30 | throw new Exception\HomeNotFound(); |
31 | } |
32 | |
33 | return Render::withLastModified($response, time(), '0')->withRedirect($homeUrl, 301); |
34 | } |
35 | |
36 | public function getHomeUrl(RequestInterface $request): string |
37 | { |
38 | $cookies = $request->getCookieParams(); |
39 | $homeUrl = TicketprinterClient::getHomeUrl(); |
40 | if (array_key_exists(TicketprinterClient::HOME_URL_COOKIE_NAME, $cookies) && ! $homeUrl) { |
41 | $homeUrl = $cookies[TicketprinterClient::HOME_URL_COOKIE_NAME]; |
42 | } |
43 | return $homeUrl; |
44 | } |
45 | } |