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