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

SignupService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 36
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogin() 0 9 2
A __construct() 0 2 1
A setPassword() 0 9 2
A signup() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\User;
6
7
final class SignupService
8
{
9
    private UserLogin $login;
10
    private UserPassword $password;
11
12
    public function __construct(private UserRepository $userRepository)
13
    {
14
    }
15
16
    public function signup(): User
17
    {
18
        $user = new User($this->login, $this->password);
19
        $this->userRepository->save($user);
20
        return $user;
21
    }
22
23
    public function setLogin(string|UserLogin $login): SignupService
24
    {
25
        if (is_string($login)) {
26
            $this->login = UserLogin::createNew($login, $this->userRepository);
27
        }else {
28
            $this->login = $login;
29
        }
30
31
        return $this;
32
    }
33
34
    public function setPassword(string|UserPassword $password): SignupService
35
    {
36
        if (is_string($password)) {
37
            $this->password = UserPassword::createNew($password,);
38
        }else {
39
            $this->password = $password;
40
        }
41
42
        return $this;
43
    }
44
}
45