Rectangle::configure()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 4
nop 2
dl 10
loc 10
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace EaselDrawing\Templates\Builders;
4
5
use EaselDrawing\Color;
6
use EaselDrawing\ElementInterface;
7
use EaselDrawing\Elements\Rectangle as Element;
8
use EaselDrawing\Templates\Template;
9
use EaselDrawing\Templates\Utilities;
10
11 View Code Duplication
class Rectangle extends AbstractBuilder
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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