Font   F
last analyzed

Complexity

Total Complexity 128

Size/Duplication

Total Lines 827
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 128
eloc 320
dl 0
loc 827
ccs 306
cts 306
cp 1
rs 2
c 0
b 0
f 0

45 Methods

Rating   Name   Duplication   Size   Complexity  
A setCap() 0 5 2
A setUnderlineColor() 0 13 2
A setChartColorFromObject() 0 5 1
A getStyleArray() 0 3 1
A getSubscript() 0 7 2
A getName() 0 7 2
A getUnderlineColor() 0 7 2
A getChartColor() 0 7 2
A setChartColor() 0 13 2
A getLatin() 0 7 2
A setEastAsian() 0 16 3
A getStrikeType() 0 7 2
B setSize() 0 22 8
A setLatin() 0 16 3
A setStrikethrough() 0 14 3
A setSuperscript() 0 13 3
A setName() 0 13 3
A getSize() 0 7 2
A getStrikethrough() 0 7 2
A getItalic() 0 7 2
A getBold() 0 7 2
A exportArray1() 0 23 1
B getHashCode() 0 31 7
A setBaseLine() 0 13 2
A getBaseLine() 0 7 2
A __clone() 0 5 3
A setItalic() 0 13 3
A getComplexScript() 0 7 2
A setBold() 0 13 3
A getUnderline() 0 7 2
A hashChartColor() 0 10 2
A setUnderline() 0 15 5
A setColor() 0 13 3
A setStrikeType() 0 13 2
A getSuperscript() 0 7 2
F applyFromArray() 0 53 17
A getCap() 0 3 1
A setSubscript() 0 13 3
A getSharedComponent() 0 6 1
A setScheme() 0 12 5
A setComplexScript() 0 16 3
A __construct() 0 22 3
A getColor() 0 3 1
A getScheme() 0 7 2
A getEastAsian() 0 7 2

How to fix   Complexity   

Complex Class

Complex classes like Font often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Font, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Style;
4
5
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
6
7
class Font extends Supervisor
8
{
9
    // Underline types
10
    const UNDERLINE_NONE = 'none';
11
    const UNDERLINE_DOUBLE = 'double';
12
    const UNDERLINE_DOUBLEACCOUNTING = 'doubleAccounting';
13
    const UNDERLINE_SINGLE = 'single';
14
    const UNDERLINE_SINGLEACCOUNTING = 'singleAccounting';
15
16
    const CAP_ALL = 'all';
17
    const CAP_SMALL = 'small';
18
    const CAP_NONE = 'none';
19
    private const VALID_CAPS = [self::CAP_ALL, self::CAP_SMALL, self::CAP_NONE];
20
21
    protected ?string $cap = null;
22
23
    public const DEFAULT_FONT_NAME = 'Calibri';
24
25
    /**
26
     * Font Name.
27
     */
28
    protected ?string $name = self::DEFAULT_FONT_NAME;
29
30
    /**
31
     * The following 7 are used only for chart titles, I think.
32
     */
33
    private string $latin = '';
34
35
    private string $eastAsian = '';
36
37
    private string $complexScript = '';
38
39
    private int $baseLine = 0;
40
41
    private string $strikeType = '';
42
43
    private ?ChartColor $underlineColor = null;
44
45
    private ?ChartColor $chartColor = null;
46
    // end of chart title items
47
48
    /**
49
     * Font Size.
50
     */
51
    protected ?float $size = 11;
52
53
    /**
54
     * Bold.
55
     */
56
    protected ?bool $bold = false;
57
58
    /**
59
     * Italic.
60
     */
61
    protected ?bool $italic = false;
62
63
    /**
64
     * Superscript.
65
     */
66
    protected ?bool $superscript = false;
67
68
    /**
69
     * Subscript.
70
     */
71
    protected ?bool $subscript = false;
72
73
    /**
74
     * Underline.
75
     */
76
    protected ?string $underline = self::UNDERLINE_NONE;
77
78
    /**
79
     * Strikethrough.
80
     */
81
    protected ?bool $strikethrough = false;
82
83
    /**
84
     * Foreground color.
85
     */
86
    protected Color $color;
87
88
    public ?int $colorIndex = null;
89
90
    protected string $scheme = '';
91
92
    /**
93
     * Create a new Font.
94
     *
95
     * @param bool $isSupervisor Flag indicating if this is a supervisor or not
96
     *                                    Leave this value at default unless you understand exactly what
97
     *                                        its ramifications are
98
     * @param bool $isConditional Flag indicating if this is a conditional style or not
99
     *                                    Leave this value at default unless you understand exactly what
100
     *                                        its ramifications are
101
     */
102 10701
    public function __construct(bool $isSupervisor = false, bool $isConditional = false)
103
    {
104
        // Supervisor?
105 10701
        parent::__construct($isSupervisor);
106
107
        // Initialise values
108 10701
        if ($isConditional) {
109 402
            $this->name = null;
110 402
            $this->size = null;
111 402
            $this->bold = null;
112 402
            $this->italic = null;
113 402
            $this->superscript = null;
114 402
            $this->subscript = null;
115 402
            $this->underline = null;
116 402
            $this->strikethrough = null;
117 402
            $this->color = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional);
118
        } else {
119 10698
            $this->color = new Color(Color::COLOR_BLACK, $isSupervisor);
120
        }
121
        // bind parent if we are a supervisor
122 10701
        if ($isSupervisor) {
123 10516
            $this->color->bindParent($this, 'color');
124
        }
125
    }
