Passed
Push — master ( fec9db...7daaf5 )
by
unknown
03:00 queued 01:27
created

SignupForm::getPropertyTranslator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth\Form;
6
7
use App\User\User;
8
use App\User\UserRepository;
9
use Yiisoft\FormModel\FormModel;
0 ignored issues
show
Bug introduced by
The type Yiisoft\FormModel\FormModel 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...
10
use Yiisoft\Translator\TranslatorInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Translator\TranslatorInterface 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 Yiisoft\Validator\PropertyTranslator\ArrayPropertyTranslator;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Proper...ArrayPropertyTranslator 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\Validator\PropertyTranslatorInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\PropertyTranslatorInterface 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\Validator\PropertyTranslatorProviderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Proper...slatorProviderInterface 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
use Yiisoft\Validator\Result;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Result 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...
15
use Yiisoft\Validator\Rule\Equal;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\Equal 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...
16
use Yiisoft\Validator\Rule\Length;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\Length 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...
17
use Yiisoft\Validator\Rule\Required;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\Rule\Required 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...
18
use Yiisoft\Validator\RulesProviderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Validator\RulesProviderInterface 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...
19
20
final class SignupForm extends FormModel implements RulesProviderInterface, PropertyTranslatorProviderInterface
21
{
22
    private string $login = '';
23
    private string $password = '';
24
    private string $passwordVerify = '';
0 ignored issues
show
introduced by
The private property $passwordVerify is not used, and could be removed.
Loading history...
25
26
    public function __construct(
27
        private readonly TranslatorInterface $translator,
28
        private readonly UserRepository $userRepository,
29
    ) {
30
    }
31
32
    public function getPropertyLabels(): array
33
    {
34
        return [
35
            'login' => $this->translator->translate('layout.login'),
36
            'password' => $this->translator->translate('layout.password'),
37
            'passwordVerify' => $this->translator->translate('layout.password-verify'),
38
        ];
39
    }
40
41
    public function getFormName(): string
42
    {
43
        return 'Signup';
44
    }
45
46
    public function getLogin(): string
47
    {
48
        return $this->login;
49
    }
50
51
    public function getPassword(): string
52
    {
53
        return $this->password;
54
    }
55
56
    public function signup(): User
57
    {
58
        $user = new User($this->getLogin(), $this->getPassword());
59
        $this->userRepository->save($user);
60
        return $user;
61
    }
62
63
    public function getRules(): array
64
    {
65
        return [
66
            'login' => [
67
                new Required(),
68
                new Length(min: 1, max: 48, skipOnError: true),
69
                function ($value): Result {
70
                    $result = new Result();
71
                    if ($this->userRepository->findByLogin($value) !== null) {
72
                        $result->addError('User with this login already exists.');
73
                    }
74
75
                    return $result;
76
                },
77
            ],
78
            'password' => [
79
                new Required(),
80
                new Length(min: 8),
81
            ],
82
            'passwordVerify' => [
83
                new Required(),
84
                new Equal(
85
                    targetValue: $this->password,
86
                    message: $this->translator->translate('validator.password.not.match')
87
                ),
88
            ],
89
        ];
90
    }
91
92
    public function getPropertyTranslator(): ?PropertyTranslatorInterface
93
    {
94
        return new ArrayPropertyTranslator($this->getPropertyLabels());
95
    }
96
}
97