Completed
Push — master ( 613187...0057b2 )
by Marek
06:22
created

JiraAuthentication   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 80
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A host() 0 4 1
A username() 0 4 1
A password() 0 4 1
A createFromArray() 0 3 1
A setHost() 0 9 2
A setUsername() 0 9 2
A setPassword() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pvg\Application\Configuration\ValueObject;
6
7
use InvalidArgumentException;
8
9
class JiraAuthentication
10
{
11
    /** @var string */
12
    private $host;
13
14
    /** @var string */
15
    private $username;
16
17
    /** @var string */
18
    private $password;
19
20
    /**
21
     * @throws InvalidArgumentException
22
     */
23
    public function __construct(string $host, string $username, string $password)
24
    {
25
        $this
26
            ->setHost($host)
27
            ->setUsername($username)
28
            ->setPassword($password);
29
    }
30
31
    public function host() : string
32
    {
33
        return $this->host;
34
    }
35
36
    public function username() : string
37
    {
38
        return $this->username;
39
    }
40
41
    public function password() : string
42
    {
43
        return $this->password;
44
    }
45
46
    public static function createFromArray(array $yamlConfigArray) : void
0 ignored issues
show
Unused Code introduced by
The parameter $yamlConfigArray is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
    }
49
50
    /**
51
     * @throws InvalidArgumentException
52
     */
53
    private function setHost(string $host) : self
54
    {
55
        if (empty($host)) {
56
            throw new InvalidArgumentException('Empty JIRA host configuration');
57
        }
58
        $this->host = $host;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @throws InvalidArgumentException
65
     */
66
    private function setUsername(string $username) : self
67
    {
68
        if (empty($host)) {
0 ignored issues
show
Bug introduced by
The variable $host seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
69
            throw new InvalidArgumentException('Empty JIRA username configuration');
70
        }
71
        $this->username = $username;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @throws InvalidArgumentException
78
     */
79
    private function setPassword(string $password) : self
80
    {
81
        if (empty($host)) {
0 ignored issues
show
Bug introduced by
The variable $host seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
82
            throw new InvalidArgumentException('Empty JIRA password configuration');
83
        }
84
        $this->password = $password;
85
86
        return $this;
87
    }
88
}
89