Completed
Push — master ( 1ff41e...4d0f8f )
by Stefan
02:53
created

Style   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 173
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 18
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 173
ccs 49
cts 49
cp 1
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getId() 0 4 1
A setId() 0 5 1
A getFont() 0 7 2
A getFill() 0 7 2
A setFontName() 0 5 1
A setFontSize() 0 5 1
A setFontColor() 0 5 1
A setFontBold() 0 5 1
A setFontItalic() 0 5 1
A setFontUnderline() 0 5 1
A setFontStrikethrough() 0 5 1
A setFillColor() 0 5 1
A setFillPattern() 0 5 1
A lock() 0 4 1
A asXml() 0 4 1
1
<?php
2
3
namespace OneSheet\Style;
4
5
use OneSheet\Xml\StyleXml;
6
7
/**
8
 * Class Style
9
 *
10
 * @package OneSheet
11
 */
12
class Style implements Component
13
{
14
    /**
15
     * @var int
16
     */
17
    private $id;
18
19
    /**
20
     * @var Font
21
     */
22
    private $font;
23
24
    /**
25
     * @var Fill
26
     */
27
    private $fill;
28
29
    /**
30
     * @var bool
31
     */
32
    private $isLocked = false;
33
34
    /**
35
     * Style constructor.
36
     */
37 7
    public function __construct()
38
    {
39 7
        $this->font = new Font();
40 7
        $this->fill = new Fill();
41 7
    }
42
43
    /**
44
     * @return int|null
45
     */
46 5
    public function getId()
47
    {
48 5
        return $this->id;
49
    }
50
51
    /**
52
     * @param int $id
53
     * @return Style
54
     */
55 4
    public function setId($id)
56
    {
57 4
        $this->id = $id;
58 4
        return $this;
59
    }
60
61
    /**
62
     * @return Font
63
     */
64 6
    public function getFont()
65
    {
66 6
        if ($this->isLocked) {
67 3
            return clone $this->font;
68
        }
69 6
        return $this->font;
70
    }
71
72
    /**
73
     * @return Fill
74
     */
75 5
    public function getFill()
76
    {
77 5
        if ($this->isLocked) {
78 1
            return clone $this->fill;
79
        }
80 5
        return $this->fill;
81
    }
82
83
    /**
84
     * @param string $name
85
     * @return Style
86
     */
87 1
    public function setFontName($name)
88
    {
89 1
        $this->getFont()->setName($name);
90 1
        return $this;
91
    }
92
93
    /**
94
     * @param string $size
95
     * @return Style
96
     */
97 1
    public function setFontSize($size)
98
    {
99 1
        $this->getFont()->setSize($size);
100 1
        return $this;
101
    }
102
103
    /**
104
     * @param string $color
105
     * @return Style
106
     */
107 1
    public function setFontColor($color)
108
    {
109 1
        $this->getFont()->setColor($color);
110 1
        return $this;
111
    }
112
113
    /**
114
     * @return Style
115
     */
116 2
    public function setFontBold()
117
    {
118 2
        $this->getFont()->setBold();
119 2
        return $this;
120
    }
121
122
    /**
123
     * @return Style
124
     */
125 1
    public function setFontItalic()
126
    {
127 1
        $this->getFont()->setItalic();
128 1
        return $this;
129
    }
130
131
    /**
132
     * @return Style
133
     */
134 1
    public function setFontUnderline()
135
    {
136 1
        $this->getFont()->setUnderline();
137 1
        return $this;
138
    }
139
140
    /**
141
     * @return Style
142
     */
143 1
    public function setFontStrikethrough()
144
    {
145 1
        $this->getFont()->setStrikethrough();
146 1
        return $this;
147
    }
148
149
    /**
150
     * @param string $color
151
     * @return Style
152
     */
153 2
    public function setFillColor($color)
154
    {
155 2
        $this->getFill()->setColor($color);
156 2
        return $this;
157
    }
158
159
    /**
160
     * @param string $pattern
161
     * @return Style
162
     */
163 5
    public function setFillPattern($pattern)
164
    {
165 5
        $this->getFill()->setPattern($pattern);
166 5
        return $this;
167
    }
168
169
    /**
170
     * Lock current style.
171
     */
172 4
    public function lock()
173
    {
174 4
        $this->isLocked = true;
175 4
    }
176
177
    /**
178
     * @return string
179
     */
180 4
    public function asXml()
181
    {
182 4
        return sprintf(StyleXml::DEFAULT_XF_XML, $this->font->getId(), $this->fill->getId());
183
    }
184
}
185