AbstractBuilder   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 69
Duplicated Lines 8.7 %

Importance

Changes 0
Metric Value
dl 6
loc 69
rs 10
c 0
b 0
f 0
wmc 20

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
B setSize() 3 13 8
A configure() 0 4 1
A getY() 0 3 1
A getX() 0 3 1
A getHeight() 0 3 1
A getWidth() 0 3 1
B setPosition() 3 11 6

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\Templates\Template;
6
use EaselDrawing\Templates\ElementBuilderInterface;
7
8
abstract class AbstractBuilder implements ElementBuilderInterface
9
{
10
    /** @var int */
11
    private $x = 0;
12
    /** @var int */
13
    private $y = 0;
14
    /** @var int */
15
    private $width = 1;
16
    /** @var int */
17
    private $height = 1;
18
19
    public static function create(): ElementBuilderInterface
20
    {
21
        return new static();
22
    }
23
24
    public function getX(): int
25
    {
26
        return $this->x;
27
    }
28
29
    public function getY(): int
30
    {
31
        return $this->y;
32
    }
33
34
    public function getWidth(): int
35
    {
36
        return $this->width;
37
    }
38
39
    public function getHeight(): int
40
    {
41
        return $this->height;
42
    }
43
44
    public function configure(array $data, Template $template)
45
    {
46
        $this->setPosition($data);
47
        $this->setSize($data);
48
    }
49
50
    protected function setPosition(array $data)
51
    {
52
        $position = [$this->getX(), $this->getY()];
53 View Code Duplication
        if (isset($data['position']) && is_array($data['position']) && count($data['position']) >= 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
54
            $position = $data['position'];
55
        }
56
        if (is_integer($position[0])) {
57
            $this->x = $position[0];
58
        }
59
        if (is_integer($position[1])) {
60
            $this->y = $position[1];
61
        }
62
    }
63
64
    protected function setSize(array $data)
65
    {
66
        $size = [$this->getWidth(), $this->getHeight()];
67 View Code Duplication
        if (isset($data['size']) && is_array($data['size']) && count($data['size']) >= 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
68
            $size = $data['size'];
69
        }
70
        if (is_integer($size[0]) && $size[0] > 0) {
71
            $this->width = $size[0];
72
        }
73
        if (is_integer($size[1]) && $size[1] > 0) {
74
            $this->height = $size[1];
75
        }
76
        return $this;
77
    }
78
}
79