LoginRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 51
ccs 14
cts 15
cp 0.9333
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A checkIsValidEmail() 0 4 2
A getPassword() 0 3 1
A getEmail() 0 3 1
A toArray() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
4
namespace talismanfr\psbbank\api\vo;
5
6
7
use InvalidArgumentException;
8
9
class LoginRequest
10
{
11
    /** @var string */
12
    private $email;
13
    /** @var string */
14
    private $password;
15
16
    /**
17
     * LoginRequest constructor.
18
     * @param string $email
19
     * @param string $password
20
     */
21 4
    public function __construct(string $email, string $password)
22
    {
23 4
        $this->checkIsValidEmail($email);
24 4
        $this->email = $email;
25 4
        $this->password = $password;
26 4
    }
27
28
    /**
29
     * @return string
30
     */
31 1
    public function getEmail(): string
32
    {
33 1
        return $this->email;
34
    }
35
36
    /**
37
     * @return string
38
     */
39 1
    public function getPassword(): string
40
    {
41 1
        return $this->password;
42
    }
43
44
    /**
45
     * Check if email is valid
46
     *
47
     * @param string $email
48
     * @throws InvalidArgumentException
49
     */
50 4
    private function checkIsValidEmail(string $email): void
51
    {
52 4
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
53
            throw new InvalidArgumentException('Email ' . $email . ' is not valid');
54
        }
55 4
    }
56
57 4
    public function toArray()
58
    {
59 4
        return get_object_vars($this);
60
    }
61
}