Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ListItemRun
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 writeParagraph
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 writeParagraphProperties
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 writeParagraphPropertiesNumbering
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
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\Word2007\Element;
20
21use PhpOffice\PhpWord\Element\ListItemRun as ListItemRunElement;
22use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
23
24/**
25 * ListItemRun element writer.
26 *
27 * @since 0.10.0
28 */
29class ListItemRun extends AbstractElement
30{
31    /**
32     * Write list item element.
33     */
34    public function write(): void
35    {
36        $element = $this->getElement();
37
38        if (!$element instanceof ListItemRunElement) {
39            return;
40        }
41
42        $this->writeParagraph($element);
43    }
44
45    private function writeParagraph(ListItemRunElement $element): void
46    {
47        $xmlWriter = $this->getXmlWriter();
48        $xmlWriter->startElement('w:p');
49
50        $this->writeParagraphProperties($element);
51
52        $containerWriter = new Container($xmlWriter, $element);
53        $containerWriter->write();
54
55        $xmlWriter->endElement(); // w:p
56    }
57
58    private function writeParagraphProperties(ListItemRunElement $element): void
59    {
60        $xmlWriter = $this->getXmlWriter();
61        $xmlWriter->startElement('w:pPr');
62
63        $styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle());
64        $styleWriter->setIsInline(true);
65        $styleWriter->setWithoutPPR(true);
66        $styleWriter->write();
67
68        $this->writeParagraphPropertiesNumbering($element);
69
70        $xmlWriter->endElement(); // w:pPr
71    }
72
73    private function writeParagraphPropertiesNumbering(ListItemRunElement $element): void
74    {
75        $xmlWriter = $this->getXmlWriter();
76        $xmlWriter->startElement('w:numPr');
77
78        $xmlWriter->writeElementBlock('w:ilvl', [
79            'w:val' => $element->getDepth(),
80        ]);
81
82        $xmlWriter->writeElementBlock('w:numId', [
83            'w:val' => $element->getStyle()->getNumId(),
84        ]);
85
86        $xmlWriter->endElement(); // w:numPr
87    }
88}