AbstractBuilder::setPosition()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 11
Code Lines 7

Duplication

Lines 3
Ratio 27.27 %

Importance

Changes 0
Metric Value
cc 6
eloc 7
nc 8
nop 1
dl 3
loc 11
rs 8.8571
c 0
b 0
f 0
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