Completed
Push — master ( 26d7ed...da315f )
by Stefan
04:47 queued 02:12
created

Style::getBorder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
ccs 1
cts 1
cp 1
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace OneSheet\Style;
4
5
use OneSheet\Xml\StyleXml;
6
7
/**
8
 * Class Style
9
 *
10
 * @package OneSheet
11
 */
12
class Style implements Component
13
{
14
    /**
15
     * @var int
16
     */
17
    private $id;
18
19
    /**
20
     * @var Font
21
     */
22
    private $font;
23
24
    /**
25
     * @var Fill
26
     */
27
    private $fill;
28
29
    /**
30
     * @var Border
31
     */
32
    private $border;
33
34
    /**
35
     * @var bool
36
     */
37 9
    private $isLocked = false;
38
39 9
    /**
40 9
     * Style constructor.
41 9
     */
42
    public function __construct()
43
    {
44
        $this->font = new Font();
45
        $this->fill = new Fill();
46 7
        $this->border = new Border();
47
    }
48 7
49
    /**
50
     * @return int|null
51
     */
52
    public function getId()
53
    {
54
        return $this->id;
55 4
    }
56
57 4
    /**
58 4
     * @param int $id
59
     * @return Style
60
     */
61
    public function setId($id)
62
    {
63
        $this->id = $id;
64 8
        return $this;
65
    }
66 8
67 3
    /**
68
     * @return Font
69 8
     */
70
    public function getFont()
71
    {
72
        if ($this->isLocked) {
73
            return clone $this->font;
74
        }
75 5
        return $this->font;
76
    }
77 5
78 1
    /**
79
     * @return Fill
80 5
     */
81
    public function getFill()
82
    {
83
        if ($this->isLocked) {
84
            return clone $this->fill;
85
        }
86
        return $this->fill;
87 2
    }
88
89 2
    /**
90 2
     * @return Border
91
     */
92
    public function getBorder()
93
    {
94
        if ($this->isLocked) {
95
            return clone $this->border;
96
        }
97 2
        return $this->border;
98
    }
99 2
100 2
    /**
101
     * @param string $name
102
     * @return Style
103
     */
104
    public function setFontName($name)
105
    {
106
        $this->getFont()->setName($name);
107 1
        return $this;
108
    }
109 1
110 1
    /**
111
     * @param string $size
112
     * @return Style
113
     */
114
    public function setFontSize($size)
115
    {
116 2
        $this->getFont()->setSize($size);
117
        return $this;
118 2
    }
119 2
120
    /**
121
     * @param string $color
122
     * @return Style
123
     */
124
    public function setFontColor($color)
125 1
    {
126
        $this->getFont()->setColor($color);
127 1
        return $this;
128 1
    }
129
130
    /**
131
     * @return Style
132
     */
133
    public function setFontBold()
134 1
    {
135
        $this->getFont()->setBold();
136 1
        return $this;
137 1
    }
138
139
    /**
140
     * @return Style
141
     */
142
    public function setFontItalic()
143 1
    {
144
        $this->getFont()->setItalic();
145 1
        return $this;
146 1
    }
147
148
    /**
149
     * @return Style
150
     */
151
    public function setFontUnderline()
152
    {
153 2
        $this->getFont()->setUnderline();
154
        return $this;
155 2
    }
156 2
157
    /**
158
     * @return Style
159
     */
160
    public function setFontStrikethrough()
161
    {
162
        $this->getFont()->setStrikethrough();
163 5
        return $this;
164
    }
165 5
166 5
    /**
167
     * @param string $color
168
     * @return Style
169
     */
170
    public function setFillColor($color)
171
    {
172 4
        $this->getFill()->setColor($color);
173
        return $this;
174 4
    }
175 4
176
    /**
177
     * @param string $pattern
178
     * @return Style
179
     */
180 4
    public function setFillPattern($pattern)
181
    {
182 4
        $this->getFill()->setPattern($pattern);
183
        return $this;
184
    }
185
186
    /**
187
     * @param string $style
188
     * @param string $color
189
     * @return Style
190
     */
191
    public function setBorderLeft($style, $color)
192
    {
193
        $this->getBorder()->set(BorderType::LEFT, $style, $color);
194
        return $this;
195
    }
196
197
    /**
198
     * @param string $style
199
     * @param string $color
200
     * @return Style
201
     */
202
    public function setBorderRight($style, $color)
203
    {
204
        $this->getBorder()->set(BorderType::RIGHT, $style, $color);
205
        return $this;
206
    }
207
208
    /**
209
     * @param string $style
210
     * @param string $color
211
     * @return Style
212
     */
213
    public function setBorderRightTop($style, $color)
214
    {
215
        $this->getBorder()->set(BorderType::TOP, $style, $color);
216
        return $this;
217
    }
218
219
    /**
220
     * @param string $style
221
     * @param string $color
222
     * @return Style
223
     */
224
    public function setBorderBottom($style, $color)
225
    {
226
        $this->getBorder()->set(BorderType::BOTTOM, $style, $color);
227
        return $this;
228
    }
229
230
    /**
231
     * Lock current style to prevent overwriting of existing styles.
232
     */
233
    public function lock()
234
    {
235
        $this->isLocked = true;
236
    }
237
238
    /**
239
     * Return single <xf> string for current style.
240
     *
241
     * @return string
242
     */
243
    public function asXml()
244
    {
245
        return sprintf(
246
            StyleXml::DEFAULT_XF_XML,
247
            $this->font->getId(),
248
            $this->fill->getId(),
249
            $this->border->getId()
250
        );
251
    }
252
}
253