Test Failed
Pull Request — master (#494)
by
unknown
03:32
created

WebControllerService::getRedirectResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Service;
6
7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Yiisoft\Http\Header;
10
use Yiisoft\Http\Status;
11
use Yiisoft\Router\UrlGeneratorInterface;
12
13
final class WebControllerService
14
{
15
    public function __construct(
16
        private ResponseFactoryInterface $responseFactory,
17
        private UrlGeneratorInterface $urlGenerator
18
    ) {
19
    }
20
21
    public function getRedirectResponse(string $url): ResponseInterface
22
    {
23
        return $this->responseFactory
24
            ->createResponse(Status::FOUND)
25
            ->withHeader(Header::LOCATION, $this->urlGenerator->generate($url));
26
    }
27
28
    public function getNotFoundResponse(): ResponseInterface
29
    {
30
        return $this->responseFactory
31
            ->createResponse(Status::NOT_FOUND);
32
    }
33
}
34