Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TablePosition
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
6
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
6
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
18namespace PhpOffice\PhpWord\Writer\Word2007\Style;
19
20/**
21 * TablePosition style writer.
22 */
23class TablePosition extends AbstractStyle
24{
25    /**
26     * Write style.
27     */
28    public function write(): void
29    {
30        $style = $this->getStyle();
31        if (!$style instanceof \PhpOffice\PhpWord\Style\TablePosition) {
32            return;
33        }
34
35        $values = [];
36        $properties = [
37            'leftFromText',
38            'rightFromText',
39            'topFromText',
40            'bottomFromText',
41            'vertAnchor',
42            'horzAnchor',
43            'tblpXSpec',
44            'tblpX',
45            'tblpYSpec',
46            'tblpY',
47        ];
48        foreach ($properties as $property) {
49            $method = 'get' . $property;
50            if (method_exists($style, $method)) {
51                $values[$property] = $style->$method();
52            }
53        }
54        $values = array_filter($values);
55
56        if ($values) {
57            $xmlWriter = $this->getXmlWriter();
58            $xmlWriter->startElement('w:tblpPr');
59            foreach ($values as $property => $value) {
60                $xmlWriter->writeAttribute('w:' . $property, $value);
61            }
62            $xmlWriter->endElement();
63        }
64    }
65}