PurgeAllQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 30 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 9
loc 30
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 9 20 3

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
/**
6
 * Class PurgeAllQuery
7
 */
8
class PurgeAllQuery extends AbstractResourcesAwareQuery implements QueryInterface
9
{
10
    const URL = 'https://api.cdn77.com/v2.0/data/purge';
11
12
    /**
13
     * @param null  $resource
14
     *
15
     * @return mixed|null
16
     */
17 2
    public function execute($resource = null)
18
    {
19 2
        $this->populateCDNResources();
20
21 2
        $cdnResources = array_filter($this->cdnResources, function($value, $key) use ($resource) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22 2
            return $resource === null || $value['cname'] == $resource;
23 2
        }, ARRAY_FILTER_USE_BOTH);
24
25 2 View Code Duplication
        foreach ($cdnResources as $cdnResource) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
26 2
            $this->client->post($this->url, [
27
                'form_params' => [
28 2
                    'cdn_id' => $cdnResource['id'],
29 2
                    'login' => $this->login,
30 2
                    'passwd' => $this->password,
31
                ]
32 2
            ]);
33 2
        }
34
35 2
        return;
36
    }
37
}
38