Completed
Pull Request — master (#699)
by Adrien
01:41
created

StyleBuilder::setBorder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Box\Spout\Writer\Common\Creator\Style;
4
5
use Box\Spout\Common\Entity\Style\Border;
6
use Box\Spout\Common\Entity\Style\CellAlignment;
7
use Box\Spout\Common\Entity\Style\Style;
8
use Box\Spout\Common\Exception\InvalidArgumentException;
9
10
/**
11
 * Class StyleBuilder
12
 * Builder to create new styles
13
 */
14
class StyleBuilder
15
{
16
    /** @var Style Style to be created */
17
    protected $style;
18
19
    /**
20 108
     *
21
     */
22 108
    public function __construct()
23 108
    {
24
        $this->style = new Style();
25
    }
26
27
    /**
28
     * Makes the font bold.
29
     *
30 21
     * @return StyleBuilder
31
     */
32 21
    public function setFontBold()
33
    {
34 21
        $this->style->setFontBold();
35
36
        return $this;
37
    }
38
39
    /**
40
     * Makes the font italic.
41
     *
42 7
     * @return StyleBuilder
43
     */
44 7
    public function setFontItalic()
45
    {
46 7
        $this->style->setFontItalic();
47
48
        return $this;
49
    }
50
51
    /**
52
     * Makes the font underlined.
53
     *
54 7
     * @return StyleBuilder
55
     */
56 7
    public function setFontUnderline()
57
    {
58 7
        $this->style->setFontUnderline();
59
60
        return $this;
61
    }
62
63
    /**
64
     * Makes the font struck through.
65
     *
66 4
     * @return StyleBuilder
67
     */
68 4
    public function setFontStrikethrough()
69
    {
70 4
        $this->style->setFontStrikethrough();
71
72
        return $this;
73
    }
74
75
    /**
76
     * Sets the font size.
77
     *
78
     * @param int $fontSize Font size, in pixels
79 52
     * @return StyleBuilder
80
     */
81 52
    public function setFontSize($fontSize)
82
    {
83 52
        $this->style->setFontSize($fontSize);
84
85
        return $this;
86
    }
87
88
    /**
89
     * Sets the font color.
90
     *
91
     * @param string $fontColor ARGB color (@see Color)
92 3
     * @return StyleBuilder
93
     */
94 3
    public function setFontColor($fontColor)
95
    {
96 3
        $this->style->setFontColor($fontColor);
97
98
        return $this;
99
    }
100
101
    /**
102
     * Sets the font name.
103
     *
104
     * @param string $fontName Name of the font to use
105 50
     * @return StyleBuilder
106
     */
107 50
    public function setFontName($fontName)
108
    {
109 50
        $this->style->setFontName($fontName);
110
111
        return $this;
112
    }
113
114
    /**
115
     * Makes the text wrap in the cell if requested
116
     *
117
     * @param bool $shouldWrap Should the text be wrapped
118 4
     * @return StyleBuilder
119
     */
120 4
    public function setShouldWrapText($shouldWrap = true)
121
    {
122 4
        $this->style->setShouldWrapText($shouldWrap);
123
124
        return $this;
125
    }
126
127
    /**
128
     * Sets the cell alignment.
129
     *
130
     * @param string $cellAlignment The cell alignment
131 8
     *
132
     * @throws InvalidArgumentException If the given cell alignment is not valid
133 8
     * @return StyleBuilder
134
     */
135 8
    public function setCellAlignment($cellAlignment)
136
    {
137
        if (!CellAlignment::isValid($cellAlignment)) {
138
            throw new InvalidArgumentException('Invalid cell alignment value');
139
        }
140
141
        $this->style->setCellAlignment($cellAlignment);
142
143
        return $this;
144 7
    }
145
146 7
    /**
147
     * Set a border
148 7
     *
149
     * @param Border $border
150
     * @return $this
151
     */
152
    public function setBorder(Border $border)
153
    {
154
        $this->style->setBorder($border);
155
156
        return $this;
157
    }
158 3
159
    /**
160 3
     *  Sets a background color
161
     *
162 3
     * @param string $color ARGB color (@see Color)
163
     * @return StyleBuilder
164
     */
165
    public function setBackgroundColor($color)
166
    {
167
        $this->style->setBackgroundColor($color);
168
169
        return $this;
170 108
    }
171
172 108
    /**
173
     *  Sets a format
174
     *
175
     * @param string $format Format
176
     * @return StyleBuilder
177
     * @api
178
     */
179
    public function setFormat($format)
180
    {
181
        $this->style->setFormat($format);
182
183
        return $this;
184
    }
185
186
    /**
187
     * Returns the configured style. The style is cached and can be reused.
188
     *
189
     * @return Style
190
     */
191
    public function build()
192
    {
193
        return $this->style;
194
    }
195
}
196