Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Control
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
1 / 2
10.02
0.00% covered (danger)
0.00%
0 / 1
 writeControlAnchor
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
 writeControlText
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
6.03
1<?php
2
3/**
4 * This file is part of PHPWord - A pure PHP library for reading and writing
5 * document files.
6 *
7 * PHPWord is free software distributed under the terms of the GNU Lesser
8 * General Public License 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\ODText\Element;
20
21use PhpOffice\PhpWord\Element\Text;
22
23/**
24 * Base writer for inline ODF form controls.
25 */
26abstract class Control extends AbstractElement
27{
28    /**
29     * @param mixed $fontStyle
30     */
31    protected function writeControlAnchor(string $id, ?string $name, ?string $text, $fontStyle = null): void
32    {
33        $xmlWriter = $this->getXmlWriter();
34        $xmlWriter->startElement('draw:control');
35        $xmlWriter->writeAttribute('draw:control', $id);
36        $xmlWriter->writeAttribute('draw:name', $name ?: $id);
37        if ($fontStyle && is_string($fontStyle)) {
38            $xmlWriter->writeAttribute('draw:text-style-name', $fontStyle);
39        }
40        $xmlWriter->endElement();
41    }
42
43    protected function writeControlText(Text $element, ?string $text): void
44    {
45        if ($text === null || $text === '') {
46            return;
47        }
48        $xmlWriter = $this->getXmlWriter();
49        $fontStyle = $element->getFontStyle();
50        if ($fontStyle) {
51            $xmlWriter->startElement('text:span');
52            if (is_string($fontStyle)) {
53                $xmlWriter->writeAttribute('text:style-name', $fontStyle);
54            }
55        }
56        $this->replaceTabs($text, $xmlWriter);
57        if ($fontStyle) {
58            $xmlWriter->endElement();
59        }
60    }
61}