Label::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 1
nop 10
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace EaselDrawing\Elements;
4
5
use EaselDrawing\AbstractElement;
6
use EaselDrawing\Align;
7
use EaselDrawing\Color;
8
use EaselDrawing\Font;
9
use EaselDrawing\TextBackground;
10
11
class Label extends AbstractElement
12
{
13
    /** @var string */
14
    private $content;
15
    /** @var Font */
16
    private $font;
17
    /** @var float */
18
    private $size;
19
    /** @var Color */
20
    private $color;
21
    /** @var Align */
22
    private $align;
23
    /** @var TextBackground */
24
    private $textBackground;
25
26
    public function __construct(
27
        int $x,
28
        int $y,
29
        int $width,
30
        int $height,
31
        string $content,
32
        Font $font,
33
        float $size,
34
        Color $color,
35
        Align $align = null,
36
        TextBackground $textBackground = null
37
    ) {
38
        parent::__construct($x, $y, $width, $height);
39
        $this->setContent($content);
40
        $this->setFont($font);
41
        $this->setSize($size);
42
        $this->setColor($color);
43
        $this->setAlign($align ? : new Align(Align::LEFT));
44
        $this->setTextBackground($textBackground ? : new TextBackground(TextBackground::BOX, new Color(255, 255, 255)));
45
    }
46
47
    public function getContent(): string
48
    {
49
        return $this->content;
50
    }
51
52
    public function getFont(): Font
53
    {
54
        return $this->font;
55
    }
56
57
    public function getSize(): float
58
    {
59
        return $this->size;
60
    }
61
62
    public function getColor(): Color
63
    {
64
        return $this->color;
65
    }
66
67
    public function getAlign(): Align
68
    {
69
        return $this->align;
70
    }
71
72
    public function getTextBackground(): TextBackground
73
    {
74
        return $this->textBackground;
75
    }
76
77
    public function setContent(string $content)
78
    {
79
        $this->content = $content;
80
    }
81
82
    public function setFont(Font $font)
83
    {
84
        $this->font = $font;
85
    }
86
87
    public function setSize(float $size)
88
    {
89
        $this->size = $size;
90
    }
91
92
    public function setColor(Color $color)
93
    {
94
        $this->color = $color;
95
    }
96
97
    public function setAlign(Align $align)
98
    {
99
        $this->align = $align;
100
    }
101
102
    public function setTextBackground(TextBackground $textBackground)
103
    {
104
        $this->textBackground = $textBackground;
105
    }
106
}
107