SignupController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 28
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A signup() 0 16 3
A redirectToMain() 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;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psr\Http\Message\ServerRequestInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ServerRequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Yiisoft\FormModel\FormHydrator;
0 ignored issues
show
Bug introduced by
The type Yiisoft\FormModel\FormHydrator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Yiisoft\Yii\View\Renderer\ViewRenderer;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\View\Renderer\ViewRenderer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
    public function signup(
23
        AuthService $authService,
24
        ServerRequestInterface $request,
25
        FormHydrator $formHydrator,
26
        SignupForm $signupForm
27
    ): ResponseInterface {
28
        if (!$authService->isGuest()) {
29
            return $this->redirectToMain();
30
        }
31
32
        if ($formHydrator->populateFromPostAndValidate($signupForm, $request)) {
33
            $signupForm->signup();
34
            return $this->redirectToMain();
35
        }
36
37
        return $this->viewRenderer->render('signup', ['formModel' => $signupForm]);
38
    }
39
40
    private function redirectToMain(): ResponseInterface
41
    {
42
        return $this->webService->getRedirectResponse('site/index');
43
    }
44
}
45