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