Code Duplication    Length = 48-48 lines in 2 locations

src/EaselDrawing/Templates/Builders/Line.php 1 location

@@ 11-58 (lines=48) @@
8
use EaselDrawing\Templates\Template;
9
use EaselDrawing\Templates\Utilities;
10
11
class Line extends AbstractBuilder
12
{
13
    /** @var Color */
14
    private $color;
15
    /** @var int */
16
    private $thickness = 1;
17
18
    /**
19
     * @return Color
20
     */
21
    public function getColor()
22
    {
23
        if (null === $this->color) {
24
            throw new \RuntimeException("Color property has not been set");
25
        }
26
        return $this->color;
27
    }
28
29
    public function getThickness(): int
30
    {
31
        return $this->thickness;
32
    }
33
34
    public function configure(array $data, Template $template)
35
    {
36
        parent::configure($data, $template);
37
        if (isset($data['color'])) {
38
            $this->color = Utilities::interpretColor($data['color'], $template->getForeground());
39
        } else {
40
            $this->color = $template->getForeground();
41
        }
42
        if (isset($data['thickness']) && is_integer($data['thickness']) && $data['thickness'] > 0) {
43
            $this->thickness = $data['thickness'];
44
        }
45
    }
46
47
    public function build(): ElementInterface
48
    {
49
        return new Element(
50
            $this->getX(),
51
            $this->getY(),
52
            $this->getWidth(),
53
            $this->getHeight(),
54
            $this->getColor(),
55
            $this->getThickness()
56
        );
57
    }
58
}
59

src/EaselDrawing/Templates/Builders/Rectangle.php 1 location

@@ 11-58 (lines=48) @@
8
use EaselDrawing\Templates\Template;
9
use EaselDrawing\Templates\Utilities;
10
11
class Rectangle extends AbstractBuilder
12
{
13
    /** @var Color */
14
    private $color;
15
    /** @var int */
16
    private $thickness = 1;
17
18
    /**
19
     * @return Color
20
     */
21
    public function getColor()
22
    {
23
        if (null === $this->color) {
24
            throw new \RuntimeException("Color property has not been set");
25
        }
26
        return $this->color;
27
    }
28
29
    public function getThickness(): int
30
    {
31
        return $this->thickness;
32
    }
33
34
    public function configure(array $data, Template $template)
35
    {
36
        parent::configure($data, $template);
37
        if (isset($data['color'])) {
38
            $this->color = Utilities::interpretColor($data['color'], $template->getForeground());
39
        } else {
40
            $this->color = $template->getForeground();
41
        }
42
        if (isset($data['thickness']) && is_integer($data['thickness']) && $data['thickness'] > 0) {
43
            $this->thickness = $data['thickness'];
44
        }
45
    }
46
47
    public function build(): ElementInterface
48
    {
49
        return new Element(
50
            $this->getX(),
51
            $this->getY(),
52
            $this->getWidth(),
53
            $this->getHeight(),
54
            $this->getColor(),
55
            $this->getThickness()
56
        );
57
    }
58
}
59