126
127
    /**
128
     * Get the shared style component for the currently active cell in currently active sheet.
129
     * Only used for style supervisor.
130
     */
131 69
    public function getSharedComponent(): self
132
    {
133
        /** @var Style $parent */
134 69
        $parent = $this->parent;
135
136 69
        return $parent->getSharedComponent()->getFont();
137
    }
138
139
    /**
140
     * Build style array from subcomponents.
141
     */
142 103
    public function getStyleArray(array $array): array
143
    {
144 103
        return ['font' => $array];
145
    }
146
147
    /**
148
     * Apply styles from array.
149
     *
150
     * <code>
151
     * $spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->applyFromArray(
152
     *     [
153
     *         'name' => 'Arial',
154
     *         'bold' => TRUE,
155
     *         'italic' => FALSE,
156
     *         'underline' => \PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE,
157
     *         'strikethrough' => FALSE,
158
     *         'color' => [
159
     *             'rgb' => '808080'
160
     *         ]
161
     *     ]
162
     * );
163
     * </code>
164
     *
165
     * @param array $styleArray Array containing style information
166
     *
167
     * @return $this
168
     */
169 268
    public function applyFromArray(array $styleArray): static
170
    {
171 268
        if ($this->isSupervisor) {
172 1
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($styleArray));
173
        } else {
174 268
            if (isset($styleArray['name'])) {
175 178
                $this->setName($styleArray['name']);
176
            }
177 268
            if (isset($styleArray['latin'])) {
178 25
                $this->setLatin($styleArray['latin']);
179
            }
180 268
            if (isset($styleArray['eastAsian'])) {
181 17
                $this->setEastAsian($styleArray['eastAsian']);
182
            }
183 268
            if (isset($styleArray['complexScript'])) {
184 17
                $this->setComplexScript($styleArray['complexScript']);
185
            }
186 268
            if (isset($styleArray['bold'])) {
187 168
                $this->setBold($styleArray['bold']);
188
            }
189 268
            if (isset($styleArray['italic'])) {
190 105
                $this->setItalic($styleArray['italic']);
191
            }
192 268
            if (isset($styleArray['superscript'])) {
193 30
                $this->setSuperscript($styleArray['superscript']);
194
            }
195 268
            if (isset($styleArray['subscript'])) {
196 28
                $this->setSubscript($styleArray['subscript']);
197
            }
198 268
            if (isset($styleArray['underline'])) {
199 64
                $this->setUnderline($styleArray['underline']);
200
            }
201 268
            if (isset($styleArray['strikethrough'])) {
202 59
                $this->setStrikethrough($styleArray['strikethrough']);
203
            }
204 268
            if (isset($styleArray['color'])) {
205 116
                $this->getColor()->applyFromArray($styleArray['color']);
206
            }
207 268
            if (isset($styleArray['size'])) {
208 115
                $this->setSize($styleArray['size']);
209
            }
210 268
            if (isset($styleArray['chartColor'])) {
211 13
                $this->chartColor = $styleArray['chartColor'];
212
            }
213 268
            if (isset($styleArray['scheme'])) {
214 51
                $this->setScheme($styleArray['scheme']);
215
            }
216 268
            if (isset($styleArray['cap'])) {
217 2
                $this->setCap($styleArray['cap']);
218
            }
219
        }
