PurgeFileQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 27.03 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 10 26 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
use Dekalee\Cdn77\Exception\QueryErrorException;
6
use GuzzleHttp\Client;
7
8
/**
9
 * Class PurgeFileQuery
10
 */
11
class PurgeFileQuery extends AbstractResourcesAwareQuery implements QueryInterface
12
{
13
    const URL = 'https://api.cdn77.com/v2.0/data/purge';
14
15
    /**
16
     * @param null  $resource
17
     * @param array $files
18
     *
19
     * @return mixed|null
20
     */
21 1
    public function execute($resource = null, array $files = array())
22
    {
23 1
        $this->populateCDNResources();
24
25 1
        $urls = [];
26 1
        foreach ($files as $file) {
27 1
            $urls[] = '/' . urlencode($file);
28 1
        }
29
30 1
        $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...
31 1
            return $value['cname'] == $resource;
32 1
        }, ARRAY_FILTER_USE_BOTH);
33
34 1 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...
35 1
            $this->client->post($this->url, [
36
                'form_params' => [
37 1
                    'cdn_id' => $cdnResource['id'],
38 1
                    'login' => $this->login,
39 1
                    'passwd' => $this->password,
40
                    'url' => $urls
41 1
                ]
42 1
            ]);
43 1
        }
44
45 1
        return;
46
    }
47
}
48