Failed Conditions
Push — master ( 8e3417...f52ae2 )
by
unknown
18:26 queued 07:14
created

StyleMerger::mergeFillStyle()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 8
nop 2
crap 4
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
4
5
use PhpOffice\PhpSpreadsheet\Style\Border;
6
use PhpOffice\PhpSpreadsheet\Style\Borders;
7
use PhpOffice\PhpSpreadsheet\Style\Fill;
8
use PhpOffice\PhpSpreadsheet\Style\Font;
9
use PhpOffice\PhpSpreadsheet\Style\Style;
10
11
class StyleMerger
12
{
13
    protected Style $baseStyle;
14
15 15
    public function __construct(Style $baseStyle)
16
    {
17 15
        $this->baseStyle = $baseStyle;
18
    }
19
20 14
    public function getStyle(): Style
21
    {
22 14
        return $this->baseStyle;
23
    }
24
25 13
    public function mergeStyle(Style $style): void
26
    {
27 13
        if ($style->getNumberFormat()->getFormatCode() !== null) {
28 8
            $this->baseStyle->getNumberFormat()->setFormatCode($style->getNumberFormat()->getFormatCode());
29
        }
30 13
        $this->mergeFontStyle($this->baseStyle->getFont(), $style->getFont());
31 13
        $this->mergeFillStyle($this->baseStyle->getFill(), $style->getFill());
32 13
        $this->mergeBordersStyle($this->baseStyle->getBorders(), $style->getBorders());
33
    }
34
35 13
    protected function mergeFontStyle(Font $baseFontStyle, Font $fontStyle): void
36
    {
37 13
        if ($fontStyle->getBold() !== null) {
38 8
            $baseFontStyle->setBold($fontStyle->getBold());
39
        }
40 13
        if ($fontStyle->getItalic() !== null) {
41 8
            $baseFontStyle->setItalic($fontStyle->getItalic());
42
        }
43 13
        if ($fontStyle->getStrikethrough() !== null) {
44 8
            $baseFontStyle->setStrikethrough($fontStyle->getStrikethrough());
45
        }
46 13
        if ($fontStyle->getUnderline() !== null) {
47 8
            $baseFontStyle->setUnderline($fontStyle->getUnderline());
48
        }
49 13
        if ($fontStyle->getColor()->getARGB() !== null) {
50 10
            $baseFontStyle->setColor($fontStyle->getColor());
51
        }
52
    }
53
54 13
    protected function mergeFillStyle(Fill $baseFillStyle, Fill $fillStyle): void
55
    {
56 13
        if ($fillStyle->getFillType() !== null) {
57 13
            $baseFillStyle->setFillType($fillStyle->getFillType());
58
        }
59 13
        $baseFillStyle->setRotation($fillStyle->getRotation());
60 13
        if ($fillStyle->getStartColor()->getARGB() !== null) {
61 13
            $baseFillStyle->setStartColor($fillStyle->getStartColor());
62
        }
63 13
        if ($fillStyle->getEndColor()->getARGB() !== null) {
64 10
            $baseFillStyle->setEndColor($fillStyle->getEndColor());
65
        }
66
    }
67
68 13
    protected function mergeBordersStyle(Borders $baseBordersStyle, Borders $bordersStyle): void
69
    {
70 13
        $this->mergeBorderStyle($baseBordersStyle->getTop(), $bordersStyle->getTop());
71 13
        $this->mergeBorderStyle($baseBordersStyle->getBottom(), $bordersStyle->getBottom());
72 13
        $this->mergeBorderStyle($baseBordersStyle->getLeft(), $bordersStyle->getLeft());
73 13
        $this->mergeBorderStyle($baseBordersStyle->getRight(), $bordersStyle->getRight());
74
    }
75
76 13
    protected function mergeBorderStyle(Border $baseBorderStyle, Border $borderStyle): void
77
    {
78 13
        $baseBorderStyle->setBorderStyle($borderStyle->getBorderStyle());
79 13
        if ($borderStyle->getColor()->getARGB() !== null) {
80 13
            $baseBorderStyle->setColor($borderStyle->getColor());
81
        }
82
    }
83
}
84