Url   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 10
loc 47
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseString() 0 4 1
A getQueryStringParameters() 0 4 1
A getUrl() 0 10 2
A buildQueryString() 10 10 2
A __construct() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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