Test Failed
Pull Request — master (#476)
by
unknown
03:13
created

SignupController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 10
c 2
b 0
f 1
dl 0
loc 29
ccs 8
cts 9
cp 0.8889
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A signup() 0 17 5
A redirectToMain() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth\Controller;
6
7
use App\Auth\AuthService;
8
use App\Auth\Form\SignupForm;
9
use App\Service\WebControllerService;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
use Yiisoft\Http\Method;
13
use Yiisoft\Yii\View\ViewRenderer;
14
15
final class SignupController
16
{
17
    public function __construct(private WebControllerService $webService, private ViewRenderer $viewRenderer)
18
    {
19
        $this->viewRenderer = $viewRenderer->withControllerName('signup');
20
    }
21
22 5
    public function signup(
23
        AuthService $authService,
24 5
        ServerRequestInterface $request,
25 5
        SignupForm $signupForm
26
    ): ResponseInterface {
27
        if (!$authService->isGuest()) {
28 5
            return $this->redirectToMain();
29
        }
30
31
        if ($request->getMethod() === Method::POST
32
            && $signupForm->load($request->getParsedBody())
33
            && $signupForm->signup()
34 5
        ) {
35
            return $this->redirectToMain();
36
        }
37
38 5
        return $this->viewRenderer->render('signup', ['formModel' => $signupForm]);
39
    }
40 5
41
    private function redirectToMain(): ResponseInterface
42
    {
43 5
        return $this->webService->getRedirectResponse('site/index');
44 4
    }
45
}
46