Lines
88.88%
8 / 9
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Home | 88.88% | 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 | #[\Override] | |
| 24 | public function readResponse( | |
| 25 | RequestInterface $request, | |
| 26 | ResponseInterface $response, | |
| 27 | array $args | |
| 28 | ) { | |
| 29 | $homeUrl = Helper\HomeUrl::sanitizeUrl(static::getHomeUrl($request)); | |
| 30 | if ($homeUrl === '') { | |
| 31 | throw new Exception\HomeNotFound(); | |
| 32 | } | |
| 33 | ||
| 34 | return Render::withLastModified($response, time(), '0')->withRedirect($homeUrl, 301); | |
| 35 | } | |
| 36 | ||
| 37 | public static function getHomeUrl(RequestInterface $request): string | |
| 38 | { | |
| 39 | $cookies = $request->getCookieParams(); | |
| 40 | $homeUrl = TicketprinterClient::getHomeUrl(); | |
| 41 | if (array_key_exists(TicketprinterClient::HOME_URL_COOKIE_NAME, $cookies) && ! $homeUrl) { | |
| 42 | $homeUrl = $cookies[TicketprinterClient::HOME_URL_COOKIE_NAME]; | |
| 43 | } | |
| 44 | return $homeUrl; | |
| 45 | } | |
| 46 | } |