Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.45% |
42 / 44 |
|
94.44% |
17 / 18 |
CRAP | |
0.00% |
0 / 1 |
Cell | |
95.45% |
42 / 44 |
|
94.44% |
17 / 18 |
21 | |
0.00% |
0 / 1 |
getVAlign | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setVAlign | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getTextDirection | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setTextDirection | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
getBgColor | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
setBgColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getGridSpan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setGridSpan | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getVMerge | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setVMerge | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getShading | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setShading | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setWidth | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getUnit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setUnit | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setNoWrap | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getNoWrap | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Style; |
19 | |
20 | use PhpOffice\PhpWord\SimpleType\TblWidth; |
21 | use PhpOffice\PhpWord\SimpleType\VerticalJc; |
22 | |
23 | /** |
24 | * Table cell style. |
25 | */ |
26 | class Cell extends Border |
27 | { |
28 | //Text direction constants |
29 | /** |
30 | * Left to Right, Top to Bottom. |
31 | */ |
32 | const TEXT_DIR_LRTB = 'lrTb'; |
33 | /** |
34 | * Top to Bottom, Right to Left. |
35 | */ |
36 | const TEXT_DIR_TBRL = 'tbRl'; |
37 | /** |
38 | * Bottom to Top, Left to Right. |
39 | */ |
40 | const TEXT_DIR_BTLR = 'btLr'; |
41 | /** |
42 | * Left to Right, Top to Bottom Rotated. |
43 | */ |
44 | const TEXT_DIR_LRTBV = 'lrTbV'; |
45 | /** |
46 | * Top to Bottom, Right to Left Rotated. |
47 | */ |
48 | const TEXT_DIR_TBRLV = 'tbRlV'; |
49 | /** |
50 | * Top to Bottom, Left to Right Rotated. |
51 | */ |
52 | const TEXT_DIR_TBLRV = 'tbLrV'; |
53 | |
54 | /** |
55 | * Vertical merge (rowspan) constants. |
56 | * |
57 | * @const string |
58 | */ |
59 | const VMERGE_RESTART = 'restart'; |
60 | const VMERGE_CONTINUE = 'continue'; |
61 | |
62 | /** |
63 | * Default border color. |
64 | * |
65 | * @const string |
66 | */ |
67 | const DEFAULT_BORDER_COLOR = '000000'; |
68 | |
69 | /** |
70 | * Vertical align (top, center, both, bottom). |
71 | * |
72 | * @var null|string |
73 | */ |
74 | private $vAlign; |
75 | |
76 | /** |
77 | * Text Direction. |
78 | * |
79 | * @var string |
80 | */ |
81 | private $textDirection; |
82 | |
83 | /** |
84 | * colspan. |
85 | * |
86 | * @var int |
87 | */ |
88 | private $gridSpan; |
89 | |
90 | /** |
91 | * rowspan (restart, continue). |
92 | * |
93 | * - restart: Start/restart merged region |
94 | * - continue: Continue merged region |
95 | * |
96 | * @var null|string |
97 | */ |
98 | private $vMerge; |
99 | |
100 | /** |
101 | * Shading. |
102 | * |
103 | * @var \PhpOffice\PhpWord\Style\Shading |
104 | */ |
105 | private $shading; |
106 | |
107 | /** |
108 | * Width. |
109 | * |
110 | * @var ?int |
111 | */ |
112 | private $width; |
113 | |
114 | /** |
115 | * Width unit. |
116 | * |
117 | * @var string |
118 | */ |
119 | private $unit = TblWidth::TWIP; |
120 | |
121 | /** |
122 | * Prevent text from wrapping in the cell. |
123 | * |
124 | * @var bool |
125 | */ |
126 | private $noWrap = true; |
127 | |
128 | /** |
129 | * Get vertical align. |
130 | * |
131 | * @return null|string |
132 | */ |
133 | public function getVAlign() |
134 | { |
135 | return $this->vAlign; |
136 | } |
137 | |
138 | /** |
139 | * Set vertical align. |
140 | * |
141 | * @param null|string $value |
142 | * |
143 | * @return self |
144 | */ |
145 | public function setVAlign($value = null) |
146 | { |
147 | if ($value === null) { |
148 | $this->vAlign = null; |
149 | |
150 | return $this; |
151 | } |
152 | |
153 | VerticalJc::validate($value); |
154 | $this->vAlign = $this->setEnumVal($value, VerticalJc::values(), $this->vAlign); |
155 | |
156 | return $this; |
157 | } |
158 | |
159 | /** |
160 | * Get text direction. |
161 | * |
162 | * @return string |
163 | */ |
164 | public function getTextDirection() |
165 | { |
166 | return $this->textDirection; |
167 | } |
168 | |
169 | /** |
170 | * Set text direction. |
171 | * |
172 | * @param string $value |
173 | * |
174 | * @return self |
175 | */ |
176 | public function setTextDirection($value = null) |
177 | { |
178 | $enum = [ |
179 | self::TEXT_DIR_BTLR, |
180 | self::TEXT_DIR_TBRL, |
181 | self::TEXT_DIR_LRTB, |
182 | self::TEXT_DIR_LRTBV, |
183 | self::TEXT_DIR_TBRLV, |
184 | self::TEXT_DIR_TBLRV, |
185 | ]; |
186 | $this->textDirection = $this->setEnumVal($value, $enum, $this->textDirection); |
187 | |
188 | return $this; |
189 | } |
190 | |
191 | /** |
192 | * Get background. |
193 | * |
194 | * @return string |
195 | */ |
196 | public function getBgColor() |
197 | { |
198 | if ($this->shading !== null) { |
199 | return $this->shading->getFill(); |
200 | } |
201 | |
202 | return null; |
203 | } |
204 | |
205 | /** |
206 | * Set background. |
207 | * |
208 | * @param string $value |
209 | * |
210 | * @return self |
211 | */ |
212 | public function setBgColor($value = null) |
213 | { |
214 | return $this->setShading(['fill' => $value]); |
215 | } |
216 | |
217 | /** |
218 | * Get grid span (colspan). |
219 | * |
220 | * @return int |
221 | */ |
222 | public function getGridSpan() |
223 | { |
224 | return $this->gridSpan; |
225 | } |
226 | |
227 | /** |
228 | * Set grid span (colspan). |
229 | * |
230 | * @param int $value |
231 | * |
232 | * @return self |
233 | */ |
234 | public function setGridSpan($value = null) |
235 | { |
236 | $this->gridSpan = $this->setIntVal($value, $this->gridSpan); |
237 | |
238 | return $this; |
239 | } |
240 | |
241 | /** |
242 | * Get vertical merge (rowspan). |
243 | * |
244 | * @return null|string |
245 | */ |
246 | public function getVMerge() |
247 | { |
248 | return $this->vMerge; |
249 | } |
250 | |
251 | /** |
252 | * Set vertical merge (rowspan). |
253 | * |
254 | * @param null|string $value |
255 | * |
256 | * @return self |
257 | */ |
258 | public function setVMerge($value = null) |
259 | { |
260 | if ($value === null) { |
261 | $this->vMerge = null; |
262 | |
263 | return $this; |
264 | } |
265 | |
266 | $enum = [self::VMERGE_RESTART, self::VMERGE_CONTINUE]; |
267 | $this->vMerge = $this->setEnumVal($value, $enum, $this->vMerge); |
268 | |
269 | return $this; |
270 | } |
271 | |
272 | /** |
273 | * Get shading. |
274 | * |
275 | * @return \PhpOffice\PhpWord\Style\Shading |
276 | */ |
277 | public function getShading() |
278 | { |
279 | return $this->shading; |
280 | } |
281 | |
282 | /** |
283 | * Set shading. |
284 | * |
285 | * @param mixed $value |
286 | * |
287 | * @return self |
288 | */ |
289 | public function setShading($value = null) |
290 | { |
291 | $this->setObjectVal($value, 'Shading', $this->shading); |
292 | |
293 | return $this; |
294 | } |
295 | |
296 | /** |
297 | * Get cell width. |
298 | * |
299 | * @return ?int |
300 | */ |
301 | public function getWidth() |
302 | { |
303 | return $this->width; |
304 | } |
305 | |
306 | /** |
307 | * Set cell width. |
308 | * |
309 | * @param int $value |
310 | * |
311 | * @return self |
312 | */ |
313 | public function setWidth($value) |
314 | { |
315 | $this->width = $this->setIntVal($value); |
316 | |
317 | return $this; |
318 | } |
319 | |
320 | /** |
321 | * Get width unit. |
322 | * |
323 | * @return string |
324 | */ |
325 | public function getUnit() |
326 | { |
327 | return $this->unit; |
328 | } |
329 | |
330 | /** |
331 | * Set width unit. |
332 | * |
333 | * @param string $value |
334 | */ |
335 | public function setUnit($value) |
336 | { |
337 | $this->unit = $this->setEnumVal($value, [TblWidth::AUTO, TblWidth::PERCENT, TblWidth::TWIP], TblWidth::TWIP); |
338 | |
339 | return $this; |
340 | } |
341 | |
342 | /** |
343 | * Set noWrap. |
344 | */ |
345 | public function setNoWrap(bool $value): self |
346 | { |
347 | $this->noWrap = $this->setBoolVal($value, true); |
348 | |
349 | return $this; |
350 | } |
351 | |
352 | /** |
353 | * Get noWrap. |
354 | */ |
355 | public function getNoWrap(): bool |
356 | { |
357 | return $this->noWrap; |
358 | } |
359 | } |