WebControllerService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 11
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRedirectResponse() 0 5 1
A getNotFoundResponse() 0 4 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
34
            ->createResponse(Status::NOT_FOUND);
35
    }
36
}
37