UserInfo::getValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
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