220
221 268
        return $this;
222
    }
223
224
    /**
225
     * Get Name.
226
     */
227 1206
    public function getName(): ?string
228
    {
229 1206
        if ($this->isSupervisor) {
230 30
            return $this->getSharedComponent()->getName();
231
        }
232
233 1206
        return $this->name;
234
    }
235
236 53
    public function getLatin(): string
237
    {
238 53
        if ($this->isSupervisor) {
239 8
            return $this->getSharedComponent()->getLatin();
240
        }
241
242 53
        return $this->latin;
243
    }
244
245 53
    public function getEastAsian(): string
246
    {
247 53
        if ($this->isSupervisor) {
248 8
            return $this->getSharedComponent()->getEastAsian();
249
        }
250
251 53
        return $this->eastAsian;
252
    }
253
254 53
    public function getComplexScript(): string
255
    {
256 53
        if ($this->isSupervisor) {
257 8
            return $this->getSharedComponent()->getComplexScript();
258
        }
259
260 53
        return $this->complexScript;
261
    }
262
263
    /**
264
     * Set Name and turn off Scheme.
265
     */
266 985
    public function setName(string $fontname): self
267
    {
268 985
        if ($fontname == '') {
269 1
            $fontname = 'Calibri';
270
        }
271 985
        if ($this->isSupervisor) {
272 41
            $styleArray = $this->getStyleArray(['name' => $fontname]);
273 41
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
274
        } else {
275 985
            $this->name = $fontname;
276
        }
277
278 985
        return $this->setScheme('');
279
    }
280
281 48
    public function setLatin(string $fontname): self
282
    {
283 48
        if ($fontname == '') {
284 12
            $fontname = 'Calibri';
285
        }
286 48
        if (!$this->isSupervisor) {
287 48
            $this->latin = $fontname;
288
        } else {
289
            // should never be true
290
            // @codeCoverageIgnoreStart
291
            $styleArray = $this->getStyleArray(['latin' => $fontname]);
292
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
293
            // @codeCoverageIgnoreEnd
294
        }
295
296 48
        return $this;
297
    }
298
299 41
    public function setEastAsian(string $fontname): self
300
    {
301 41
        if ($fontname == '') {
302 12
            $fontname = 'Calibri';
303
        }
304 41
        if (!$this->isSupervisor) {
305 41
            $this->eastAsian = $fontname;
306
        } else {
307
            // should never be true
308
            // @codeCoverageIgnoreStart
309
            $styleArray = $this->getStyleArray(['eastAsian' => $fontname]);
310
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
311
            // @codeCoverageIgnoreEnd
312
        }
313
314 41
        return $this;
315
    }
316
317 41
    public function setComplexScript(string $fontname): self
318
    {
319 41
        if ($fontname == '') {
320 12
            $fontname = 'Calibri';
321
        }
322 41
        if (!$this->isSupervisor) {
323 41
            $this->complexScript = $fontname;
324
        } else {
325
            // should never be true
326
            // @codeCoverageIgnoreStart
327
            $styleArray = $this->getStyleArray(['complexScript' => $fontname]);
328
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
329
            // @codeCoverageIgnoreEnd
330
        }
331
332 41
        return $this;
333
    }
