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

WebControllerService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNotFoundResponse() 0 3 1
A __construct() 0 4 1
A getRedirectResponse() 0 5 1
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