PurgeFileQuery::execute()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 16

Duplication

Lines 10
Ratio 38.46 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
dl 10
loc 26
c 0
b 0
f 0
ccs 18
cts 18
cp 1
rs 8.8571
cc 3
eloc 16
nc 4
nop 2
crap 3
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