Failed Conditions
Pull Request — master (#200)
by Hura
03:45 queued 01:12
created

BorderPart::getWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Box\Spout\Writer\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 $style @see BorderPart::allowedStyles
67
     * @param string $width @see BorderPart::allowedWidths
68
     * @param string $color A RGB color code
69
     * @throws InvalidNameException
70
     * @throws InvalidStyleException
71
     * @throws InvalidWidthException
72
     */
73
    public function __construct($name, $style = Border::STYLE_SOLID, $color = Color::BLACK, $width = Border::WIDTH_MEDIUM)
74
    {
75
        $this->setName($name);
76
        $this->setStyle($style);
77
        $this->setWidth($width);
78
        $this->setColor($color);
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getName()
85
    {
86
        return $this->name;
87
    }
88
89
    /**
90
     * @param string $name
91
     */
92
    public function setName($name)
93
    {
94
        if (!in_array($name, self::$allowedNames)) {
95
            throw new InvalidNameException($name);
96
        }
97
        $this->name = $name;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getStyle()
104
    {
105
        return $this->style;
106
    }
107
108
    /**
109
     * @param string $style
110
     */
111
    public function setStyle($style)
112
    {
113
        if (!in_array($style, self::$allowedStyles)) {
114
            throw new InvalidStyleException($style);
115
        }
116
        $this->style = $style;
117
    }
118
119
    /**
120
     * @return string
121
     */
122
    public function getColor()
123
    {
124
        return $this->color;
125
    }
126
127
    /**
128
     * @param string $color
129
     */
130
    public function setColor($color)
131
    {
132
        $this->color = $color;
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    public function getWidth()
139
    {
140
        return $this->width;
141
    }
142
143
    /**
144
     * @param string $width
145
     */
146
    public function setWidth($width)
147
    {
148
        if (!in_array($width, self::$allowedWidths)) {
149
            throw new InvalidWidthException($width);
150
        }
151
        $this->width = $width;
152
    }
153
154
    /**
155
     * @return array
156
     */
157
    public static function getAllowedStyles()
158
    {
159
        return self::$allowedStyles;
160
    }
161
162
    /**
163
     * @return array
164
     */
165
    public static function getAllowedNames()
166
    {
167
        return self::$allowedNames;
168
    }
169
170
    /**
171
     * @return array
172
     */
173
    public static function getAllowedWidths()
174
    {
175
        return self::$allowedWidths;
176
    }
177
}
178