RegistrationResult   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 93
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setId() 0 7 2
A getId() 0 3 1
A setLogin() 0 7 2
A getLogin() 0 3 1
A getEmail() 0 3 1
A __construct() 0 7 1
A setEmail() 0 11 3
1
<?php
2
3
namespace JincorTech\AuthClient\Abstracts;
4
5
use InvalidArgumentException;
6
use JincorTech\AuthClient\Traits\ValidateParams;
7
8
/**
9
 * Class RegistrationResult.
10
 */
11
abstract class RegistrationResult
12
{
13
    use ValidateParams;
14
15
    /**
16
     * @var string
17
     */
18
    private $id;
19
    /**
20
     * @var string
21
     */
22
    private $email;
23
    /**
24
     * @var string
25
     */
26
    private $login;
27
28
    /**
29
     * RegistrationResult constructor.
30
     *
31
     * @param array $params
32
     */
33
    public function __construct(array $params)
34
    {
35
        $this->validateParams($params, ['id', 'email', 'login']);
36
37
        $this->setId($params['id']);
38
        $this->setEmail($params['email']);
39
        $this->setLogin($params['login']);
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getId(): string
46
    {
47
        return $this->id;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getEmail(): string
54
    {
55
        return $this->email;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getLogin(): string
62
    {
63
        return $this->login;
64
    }
65
66
    /**
67
     * @param string $id
68
     */
69
    private function setId(string $id)
70
    {
71
        if (empty($id)) {
72
            throw new InvalidArgumentException('Id value can not be empty');
73
        }
74
75
        $this->id = $id;
76
    }
77
78
    /**
79
     * @param string $email
80
     */
81
    private function setEmail(string $email)
82
    {
83
        if (empty($email)) {
84
            throw new InvalidArgumentException('Email value can not be empty');
85
        }
86
87
        if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
88
            throw new InvalidArgumentException('Invalid Email address');
89
        }
90
91
        $this->email = $email;
92
    }
93
94
    /**
95
     * @param string $login
96
     */
97
    private function setLogin(string $login)
98
    {
99
        if (empty($login)) {
100
            throw new InvalidArgumentException('Login value can not be empty');
101
        }
102
103
        $this->login = $login;
104
    }
105
}
106