PurgeAllQuery::execute()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 9
Ratio 45 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 9
loc 20
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 9.4285
cc 3
eloc 12
nc 2
nop 1
crap 3
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