Completed
Pull Request — master (#738)
by
unknown
02:20
created

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