Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Container
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
5
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\RTF\Element;
19
20use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
21
22/**
23 * Container element RTF writer.
24 *
25 * @since 0.11.0
26 */
27class Container extends AbstractElement
28{
29    /**
30     * Namespace; Can't use __NAMESPACE__ in inherited class (RTF).
31     *
32     * @var string
33     */
34    protected $namespace = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element';
35
36    /**
37     * Write container.
38     *
39     * @return string
40     */
41    public function write()
42    {
43        $container = $this->element;
44        if (!$container instanceof ContainerElement) {
45            return '';
46        }
47        $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
48        $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote']) ? true : false;
49        $content = '';
50
51        $elements = $container->getElements();
52        foreach ($elements as $element) {
53            $elementClass = get_class($element);
54            $writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass);
55            if (class_exists($writerClass)) {
56                /** @var AbstractElement $writer Type hint */
57                $writer = new $writerClass($this->parentWriter, $element, $withoutP);
58                $content .= $writer->write();
59            }
60        }
61
62        return $content;
63    }
64}