Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractElement
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
6
100.00% covered (success)
100.00%
1 / 1
 replaceTabs
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
6
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\ODText\Element;
20
21use PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement as Word2007AbstractElement;
22
23/**
24 * Abstract element writer.
25 *
26 * @since 0.11.0
27 */
28abstract class AbstractElement extends Word2007AbstractElement
29{
30    protected function replaceTabs($text, $xmlWriter): void
31    {
32        if (preg_match('/^ +/', $text, $matches)) {
33            $num = strlen($matches[0]);
34            $xmlWriter->startElement('text:s');
35            $xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num");
36            $xmlWriter->endElement();
37            $text = preg_replace('/^ +/', '', $text);
38        }
39        preg_match_all('/([\\s\\S]*?)(\\t|  +| ?$)/', $text, $matches, PREG_SET_ORDER);
40        foreach ($matches as $match) {
41            $this->writeText($match[1]);
42            if ($match[2] === '') {
43                break;
44            } elseif ($match[2] === "\t") {
45                $xmlWriter->writeElement('text:tab');
46            } elseif ($match[2] === ' ') {
47                $xmlWriter->writeElement('text:s');
48
49                break;
50            } else {
51                $num = strlen($match[2]);
52                $xmlWriter->startElement('text:s');
53                $xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num");
54                $xmlWriter->endElement();
55            }
56        }
57    }
58}