334
335
    /**
336
     * Get Size.
337
     */
338 1152
    public function getSize(): ?float
339
    {
340 1152
        if ($this->isSupervisor) {
341 24
            return $this->getSharedComponent()->getSize();
342
        }
343
344 1152
        return $this->size;
345
    }
346
347
    /**
348
     * Set Size.
349
     *
350
     * @param mixed $sizeInPoints A float representing the value of a positive measurement in points (1/72 of an inch)
351
     *
352
     * @return $this
353
     */
354 915
    public function setSize(mixed $sizeInPoints, bool $nullOk = false): static
355
    {
356 915
        if (is_string($sizeInPoints) || is_int($sizeInPoints)) {
357 233
            $sizeInPoints = (float) $sizeInPoints; // $pValue = 0 if given string is not numeric
358
        }
359
360
        // Size must be a positive floating point number
361
        // ECMA-376-1:2016, part 1, chapter 18.4.11 sz (Font Size), p. 1536
362 915
        if (!is_float($sizeInPoints) || !($sizeInPoints > 0)) {
363 61
            if (!$nullOk || $sizeInPoints !== null) {
364 1
                $sizeInPoints = 10.0;
365
            }
366
        }
367
368 915
        if ($this->isSupervisor) {
369 20
            $styleArray = $this->getStyleArray(['size' => $sizeInPoints]);
370 20
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
371
        } else {
372 915
            $this->size = $sizeInPoints;
373
        }
374
375 915
        return $this;
376
    }
377
378
    /**
379
     * Get Bold.
380
     */
381 1128
    public function getBold(): ?bool
382
    {
383 1128
        if ($this->isSupervisor) {
384 48
            return $this->getSharedComponent()->getBold();
385
        }
386
387 1128
        return $this->bold;
388
    }
389
390
    /**
391
     * Set Bold.
392
     *
393
     * @return $this
394
     */
395 753
    public function setBold(bool $bold): static
396
    {
397 753
        if ($bold == '') {
398 499
            $bold = false;
399
        }
400 753
        if ($this->isSupervisor) {
401 68
            $styleArray = $this->getStyleArray(['bold' => $bold]);
402 68
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
403
        } else {
404 753
            $this->bold = $bold;
405
        }
406
407 753
        return $this;
408
    }
409
410
    /**
411
     * Get Italic.
412
     */
413 1116
    public function getItalic(): ?bool
414
    {
415 1116
        if ($this->isSupervisor) {
416 35
            return $this->getSharedComponent()->getItalic();
417
        }
418
419 1116
        return $this->italic;
420
    }
421
422
    /**
423
     * Set Italic.
424
     *
425
     * @return $this
426
     */
427 654
    public function setItalic(bool $italic): static
428
    {
429 654
        if ($italic == '') {
430 514
            $italic = false;
431
        }
432 654
        if ($this->isSupervisor) {
433 19
            $styleArray = $this->getStyleArray(['italic' => $italic]);
434 19
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
435
        } else {
436 654
            $this->italic = $italic;
437
        }
438
439 654
        return $this;
440
    }
441
442
    /**
443
     * Get Superscript.
444
     */
445 987
    public function getSuperscript(): ?bool
446
    {
447 987
        if ($this->isSupervisor) {
448 13
            return $this->getSharedComponent()->getSuperscript();
449
        }
450
451 987
        return $this->superscript;
452
    }
453
454
    /**
455
     * Set Superscript.
456
     *
457
     * @return $this
458
     */
459 41
    public function setSuperscript(bool $superscript): static
460
    {
461 41
        if ($this->isSupervisor) {
462 5
            $styleArray = $this->getStyleArray(['superscript' => $superscript]);
463 5
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
464
        } else {
465 41
            $this->superscript = $superscript;
466 41
            if ($this->superscript) {
467 29
                $this->subscript = false;
468
            }
469
        }
470
471 41
        return $this;
472
    }
473
474
    /**
475
     * Get Subscript.
476
     */
