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

SignupController::signup()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.0729

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 7
c 1
b 0
f 1
nc 3
nop 3
dl 0
loc 17
ccs 6
cts 7
cp 0.8571
crap 5.0729
rs 9.6111
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