Completed
Pull Request — master (#200)
by Hura
11:35
created

BorderPart::getWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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