Passed
Push — main ( a01d42...f042b8 )
by Andrey
13:24 queued 11:56
created

Uri::withPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helldar\Support\Tools\Http;
4
5
use Helldar\Support\Concerns\Makeable;
6
use Helldar\Support\Facades\Helpers\Ables\Stringable;
0 ignored issues
show
Bug introduced by
The type Helldar\Support\Facades\Helpers\Ables\Stringable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Helldar\Support\Helpers\HttpBuilder;
8
use Psr\Http\Message\UriInterface;
9
10
class Uri implements UriInterface
11
{
12
    use Makeable;
13
14
    /** @var \Helldar\Support\Helpers\HttpBuilder */
15
    protected $builder;
16
17 4
    public function __construct(HttpBuilder $builder = null)
18
    {
19 4
        $this->builder = $builder ?: new HttpBuilder();
20 4
    }
21
22 4
    public function __toString()
23
    {
24 4
        return $this->builder->compile();
25
    }
26
27 2
    public function getScheme(): ?string
28
    {
29 2
        return $this->builder->getScheme();
30
    }
31
32 2
    public function getAuthority(): ?string
33
    {
34 2
        $auth = $this->getUserInfo();
35 2
        $host = $this->getHost();
36 2
        $port = $this->getPort();
37
38 2
        $auth = $auth ? $auth . '@' : '';
39 2
        $port = $port ? ':' . $port : '';
40
41 2
        return $auth . $host . $port;
42
    }
43
44 2
    public function getUserInfo(): ?string
45
    {
46 2
        if (empty($this->builder->getUser()) && empty($this->builder->getUser())) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->builder->getUser() targeting Helldar\Support\Helpers\HttpBuilder::getUser() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
47
            return null;
48
        }
49
50 2
        $user     = Stringable::of($this->builder->getUser())->trim();
51 2
        $password = Stringable::of($this->builder->getPass())->trim()->start(':');
52
53 2
        return $user . $password;
54
    }
55
56 2
    public function getHost(): ?string
57
    {
58 2
        return $this->builder->getHost();
59
    }
60
61 2
    public function getPort(): ?int
62
    {
63 2
        return $this->builder->getPort();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->builder->getPort() could return the type string which is incompatible with the type-hinted return integer|null. Consider adding an additional type-check to rule them out.
Loading history...
64
    }
65
66 2
    public function getPath(): ?string
67
    {
68 2
        return $this->builder->getPath();
69
    }
70
71 2
    public function getQuery(): ?string
72
    {
73 2
        return $this->builder->getQuery();
74
    }
75
76 2
    public function getFragment(): ?string
77
    {
78 2
        return $this->builder->getFragment();
79
    }
80
81
    public function withScheme($scheme): self
82
    {
83
        $this->builder->setScheme($scheme);
84
85
        return $this;
86
    }
87
88
    public function withUserInfo($user, $password = null): self
89
    {
90
        $this->builder->setUser($user);
91
        $this->builder->setPass($password);
92
93
        return $this;
94
    }
95
96
    public function withHost($host): self
97
    {
98
        $this->builder->setHost($host);
99
100
        return $this;
101
    }
102
103
    public function withPort($port): self
104
    {
105
        $this->builder->setPort($port);
106
107
        return $this;
108
    }
109
110
    public function withPath($path): self
111
    {
112
        $this->builder->setPath($path);
113
114
        return $this;
115
    }
116
117
    public function withQuery($query): self
118
    {
119
        $this->builder->setQuery($query);
120
121
        return $this;
122
    }
123
124
    public function withFragment($fragment): self
125
    {
126
        $this->builder->setFragment($fragment);
127
128
        return $this;
129
    }
130
}
131