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

RedirectResponseHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 17
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildRedirectResponse() 0 8 2
A __construct() 0 3 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