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