BorderCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 30
c 1
b 0
f 1
dl 0
loc 61
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 46 2
A __construct() 0 3 1
1
<?php
2
3
namespace Jackal\ImageMerge\Command;
4
5
use Jackal\ImageMerge\Builder\ImageBuilder;
6
use Jackal\ImageMerge\Command\Options\BorderCommandOption;
7
use Jackal\ImageMerge\Command\Options\DoubleCoordinateColorCommandOption;
8
use Jackal\ImageMerge\Command\Asset\LineAssetCommand;
9
use Jackal\ImageMerge\ValueObject\Coordinate;
10
use Jackal\ImageMerge\Model\Image;
11
12
/**
13
 * Class BorderCommand
14
 * @package Jackal\ImageMerge\Command
15
 */
16
class BorderCommand extends AbstractCommand
17
{
18
    /**
19
     * BorderCommand constructor.
20
     * @param BorderCommandOption $options
21
     */
22
    public function __construct(BorderCommandOption $options)
23
    {
24
        parent::__construct($options);
25
    }
26
27
    /**
28
     * @param Image $image
29
     * @return Image
30
     */
31
    public function execute(Image $image)
32
    {
33
        /** @var BorderCommandOption $options */
34
        $options = $this->options;
35
36
        for ($i = 0;$i < $options->getStroke();$i++) {
37
            $builder = new ImageBuilder($image);
38
39
            $builder->addCommand(
40
                new LineAssetCommand(
41
                    new DoubleCoordinateColorCommandOption(
42
                        new Coordinate(0, $i),
43
                        new Coordinate($image->getWidth(), $i),
44
                        $options->getColor()
45
                    )
46
            ));
47
            //bottom
48
            $builder->addCommand(
49
                new LineAssetCommand(
50
                    new DoubleCoordinateColorCommandOption(
51
                        new Coordinate(0, $image->getHeight() - $i - 1),
52
                        new Coordinate($image->getWidth(), $image->getHeight() - $i - 1),
53
                        $options->getColor()
54
                )
55
            ));
56
            //right
57
            $builder->addCommand(
58
                new LineAssetCommand(
59
                    new DoubleCoordinateColorCommandOption(
60
                        new Coordinate($image->getWidth() - $i - 1, 0),
61
                        new Coordinate($image->getWidth() - $i - 1, $image->getHeight()),
62
                        $options->getColor()
63
                )
64
            ));
65
            //left
66
            $builder->addCommand(
67
                new LineAssetCommand(
68
                    new DoubleCoordinateColorCommandOption(
69
                        new Coordinate($i, 0),
70
                        new Coordinate($i, $image->getHeight()),
71
                        $options->getColor()
72
                    )
73
            ));
74
        }
75
76
        return $image;
77
    }
78
}
79