477 987
    public function getSubscript(): ?bool
478
    {
479 987
        if ($this->isSupervisor) {
480 13
            return $this->getSharedComponent()->getSubscript();
481
        }
482
483 987
        return $this->subscript;
484
    }
485
486
    /**
487
     * Set Subscript.
488
     *
489
     * @return $this
490
     */
491 39
    public function setSubscript(bool $subscript): static
492
    {
493 39
        if ($this->isSupervisor) {
494 3
            $styleArray = $this->getStyleArray(['subscript' => $subscript]);
495 3
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
496
        } else {
497 39
            $this->subscript = $subscript;
498 39
            if ($this->subscript) {
499 27
                $this->superscript = false;
500
            }
501
        }
502
503 39
        return $this;
504
    }
505
506 42
    public function getBaseLine(): int
507
    {
508 42
        if ($this->isSupervisor) {
509 8
            return $this->getSharedComponent()->getBaseLine();
510
        }
511
512 42
        return $this->baseLine;
513
    }
514
515 32
    public function setBaseLine(int $baseLine): self
516
    {
517 32
        if (!$this->isSupervisor) {
518 32
            $this->baseLine = $baseLine;
519
        } else {
520
            // should never be true
521
            // @codeCoverageIgnoreStart
522
            $styleArray = $this->getStyleArray(['baseLine' => $baseLine]);
523
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
524
            // @codeCoverageIgnoreEnd
525
        }
526
527 32
        return $this;
528
    }
529
530 42
    public function getStrikeType(): string
531
    {
532 42
        if ($this->isSupervisor) {
533 8
            return $this->getSharedComponent()->getStrikeType();
534
        }
535
536 42
        return $this->strikeType;
537
    }
538
539 35
    public function setStrikeType(string $strikeType): self
540
    {
541 35
        if (!$this->isSupervisor) {
542 35
            $this->strikeType = $strikeType;
543
        } else {
544
            // should never be true
545
            // @codeCoverageIgnoreStart
546
            $styleArray = $this->getStyleArray(['strikeType' => $strikeType]);
547
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
548
            // @codeCoverageIgnoreEnd
549
        }
550
551 35
        return $this;
552
    }
553
554 42
    public function getUnderlineColor(): ?ChartColor
555
    {
556 42
        if ($this->isSupervisor) {
557 8
            return $this->getSharedComponent()->getUnderlineColor();
558
        }
559
560 42
        return $this->underlineColor;
561
    }
562
563 8
    public function setUnderlineColor(array $colorArray): self
564
    {
565 8
        if (!$this->isSupervisor) {
566 8
            $this->underlineColor = new ChartColor($colorArray);
567
        } else {
568
            // should never be true
569
            // @codeCoverageIgnoreStart
570
            $styleArray = $this->getStyleArray(['underlineColor' => $colorArray]);
571
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
572
            // @codeCoverageIgnoreEnd
573
        }
574
575 8
        return $this;
576
    }
577
578 61
    public function getChartColor(): ?ChartColor
579
    {
580 61
        if ($this->isSupervisor) {
581 8
            return $this->getSharedComponent()->getChartColor();
582
        }
583
584 61
        return $this->chartColor;
585
    }
586
587 30
    public function setChartColor(array $colorArray): self
588
    {
589 30
        if (!$this->isSupervisor) {
590 30
            $this->chartColor = new ChartColor($colorArray);
591
        } else {
592
            // should never be true
593
            // @codeCoverageIgnoreStart
594
            $styleArray = $this->getStyleArray(['chartColor' => $colorArray]);
595
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
596
            // @codeCoverageIgnoreEnd
597
        }
598
599 30
        return $this;
600
    }
601
602 12
    public function setChartColorFromObject(?ChartColor $chartColor): self
603
    {
604 12
        $this->chartColor = $chartColor;
605
606 12
        return $this;
607
    }
608
609
    /**
610
     * Get Underline.
611
     */
612 1042
    public function getUnderline(): ?string
