Passed
Pull Request — master (#138)
by Sergei
11:25
created

WebControllerService::getNotFoundResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\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
    private ResponseFactoryInterface $responseFactory;
16
    private UrlGeneratorInterface $urlGenerator;
17
18
    public function __construct(ResponseFactoryInterface $responseFactory, UrlGeneratorInterface $urlGenerator)
19
    {
20
        $this->responseFactory = $responseFactory;
21
        $this->urlGenerator = $urlGenerator;
22
    }
23
24
    public function getRedirectResponse(string $url): ResponseInterface
25
    {
26
        return $this->responseFactory
27
            ->createResponse(Status::FOUND)
28
            ->withHeader(Header::LOCATION, $this->urlGenerator->generate($url));
29
    }
30
31
    public function getNotFoundResponse(): ResponseInterface
32
    {
33
        return $this->responseFactory->createResponse(Status::NOT_FOUND);
34
    }
35
}
36