Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
ListItem
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 getStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTextObject
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDepth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getText
100.00% covered (success)
100.00%
1 / 1
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\Element;
20
21use PhpOffice\PhpWord\Shared\Text as SharedText;
22use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
23
24/**
25 * List item element.
26 */
27class ListItem extends AbstractElement
28{
29    /**
30     * Element style.
31     *
32     * @var ?ListItemStyle
33     */
34    private $style;
35
36    /**
37     * Text object.
38     *
39     * @var Text
40     */
41    private $textObject;
42
43    /**
44     * Depth.
45     *
46     * @var int
47     */
48    private $depth;
49
50    /**
51     * Create a new ListItem.
52     *
53     * @param string $text
54     * @param int $depth
55     * @param mixed $fontStyle
56     * @param null|array|string $listStyle
57     * @param mixed $paragraphStyle
58     */
59    public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null)
60    {
61        $this->textObject = new Text(SharedText::toUTF8($text), $fontStyle, $paragraphStyle);
62        $this->depth = $depth;
63
64        // Version >= 0.10.0 will pass numbering style name. Older version will use old method
65        if (null !== $listStyle && is_string($listStyle)) {
66            $this->style = new ListItemStyle($listStyle); // @codeCoverageIgnore
67        } else {
68            $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
69        }
70    }
71
72    /**
73     * Get style.
74     *
75     * @return ?ListItemStyle
76     */
77    public function getStyle()
78    {
79        return $this->style;
80    }
81
82    /**
83     * Get Text object.
84     *
85     * @return Text
86     */
87    public function getTextObject()
88    {
89        return $this->textObject;
90    }
91
92    /**
93     * Get depth.
94     *
95     * @return int
96     */
97    public function getDepth()
98    {
99        return $this->depth;
100    }
101
102    /**
103     * Get text.
104     *
105     * @return string
106     *
107     * @since 0.11.0
108     */
109    public function getText()
110    {
111        return $this->textObject->getText();
112    }
113}