Passed
Push — master ( 267be1...4d09e6 )
by Eugene
03:12
created

DeleteImageSizesResourceCommand::execute()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 5

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 22
ccs 19
cts 19
cp 1
rs 8.6737
cc 5
eloc 16
nc 5
nop 0
crap 5
1
<?php
2
namespace Staticus\Resources\Commands;
3
4
use League\Flysystem\FilesystemInterface;
5
use Staticus\Resources\Image\ResourceImageDO;
6
use Staticus\Resources\Image\ResourceImageDOInterface;
7
8
class DeleteImageSizesResourceCommand implements ResourceCommandInterface
9
{
10
    /**
11
     * @var ResourceImageDOInterface
12
     */
13
    protected $resourceDO;
14
    /**
15
     * @var FilesystemInterface
16
     */
17
    protected $filesystem;
18
19 3
    public function __construct(ResourceImageDOInterface $resourceDO, FilesystemInterface $filesystem)
20
    {
21 3
        $this->resourceDO = $resourceDO;
22 3
        $this->filesystem = $filesystem;
23 3
    }
24
25 3
    public function __invoke()
26
    {
27 3
        return $this->execute();
28
    }
29
30 3
    protected function execute()
31
    {
32 3
        $command = new FindResourceOptionsCommand($this->resourceDO, $this->filesystem);
33 3
        $result = $command([
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34 3
            ResourceImageDO::TOKEN_DIMENSION,
35 3
        ]);
36 2
        foreach ($result as $dimension) {
37 1
            $dimension = array_key_exists(ResourceImageDO::TOKEN_DIMENSION, $dimension)
38 1
                ? $dimension[ResourceImageDO::TOKEN_DIMENSION]
39 1
                : '';
40 1
            $dimension = explode('x', $dimension);
41 1
            if (false !== $dimension && 2 === count($dimension)) {
42 1
                $destroyDO = clone $this->resourceDO;
43 1
                $destroyDO->setWidth($dimension[0]);
44 1
                $destroyDO->setHeight($dimension[1]);
45 1
                $command = new DestroyResourceCommand($destroyDO, $this->filesystem);
46 1
                $command(true);
47 1
            }
48 2
        }
49
50 2
        return true;
51
    }
52
}