Passed
Pull Request — develop_3.0 (#512)
by Adrien
02:47
created

BorderPart::setStyle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Box\Spout\Common\Entity\Style;
4
5
use Box\Spout\Writer\Exception\Border\InvalidNameException;
6
use Box\Spout\Writer\Exception\Border\InvalidStyleException;
7
use Box\Spout\Writer\Exception\Border\InvalidWidthException;
8
9
/**
10
 * Class BorderPart
11
 */
12
class BorderPart
13
{
14
    /**
15
     * @var string The style of this border part.
16
     */
17
    protected $style;
18
19
    /**
20
     * @var string The name of this border part.
21
     */
22
    protected $name;
23
24
    /**
25
     * @var string The color of this border part.
26
     */
27
    protected $color;
28
29
    /**
30
     * @var string The width of this border part.
31
     */
32
    protected $width;
33
34
    /**
35
     * @var array Allowed style constants for parts.
36
     */
37
    protected static $allowedStyles = [
38
        'none',
39
        'solid',
40
        'dashed',
41
        'dotted',
42
        'double',
43
    ];
44
45
    /**
46
     * @var array Allowed names constants for border parts.
47
     */
48
    protected static $allowedNames = [
49
        'left',
50
        'right',
51
        'top',
52
        'bottom',
53
    ];
54
55
    /**
56
     * @var array Allowed width constants for border parts.
57
     */
58
    protected static $allowedWidths = [
59
        'thin',
60
        'medium',
61
        'thick',
62
    ];
63
64
    /**
65
     * @param string $name @see  BorderPart::$allowedNames
66
     * @param string $color A RGB color code
67
     * @param string $width @see BorderPart::$allowedWidths
68
     * @param string $style @see BorderPart::$allowedStyles
69
     * @throws InvalidNameException
70
     * @throws InvalidStyleException
71
     * @throws InvalidWidthException
72
     */
73 16
    public function __construct($name, $color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID)
74
    {
75 16
        $this->setName($name);
76 15
        $this->setColor($color);
77 15
        $this->setWidth($width);
78 14
        $this->setStyle($style);
79 13
    }
80
81
    /**
82
     * @return string
83
     */
84 13
    public function getName()
85
    {
86 13
        return $this->name;
87
    }
88
89
    /**
90
     * @param string $name The name of the border part @see BorderPart::$allowedNames
91
     * @throws InvalidNameException
92
     * @return void
93
     */
94 16
    public function setName($name)
95
    {
96 16
        if (!in_array($name, self::$allowedNames)) {
97 1
            throw new InvalidNameException($name);
98
        }
99 15
        $this->name = $name;
100 15
    }
101
102
    /**
103
     * @return string
104
     */
105 6
    public function getStyle()
106
    {
107 6
        return $this->style;
108
    }
109
110
    /**
111
     * @param string $style The style of the border part @see BorderPart::$allowedStyles
112
     * @throws InvalidStyleException
113
     * @return void
114
     */
115 14
    public function setStyle($style)
116
    {
117 14
        if (!in_array($style, self::$allowedStyles)) {
118 1
            throw new InvalidStyleException($style);
119
        }
120 13
        $this->style = $style;
121 13
    }
122
123
    /**
124
     * @return string
125
     */
126 6
    public function getColor()
127
    {
128 6
        return $this->color;
129
    }
130
131
    /**
132
     * @param string $color The color of the border part @see Color::rgb()
133
     * @return void
134
     */
135 15
    public function setColor($color)
136
    {
137 15
        $this->color = $color;
138 15
    }
139
140
    /**
141
     * @return string
142
     */
143 6
    public function getWidth()
144
    {
145 6
        return $this->width;
146
    }
147
148
    /**
149
     * @param string $width The width of the border part @see BorderPart::$allowedWidths
150
     * @throws InvalidWidthException
151
     * @return void
152
     */
153 15
    public function setWidth($width)
154
    {
155 15
        if (!in_array($width, self::$allowedWidths)) {
156 1
            throw new InvalidWidthException($width);
157
        }
158 14
        $this->width = $width;
159 14
    }
160
161
    /**
162
     * @return array
163
     */
164 2
    public static function getAllowedStyles()
165
    {
166 2
        return self::$allowedStyles;
167
    }
168
169
    /**
170
     * @return array
171
     */
172 2
    public static function getAllowedNames()
173
    {
174 2
        return self::$allowedNames;
175
    }
176
177
    /**
178
     * @return array
179
     */
180 2
    public static function getAllowedWidths()
181
    {
182 2
        return self::$allowedWidths;
183
    }
184
}
185