Url::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php declare(strict_types=1);
2
3
namespace PeeHaa\AsyncTwitter\Request;
4
5
class Url
6
{
7
    private $url;
8
9
    private $path;
10
11
    private $parameters = [];
12
13 47
    public function __construct(string $url, string $path, Parameter ...$parameters)
14
    {
15 47
        $this->url        = $url;
16 47
        $this->path       = $path;
17 47
        $this->parameters = $parameters;
18
    }
19
20 9
    public function getBaseString(): string
21
    {
22 9
        return $this->url . $this->path;
23
    }
24
25 1
    public function getQueryStringParameters(): array
26
    {
27 1
        return $this->parameters;
28
    }
29
30 18
    public function getUrl(): string
31
    {
32 18
        $url = $this->url . $this->path;
33
34 18
        if ($this->parameters) {
35 1
            $url .= $this->buildQueryString();
36
        }
37
38 18
        return $url;
39
    }
40
41 1 View Code Duplication
    private function buildQueryString(): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43 1
        $parameters = [];
44
45 1
        foreach ($this->parameters as $parameter) {
46 1
            $parameters[$parameter->getKey()] = $parameter->getValue();
47
        }
48
49 1
        return '?' . http_build_query($parameters);
50
    }
51
}
52