Completed
Push — master ( 91f756...eb84ec )
by Adrien
13:07
created

Style::unmarkAsRegistered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
    /** @var bool */
91
    private $isEmpty = true;
92 91
93
    /**
94
     * @return int|null
95
     */
96
    public function getId()
97
    {
98
        return $this->id;
99 91
    }
100
101 91
    /**
102
     * @param int $id
103 91
     * @return Style
104
     */
105
    public function setId($id)
106
    {
107
        $this->id = $id;
108
109 78
        return $this;
110
    }
111 78
112
    /**
113
     * @return Border
114
     */
115
    public function getBorder()
116
    {
117
        return $this->border;
118 8
    }
119
120 8
    /**
121 8
     * @param Border $border
122
     * @return Style
123 8
     */
124
    public function setBorder(Border $border)
125
    {
126
        $this->shouldApplyBorder = true;
127
        $this->border = $border;
128
        $this->isEmpty = false;
129 90
130
        return $this;
131 90
    }
132
133
    /**
134
     * @return bool
135
     */
136
    public function shouldApplyBorder()
137 80
    {
138
        return $this->shouldApplyBorder;
139 80
    }
140
141
    /**
142
     * @return bool
143
     */
144
    public function isFontBold()
145 20
    {
146
        return $this->fontBold;
147 20
    }
148 20
149 20
    /**
150
     * @return Style
151 20
     */
152
    public function setFontBold()
153
    {
154
        $this->fontBold = true;
155
        $this->hasSetFontBold = true;
156
        $this->shouldApplyFont = true;
157 77
        $this->isEmpty = false;
158
159 77
        return $this;
160
    }
161
162
    /**
163
     * @return bool
164
     */
165 80
    public function hasSetFontBold()
166
    {
167 80
        return $this->hasSetFontBold;
168
    }
169
170
    /**
171
     * @return bool
172
     */
173 7
    public function isFontItalic()
174
    {
175 7
        return $this->fontItalic;
176 7
    }
177 7
178
    /**
179 7
     * @return Style
180
     */
181
    public function setFontItalic()
182
    {
183
        $this->fontItalic = true;
184
        $this->hasSetFontItalic = true;
185 77
        $this->shouldApplyFont = true;
186
        $this->isEmpty = false;
187 77
188
        return $this;
189
    }
190
191
    /**
192
     * @return bool
193 80
     */
194
    public function hasSetFontItalic()
195 80
    {
196
        return $this->hasSetFontItalic;
197
    }
198
199
    /**
200
     * @return bool
201 7
     */
202
    public function isFontUnderline()
203 7
    {
204 7
        return $this->fontUnderline;
205 7
    }
206
207 7
    /**
208
     * @return Style
209
     */
210
    public function setFontUnderline()
211
    {
212
        $this->fontUnderline = true;
213 77
        $this->hasSetFontUnderline = true;
214
        $this->shouldApplyFont = true;
215 77
        $this->isEmpty = false;
216
217
        return $this;
218
    }
219
220
    /**
221 80
     * @return bool
222
     */
223 80
    public function hasSetFontUnderline()
224
    {
225
        return $this->hasSetFontUnderline;
226
    }
227
228
    /**
229 4
     * @return bool
230
     */
231 4
    public function isFontStrikethrough()
232 4
    {
233 4
        return $this->fontStrikethrough;
234
    }
235 4
236
    /**
237
     * @return Style
238
     */
239
    public function setFontStrikethrough()
240
    {
241 77
        $this->fontStrikethrough = true;
242
        $this->hasSetFontStrikethrough = true;
243 77
        $this->shouldApplyFont = true;
244
        $this->isEmpty = false;
245
246
        return $this;
247
    }
248
249 82
    /**
250
     * @return bool
251 82
     */
252
    public function hasSetFontStrikethrough()
253
    {
254
        return $this->hasSetFontStrikethrough;
255
    }
256
257
    /**
258 54
     * @return int
259
     */
260 54
    public function getFontSize()
261 54
    {
262 54
        return $this->fontSize;
263
    }
264 54
265
    /**
266
     * @param int $fontSize Font size, in pixels
267
     * @return Style
268
     */
269
    public function setFontSize($fontSize)
270 77
    {
271
        $this->fontSize = $fontSize;
272 77
        $this->hasSetFontSize = true;
273
        $this->shouldApplyFont = true;
274
        $this->isEmpty = false;
275
276
        return $this;
277
    }
278 82
279
    /**
280 82
     * @return bool
281
     */
282
    public function hasSetFontSize()
283
    {
284
        return $this->hasSetFontSize;
285
    }
286
287
    /**
288
     * @return string
289 3
     */
290
    public function getFontColor()
291 3
    {
292 3
        return $this->fontColor;
293 3
    }
294
295 3
    /**
296
     * Sets the font color.
297
     *
298
     * @param string $fontColor ARGB color (@see Color)
299
     * @return Style
300
     */
301 77
    public function setFontColor($fontColor)