613
    {
614 1042
        if ($this->isSupervisor) {
615 24
            return $this->getSharedComponent()->getUnderline();
616
        }
617
618 1042
        return $this->underline;
619
    }
620
621
    /**
622
     * Set Underline.
623
     *
624
     * @param bool|string $underlineStyle \PhpOffice\PhpSpreadsheet\Style\Font underline type
625
     *                                    If a boolean is passed, then TRUE equates to UNDERLINE_SINGLE,
626
     *                                        false equates to UNDERLINE_NONE
627
     *
628
     * @return $this
629
     */
630 552
    public function setUnderline($underlineStyle): static
631
    {
632 552
        if (is_bool($underlineStyle)) {
633 10
            $underlineStyle = ($underlineStyle) ? self::UNDERLINE_SINGLE : self::UNDERLINE_NONE;
634 545
        } elseif ($underlineStyle == '') {
635 2
            $underlineStyle = self::UNDERLINE_NONE;
636
        }
637 552
        if ($this->isSupervisor) {
638 32
            $styleArray = $this->getStyleArray(['underline' => $underlineStyle]);
639 32
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
640
        } else {
641 552
            $this->underline = $underlineStyle;
642
        }
643
644 552
        return $this;
645
    }
646
647
    /**
648
     * Get Strikethrough.
649
     */
650 992
    public function getStrikethrough(): ?bool
651
    {
652 992
        if ($this->isSupervisor) {
653 19
            return $this->getSharedComponent()->getStrikethrough();
654
        }
655
656 992
        return $this->strikethrough;
657
    }
658
659
    /**
660
     * Set Strikethrough.
661
     *
662
     * @return $this
663
     */
664 520
    public function setStrikethrough(bool $strikethru): static
665
    {
666 520
        if ($strikethru == '') {
667 510
            $strikethru = false;
668
        }
669
670 520
        if ($this->isSupervisor) {
671 10
            $styleArray = $this->getStyleArray(['strikethrough' => $strikethru]);
672 10
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
673
        } else {
674 520
            $this->strikethrough = $strikethru;
675
        }
676
677 520
        return $this;
678
    }
679
680
    /**
681
     * Get Color.
682
     */
683 1544
    public function getColor(): Color
684
    {
685 1544
        return $this->color;
686
    }
687
688
    /**
689
     * Set Color.
690
     *
691
     * @return $this
692
     */
693 83
    public function setColor(Color $color): static
694
    {
695
        // make sure parameter is a real color and not a supervisor
696 83
        $color = $color->getIsSupervisor() ? $color->getSharedComponent() : $color;
697
698 83
        if ($this->isSupervisor) {
699 11
            $styleArray = $this->getColor()->getStyleArray(['argb' => $color->getARGB()]);
700 11
            $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
701
        } else {
702 72
            $this->color = $color;
703
        }
704
705 83
        return $this;
706
    }
707
708 1299
    private function hashChartColor(?ChartColor $underlineColor): string
709
    {
710 1299
        if ($underlineColor === null) {
711 1299
            return '';
712
        }
713
714 1
        return
715 1
            $underlineColor->getValue()
716 1
            . $underlineColor->getType()
717 1
            . (string) $underlineColor->getAlpha();
718
    }
719
720
    /**
721
     * Get hash code.
722
     *
723
     * @return string Hash code
724
     */
725 1299
    public function getHashCode(): string
726
    {
727 1299
        if ($this->isSupervisor) {
728 1
            return $this->getSharedComponent()->getHashCode();
729
        }
730
731 1299
        return md5(
732 1299
            $this->name
733 1299
            . $this->size
734 1299
            . ($this->bold ? 't' : 'f')
735 1299
            . ($this->italic ? 't' : 'f')
736 1299
            . ($this->superscript ? 't' : 'f')
737 1299
            . ($this->subscript ? 't' : 'f')
738 1299
            . $this->underline
739 1299
            . ($this->strikethrough ? 't' : 'f')
740 1299
            . $this->color->getHashCode()
741 1299
            . $this->scheme
742 1299
            . implode(
743 1299
                '*',
744 1299
                [
745 1299
                    $this->latin,
746 1299
                    $this->eastAsian,
747 1299
                    $this->complexScript,
748 1299
                    $this->strikeType,
749 1299
                    $this->hashChartColor($this->chartColor),
750 1299
                    $this->hashChartColor($this->underlineColor),
751 1299
                    (string) $this->baseLine,
752 1299
                    (string) $this->cap,
753 1299
                ]
754 1299
            )
755 1299
            . __CLASS__
756 1299
        );
757
    }
