Completed
Pull Request — master (#763)
by Adrien
03:28
created

Style::shouldApplyFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Box\Spout\Common\Entity\Style;
4
5
/**
6
 * Class Style
7
 * Represents a style to be applied to a cell
8
 */
9
class Style
10
{
11
    /** Default values */
12
    const DEFAULT_FONT_SIZE = 11;
13
    const DEFAULT_FONT_COLOR = Color::BLACK;
14
    const DEFAULT_FONT_NAME = 'Arial';
15
16
    /** @var int|null Style ID */
17
    private $id;
18
19
    /** @var bool Whether the font should be bold */
20
    private $fontBold = false;
21
    /** @var bool Whether the bold property was set */
22
    private $hasSetFontBold = false;
23
24
    /** @var bool Whether the font should be italic */
25
    private $fontItalic = false;
26
    /** @var bool Whether the italic property was set */
27
    private $hasSetFontItalic = false;
28
29
    /** @var bool Whether the font should be underlined */
30
    private $fontUnderline = false;
31
    /** @var bool Whether the underline property was set */
32
    private $hasSetFontUnderline = false;
33
34
    /** @var bool Whether the font should be struck through */
35
    private $fontStrikethrough = false;
36
    /** @var bool Whether the strikethrough property was set */
37
    private $hasSetFontStrikethrough = false;
38
39
    /** @var int Font size */
40
    private $fontSize = self::DEFAULT_FONT_SIZE;
41
    /** @var bool Whether the font size property was set */
42
    private $hasSetFontSize = false;
43
44
    /** @var string Font color */
45
    private $fontColor = self::DEFAULT_FONT_COLOR;
46
    /** @var bool Whether the font color property was set */
47
    private $hasSetFontColor = false;
48
49
    /** @var string Font name */
50
    private $fontName = self::DEFAULT_FONT_NAME;
51
    /** @var bool Whether the font name property was set */
52
    private $hasSetFontName = false;
53
54
    /** @var bool Whether specific font properties should be applied */
55
    private $shouldApplyFont = false;
56
57
    /** @var bool Whether specific cell alignment should be applied */
58
    private $shouldApplyCellAlignment = false;
59
    /** @var string Cell alignment */
60
    private $cellAlignment;
61
    /** @var bool Whether the cell alignment property was set */
62
    private $hasSetCellAlignment = false;
63
64
    /** @var bool Whether the text should wrap in the cell (useful for long or multi-lines text) */
65
    private $shouldWrapText = false;
66
    /** @var bool Whether the wrap text property was set */
67
    private $hasSetWrapText = false;
68
69
    /** @var Border */
70
    private $border;
71
72
    /** @var bool Whether border properties should be applied */
73
    private $shouldApplyBorder = false;
74
75
    /** @var string Background color */
76
    private $backgroundColor;
77
78
    /** @var bool */
79
    private $hasSetBackgroundColor = false;
80
81
    /** @var string Format */
82
    private $format;
83
84
    /** @var bool */
85
    private $hasSetFormat = false;
86
87
    /** @var bool */
88
    private $isRegistered = false;
89
90
    /**
91
     * @return int|null
92
     */
93 92
    public function getId()
94
    {
95 92
        return $this->id;
96
    }
97
98
    /**
99
     * @param int $id
100
     * @return Style
101
     */
102 92
    public function setId($id)
103
    {
104 92
        $this->id = $id;
105
106 92
        return $this;
107
    }
108
109
    /**
110
     * @return Border
111
     */
112 78
    public function getBorder()
113
    {
114 78
        return $this->border;
115
    }
116
117
    /**
118
     * @param Border $border
119
     * @return Style
120
     */
121 8
    public function setBorder(Border $border)
122
    {
123 8
        $this->shouldApplyBorder = true;
124 8
        $this->border = $border;
125
126 8
        return $this;
127
    }
128
129
    /**
130
     * @return bool
131
     */
132 90
    public function shouldApplyBorder()
133
    {
134 90
        return $this->shouldApplyBorder;
135
    }
136
137
    /**
138
     * @return bool
139
     */
140 80
    public function isFontBold()
141
    {
142 80
        return $this->fontBold;
143
    }
144
145
    /**
146
     * @return Style
147
     */
148 20
    public function setFontBold()
149
    {
150 20
        $this->fontBold = true;
151 20
        $this->hasSetFontBold = true;
152 20
        $this->shouldApplyFont = true;
153
154 20
        return $this;
155
    }
156
157
    /**
158
     * @return bool
159
     */
160 77
    public function hasSetFontBold()
161
    {
162 77
        return $this->hasSetFontBold;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168 80
    public function isFontItalic()
169
    {
170 80
        return $this->fontItalic;
171
    }
172
173
    /**
174
     * @return Style
175
     */
176 7
    public function setFontItalic()
177
    {
178 7
        $this->fontItalic = true;
179 7
        $this->hasSetFontItalic = true;
180 7
        $this->shouldApplyFont = true;
181
182 7
        return $this;
183
    }
184
185
    /**
186
     * @return bool
187
     */
188 77
    public function hasSetFontItalic()
189
    {
190 77
        return $this->hasSetFontItalic;
191
    }
192
193
    /**
194
     * @return bool
195
     */
196 80
    public function isFontUnderline()
197
    {
198 80
        return $this->fontUnderline;
199
    }
200
201
    /**
202
     * @return Style
203
     */
204 7
    public function setFontUnderline()
205
    {
206 7
        $this->fontUnderline = true;
207 7
        $this->hasSetFontUnderline = true;
208 7
        $this->shouldApplyFont = true;
209
210 7
        return $this;
211
    }
212
213
    /**
214
     * @return bool
215
     */
216 77
    public function hasSetFontUnderline()
217
    {
218 77
        return $this->hasSetFontUnderline;
219
    }
220
221
    /**
222
     * @return bool
223
     */
224 80
    public function isFontStrikethrough()
225
    {
226 80
        return $this->fontStrikethrough;
227
    }
228
229
    /**
230
     * @return Style
231
     */
232 4
    public function setFontStrikethrough()
233
    {
234 4
        $this->fontStrikethrough = true;
235 4
        $this->hasSetFontStrikethrough = true;
236 4
        $this->shouldApplyFont = true;
237
238 4
        return $this;
239
    }
240
241
    /**
242
     * @return bool
243
     */
244 77
    public function hasSetFontStrikethrough()
245
    {
246 77
        return $this->hasSetFontStrikethrough;
247
    }
248
249
    /**
250
     * @return int
251
     */
252 82
    public function getFontSize()
253
    {
254 82
        return $this->fontSize;
255
    }
256
257
    /**
258
     * @param int $fontSize Font size, in pixels
259
     * @return Style
260
     */
261 54
    public function setFontSize($fontSize)
262
    {
263 54
        $this->fontSize = $fontSize;
264 54
        $this->hasSetFontSize = true;
265 54
        $this->shouldApplyFont = true;
266
267 54
        return $this;
268
    }
269
270
    /**
271
     * @return bool
272
     */
273 77
    public function hasSetFontSize()
274
    {
275 77
        return $this->hasSetFontSize;
276
    }
277
278
    /**
279
     * @return string
280
     */
281 82
    public function getFontColor()
282
    {
283 82
        return $this->fontColor;
284
    }
285
286
    /**
287
     * Sets the font color.
288
     *
289
     * @param string $fontColor ARGB color (@see Color)
290
     * @return Style
291
     */
292 3
    public function setFontColor($fontColor)
293
    {
294 3
        $this->fontColor = $fontColor;
295 3
        $this->hasSetFontColor = true;
296 3
        $this->shouldApplyFont = true;
297
298 3
        return $this;
299
    }
300
301
    /**
302
     * @return bool
303
     */
304 77
    public function hasSetFontColor()
305
    {
306 77
        return $this->hasSetFontColor;
307
    }
308
309
    /**
310
     * @return string
311
     */
312 86
    public function getFontName()
313
    {
314 86
        return $this->fontName;
315
    }
316
317
    /**
318
     * @param string $fontName Name of the font to use
319
     * @return Style
320
     */
321 52
    public function setFontName($fontName)
322
    {
323 52
        $this->fontName = $fontName;
324 52
        $this->hasSetFontName = true;
325 52
        $this->shouldApplyFont = true;
326
327 52
        return $this;
328
    }
329
330
    /**
331
     * @return bool
332
     */
333 77
    public function hasSetFontName()
334
    {
335 77
        return $this->hasSetFontName;
336
    }
337
338
    /**
339
     * @return string
340
     */
341 2
    public function getCellAlignment()
342
    {
343 2
        return $this->cellAlignment;
344
    }
345
346
    /**
347
     * @param string $cellAlignment The cell alignment
348
     *
349
     * @return Style
350
     */
351 3
    public function setCellAlignment($cellAlignment)
352
    {
353 3
        $this->cellAlignment = $cellAlignment;
354 3
        $this->hasSetCellAlignment = true;
355 3
        $this->shouldApplyCellAlignment = true;
356
357 3
        return $this;
358
    }
359
360
    /**
361
     * @return bool
362
     */
363 77
    public function hasSetCellAlignment()
364
    {
365 77
        return $this->hasSetCellAlignment;
366
    }
367
368
    /**
369
     * @return bool Whether specific cell alignment should be applied
370
     */
371 83
    public function shouldApplyCellAlignment()
372
    {
373 83
        return $this->shouldApplyCellAlignment;
374
    }
375
376
    /**
377
     * @return bool
378
     */
379 85
    public function shouldWrapText()
380
    {
381 85
        return $this->shouldWrapText;
382
    }
383
384
    /**
385
     * @param bool $shouldWrap Should the text be wrapped
386
     * @return Style
387
     */
388 8
    public function setShouldWrapText($shouldWrap = true)
389
    {
390 8
        $this->shouldWrapText = $shouldWrap;
391 8
        $this->hasSetWrapText = true;
392
393 8
        return $this;
394
    }
395
396
    /**
397
     * @return bool
398
     */
399 80
    public function hasSetWrapText()
400
    {
401 80
        return $this->hasSetWrapText;
402
    }
403
404
    /**
405
     * @return bool Whether specific font properties should be applied
406
     */
407 73
    public function shouldApplyFont()
408
    {
409 73
        return $this->shouldApplyFont;
410
    }
411
412
    /**
413
     * Sets the background color
414
     * @param string $color ARGB color (@see Color)
415
     * @return Style
416
     */
417 7
    public function setBackgroundColor($color)
418
    {
419 7
        $this->hasSetBackgroundColor = true;
420 7
        $this->backgroundColor = $color;
421
422 7
        return $this;
423
    }
424
425
    /**
426
     * @return string
427
     */
428 48
    public function getBackgroundColor()
429
    {
430 48
        return $this->backgroundColor;
431
    }
432
433
    /**
434
     * @return bool Whether the background color should be applied
435
     */
436 79
    public function shouldApplyBackgroundColor()
437
    {
438 79
        return $this->hasSetBackgroundColor;
439
    }
440
441
    /**
442
     * Sets format
443
     * @param string $format
444
     * @return Style
445
     */
446 3
    public function setFormat($format)
447
    {
448 3
        $this->hasSetFormat = true;
449 3
        $this->format = $format;
450
451 3
        return $this;
452
    }
453
454
    /**
455
     * @return string
456
     */
457 87
    public function getFormat()
458
    {
459 87
        return $this->format;
460
    }
461
462
    /**
463
     * @return bool Whether format should be applied
464
     */
465 76
    public function shouldApplyFormat()
466
    {
467 76
        return $this->hasSetFormat;
468
    }
469
470 92
    public function setRegistered(bool $isRegistered = true) : void
471
    {
472 92
        $this->isRegistered = $isRegistered;
473 92
    }
474
475
    /**
476
     * @return bool
477
     */
478 84
    public function isRegistered() : bool
479
    {
480 84
        return $this->isRegistered;
481
    }
482
483 92
    public function register(int $id) : void
484
    {
485 92
        $this->setId($id);
486 92
        $this->isRegistered = true;
487 92
    }
488
}
489