302
    {
303 77
        $this->fontColor = $fontColor;
304
        $this->hasSetFontColor = true;
305
        $this->shouldApplyFont = true;
306
        $this->isEmpty = false;
307
308
        return $this;
309 86
    }
310
311 86
    /**
312
     * @return bool
313
     */
314
    public function hasSetFontColor()
315
    {
316
        return $this->hasSetFontColor;
317
    }
318 52
319
    /**
320 52
     * @return string
321 52
     */
322 52
    public function getFontName()
323
    {
324 52
        return $this->fontName;
325
    }
326
327
    /**
328
     * @param string $fontName Name of the font to use
329
     * @return Style
330 77
     */
331
    public function setFontName($fontName)
332 77
    {
333
        $this->fontName = $fontName;
334
        $this->hasSetFontName = true;
335
        $this->shouldApplyFont = true;
336
        $this->isEmpty = false;
337
338 2
        return $this;
339
    }
340 2
341
    /**
342
     * @return bool
343
     */
344
    public function hasSetFontName()
345
    {
346
        return $this->hasSetFontName;
347
    }
348 3
349
    /**
350 3
     * @return string
351 3
     */
352 3
    public function getCellAlignment()
353
    {
354 3
        return $this->cellAlignment;
355
    }
356
357
    /**
358
     * @param string $cellAlignment The cell alignment
359
     *
360 77
     * @return Style
361
     */
362 77
    public function setCellAlignment($cellAlignment)
363
    {
364
        $this->cellAlignment = $cellAlignment;
365
        $this->hasSetCellAlignment = true;
366
        $this->shouldApplyCellAlignment = true;
367
        $this->isEmpty = false;
368 83
369
        return $this;
370 83
    }
371
372
    /**
373
     * @return bool
374
     */
375
    public function hasSetCellAlignment()
376 84
    {
377
        return $this->hasSetCellAlignment;
378 84
    }
379
380
    /**
381
     * @return bool Whether specific cell alignment should be applied
382
     */
383
    public function shouldApplyCellAlignment()
384
    {
385 8
        return $this->shouldApplyCellAlignment;
386
    }
387 8
388 8
    /**
389
     * @return bool
390 8
     */
391
    public function shouldWrapText()
392
    {
393
        return $this->shouldWrapText;
394
    }
395
396 79
    /**
397
     * @param bool $shouldWrap Should the text be wrapped
398 79
     * @return Style
399
     */
400
    public function setShouldWrapText($shouldWrap = true)
401
    {
402
        $this->shouldWrapText = $shouldWrap;
403
        $this->hasSetWrapText = true;
404 73
        $this->isEmpty = false;
405
406 73
        return $this;
407
    }
408
409
    /**
410
     * @return bool
411
     */
412
    public function hasSetWrapText()
413
    {
414 7
        return $this->hasSetWrapText;
415
    }
416 7
417 7
    /**
418
     * @return bool Whether specific font properties should be applied
419 7
     */
420
    public function shouldApplyFont()
421
    {
422
        return $this->shouldApplyFont;
423
    }
424
425 48
    /**
426
     * Sets the background color
427 48
     * @param string $color ARGB color (@see Color)
428
     * @return Style
429
     */
430
    public function setBackgroundColor($color)
431
    {
432
        $this->hasSetBackgroundColor = true;
433 79
        $this->backgroundColor = $color;
434
        $this->isEmpty = false;
435 79
436
        return $this;
437
    }
438
439
    /**
440
     * @return string
441
     */
442
    public function getBackgroundColor()
443 3
    {
444
        return $this->backgroundColor;
445 3
    }
446 3
447
    /**
448 3
     * @return bool Whether the background color should be applied
449
     */
450
    public function shouldApplyBackgroundColor()
451
    {
452
        return $this->hasSetBackgroundColor;
453
    }
454 87
455
    /**
456 87
     * Sets format
457
     * @param string $format
458
     * @return Style
459
     */
460
    public function setFormat($format)
461
    {
462 77
        $this->hasSetFormat = true;
463
        $this->format = $format;
464 77
        $this->isEmpty = false;
465
466
        return $this;
467
    }
468
469
    /**
470
     * @return string
471
     */
472
    public function getFormat()
473
    {
474
        return $this->format;
475
    }
476
477
    /**
478
     * @return bool Whether format should be applied
479
     */
480
    public function shouldApplyFormat()
481
    {
482
        return $this->hasSetFormat;
483
    }
484
485
    /**
486
     * @return bool
487
     */
488
    public function isRegistered() : bool
489
    {
490
        return $this->isRegistered;
491
    }
492
493
    public function markAsRegistered(?int $id) : void
494
    {
495
        $this->setId($id);
496
        $this->isRegistered = true;
497
    }
498
499
    public function unmarkAsRegistered() : void
500
    {
501
        $this->setId(0);
502
        $this->isRegistered = false;
503
    }
504
505
    public function isEmpty() : bool
506
    {
507
        return $this->isEmpty;
508
    }
509
}
510