Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
AbstractStyle | |
100.00% |
15 / 15 |
|
100.00% |
6 / 6 |
12 | |
100.00% |
1 / 1 |
write | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setParentWriter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getParentWriter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStyle | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
assembleCss | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
getValueIf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
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\Writer\HTML\Style; |
19 | |
20 | use PhpOffice\PhpWord\Style\AbstractStyle as StyleAbstract; |
21 | use PhpOffice\PhpWord\Writer\HTML; |
22 | |
23 | /** |
24 | * Style writer. |
25 | * |
26 | * @since 0.10.0 |
27 | */ |
28 | abstract class AbstractStyle |
29 | { |
30 | /** |
31 | * Parent writer. |
32 | * |
33 | * @var HTML |
34 | */ |
35 | private $parentWriter; |
36 | |
37 | /** |
38 | * Style. |
39 | * |
40 | * @var null|array|StyleAbstract |
41 | */ |
42 | private $style; |
43 | |
44 | /** |
45 | * Write style. |
46 | * |
47 | * @return mixed |
48 | */ |
49 | abstract public function write(); |
50 | |
51 | /** |
52 | * Create new instance. |
53 | * |
54 | * @param array|StyleAbstract $style |
55 | */ |
56 | public function __construct($style = null) |
57 | { |
58 | $this->style = $style; |
59 | } |
60 | |
61 | /** |
62 | * Set parent writer. |
63 | * |
64 | * @param HTML $writer |
65 | */ |
66 | public function setParentWriter($writer): void |
67 | { |
68 | $this->parentWriter = $writer; |
69 | } |
70 | |
71 | /** |
72 | * Get parent writer. |
73 | * |
74 | * @return HTML |
75 | */ |
76 | public function getParentWriter() |
77 | { |
78 | return $this->parentWriter; |
79 | } |
80 | |
81 | /** |
82 | * Get style. |
83 | * |
84 | * @return null|array|string|StyleAbstract |
85 | */ |
86 | public function getStyle() |
87 | { |
88 | if (!$this->style instanceof StyleAbstract && !is_array($this->style)) { |
89 | return ''; |
90 | } |
91 | |
92 | return $this->style; |
93 | } |
94 | |
95 | /** |
96 | * Takes array where of CSS properties / values and converts to CSS string. |
97 | * |
98 | * @param array $css |
99 | * |
100 | * @return string |
101 | */ |
102 | protected function assembleCss($css) |
103 | { |
104 | $pairs = []; |
105 | $string = ''; |
106 | foreach ($css as $key => $value) { |
107 | if ($value != '') { |
108 | $pairs[] = $key . ': ' . $value; |
109 | } |
110 | } |
111 | if (!empty($pairs)) { |
112 | $string = implode('; ', $pairs) . ';'; |
113 | } |
114 | |
115 | return $string; |
116 | } |
117 | |
118 | /** |
119 | * Get value if ... |
120 | * |
121 | * @param null|bool $condition |
122 | * @param string $value |
123 | * |
124 | * @return string |
125 | */ |
126 | protected function getValueIf($condition, $value) |
127 | { |
128 | return $condition == true ? $value : ''; |
129 | } |
130 | } |