758
759 14
    protected function exportArray1(): array
760
    {
761 14
        $exportedArray = [];
762 14
        $this->exportArray2($exportedArray, 'baseLine', $this->getBaseLine());
763 14
        $this->exportArray2($exportedArray, 'bold', $this->getBold());
764 14
        $this->exportArray2($exportedArray, 'cap', $this->getCap());
765 14
        $this->exportArray2($exportedArray, 'chartColor', $this->getChartColor());
766 14
        $this->exportArray2($exportedArray, 'color', $this->getColor());
767 14
        $this->exportArray2($exportedArray, 'complexScript', $this->getComplexScript());
768 14
        $this->exportArray2($exportedArray, 'eastAsian', $this->getEastAsian());
769 14
        $this->exportArray2($exportedArray, 'italic', $this->getItalic());
770 14
        $this->exportArray2($exportedArray, 'latin', $this->getLatin());
771 14
        $this->exportArray2($exportedArray, 'name', $this->getName());
772 14
        $this->exportArray2($exportedArray, 'scheme', $this->getScheme());
773 14
        $this->exportArray2($exportedArray, 'size', $this->getSize());
774 14
        $this->exportArray2($exportedArray, 'strikethrough', $this->getStrikethrough());
775 14
        $this->exportArray2($exportedArray, 'strikeType', $this->getStrikeType());
776 14
        $this->exportArray2($exportedArray, 'subscript', $this->getSubscript());
777 14
        $this->exportArray2($exportedArray, 'superscript', $this->getSuperscript());
778 14
        $this->exportArray2($exportedArray, 'underline', $this->getUnderline());
779 14
        $this->exportArray2($exportedArray, 'underlineColor', $this->getUnderlineColor());
780
781 14
        return $exportedArray;
782
    }
783
784 390
    public function getScheme(): string
785
    {
786 390
        if ($this->isSupervisor) {
787 9
            return $this->getSharedComponent()->getScheme();
788
        }
789
790 390
        return $this->scheme;
791
    }
792
793 985
    public function setScheme(string $scheme): self
794
    {
795 985
        if ($scheme === '' || $scheme === 'major' || $scheme === 'minor') {
796 985
            if ($this->isSupervisor) {
797 41
                $styleArray = $this->getStyleArray(['scheme' => $scheme]);
798 41
                $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
799
            } else {
800 985
                $this->scheme = $scheme;
801
            }
802
        }
803
804 985
        return $this;
805
    }
806
807
    /**
808
     * Set capitalization attribute. If not one of the permitted
809
     * values (all, small, or none), set it to null.
810
     * This will be honored only for the font for chart titles.
811
     * None is distinguished from null because null will inherit
812
     * the current value, whereas 'none' will override it.
813
     */
814 2
    public function setCap(string $cap): self
815
    {
816 2
        $this->cap = in_array($cap, self::VALID_CAPS, true) ? $cap : null;
817
818 2
        return $this;
819
    }
820
821 28
    public function getCap(): ?string
822
    {
823 28
        return $this->cap;
824
    }
825
826
    /**
827
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
828
     */
829 1107
    public function __clone()
830
    {
831 1107
        $this->color = clone $this->color;
832 1107
        $this->chartColor = ($this->chartColor === null) ? null : clone $this->chartColor;
833 1107
        $this->underlineColor = ($this->underlineColor === null) ? null : clone $this->underlineColor;
834
    }
835
}
836