Passed
Pull Request — master (#27)
by Anatoly
39:10
created

UserInfo::getValue()   A

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
/**
15
 * URI component "User Information"
16
 *
17
 * @link https://tools.ietf.org/html/rfc3986#section-3.2.1
18
 */
19
final class UserInfo implements ComponentInterface
20
{
21
22
    /**
23
     * URI component "user"
24
     *
25
     * @var User
26
     */
27
    private User $user;
28
29
    /**
30
     * URI component "password"
31
     *
32
     * @var Password|null
33
     */
34
    private ?Password $password = null;
35
36
    /**
37
     * Constructor of the class
38
     *
39
     * @param mixed $user
40
     * @param mixed $password
41
     */
42 61
    public function __construct($user, $password = null)
43
    {
44 61
        $this->user = $user instanceof User ? $user : new User($user);
45
46 52
        if (isset($password)) {
47 51
            $this->password = $password instanceof Password ? $password : new Password($password);
48
        }
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     *
54
     * @return string
55
     */
56 44
    public function getValue(): string
57
    {
58 44
        $value = $this->user->getValue();
59
60 44
        if (isset($this->password)) {
61 43
            $value .= ':' . $this->password->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
            $value .= ':' . $this->password->/** @scrutinizer ignore-call */ getValue();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        }
63
64 44
        return $value;
65
    }
66
}
67