Rectangle   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 45
loc 45
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getColor() 6 6 2
B configure() 10 10 5
A build() 9 9 1
A getThickness() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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