Completed
Push — develop ( 4dbcf6...912f28 )
by Alejandro
17s queued 11s
created

RedirectResponseHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Util;
6
7
use Fig\Http\Message\StatusCodeInterface;
8
use Laminas\Diactoros\Response\RedirectResponse;
9
use Psr\Http\Message\ResponseInterface;
10
use Shlinkio\Shlink\Core\Options\UrlShortenerOptions;
11
12
use function sprintf;
13
14
class RedirectResponseHelper implements RedirectResponseHelperInterface
15
{
16
    private UrlShortenerOptions $options;
17
18
    public function __construct(UrlShortenerOptions $options)
19
    {
20
        $this->options = $options;
21
    }
22
23
    public function buildRedirectResponse(string $location): ResponseInterface
24
    {
25
        $statusCode = $this->options->redirectStatusCode();
26
        $headers = $statusCode === StatusCodeInterface::STATUS_FOUND ? [] : [
27
            'Cache-Control' => sprintf('private,max-age=%s', $this->options->redirectCacheLifetime()),
28
        ];
29
30
        return new RedirectResponse($location, $statusCode, $headers);
31
    }
32
}
33