UserInfo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getValue() 0 9 2
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-message
10
 */
11
12
namespace Sunrise\Http\Message\Uri\Component;
13
14
use Sunrise\Http\Message\Exception\InvalidArgumentException;
15
16
/**
17
 * @link https://tools.ietf.org/html/rfc3986#section-3.2.1
18
 */
19
final class UserInfo implements ComponentInterface
20
{
21
    private User $user;
22
    private ?Password $password = null;
23
24
    /**
25
     * @param mixed $user
26
     * @param mixed $password
27
     *
28
     * @throws InvalidArgumentException
29
     */
30 62
    public function __construct($user, $password = null)
31
    {
32 62
        $this->user = User::create($user);
33
34 53
        if ($password !== null) {
35 52
            $this->password = Password::create($password);
36
        }
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @return string
43
     */
44 45
    public function getValue(): string
45
    {
46 45
        $value = $this->user->getValue();
47
48 45
        if ($this->password !== null) {
49 44
            $value .= ':' . $this->password->getValue();
50
        }
51
52 45
        return $value;
53
    }
54
}
55