ListResourcesQuery   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 14.89 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 2
A __construct() 7 7 2

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
2
3
namespace Dekalee\Cdn77\Query;
4
5
use Dekalee\Cdn77\Exception\QueryErrorException;
6
use GuzzleHttp\Client;
7
8
/**
9
 * Class ListResourcesQuery
10
 */
11
class ListResourcesQuery implements QueryInterface
12
{
13
    protected $url;
14
    protected $login;
15
    protected $client;
16
    protected $password;
17
18
    const URL = 'https://api.cdn77.com/v2.0/cdn-resource/list';
19
20
    /**
21
     * @param string      $login
22
     * @param string      $password
23
     * @param string      $url
24
     * @param Client|null $client
25
     */
26 4 View Code Duplication
    public function __construct($login, $password, $url = self::URL, Client $client = null)
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...
27
    {
28 4
        $this->url = $url;
29 4
        $this->login = $login;
30 4
        $this->client = $client?: new Client();
31 4
        $this->password = $password;
32 4
    }
33
34
    /**
35
     * @return mixed|null
36
     * @throws QueryErrorException
37
     */
38 2
    public function execute()
39
    {
40 2
        $response = $this->client->get(
41 2
            sprintf(
42 2
                '%s?login=%s&passwd=%s',
43 2
                $this->url,
44 2
                $this->login,
45 2
                $this->password
46 2
            )
47 2
        );
48
49 2
        $data = json_decode($response->getBody()->getContents(), true);
50
51 2
        if ('ok' != $data['status']) {
52 1
            throw new QueryErrorException($data['description']);
53
        }
54
55 1
        return $data['cdnResources'];
56
    }
57
}
58