Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
TextBreak
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
6 / 6
13
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
 setFontStyle
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 getFontStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setParagraphStyle
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 getParagraphStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
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\Element;
19
20use PhpOffice\PhpWord\Style\Font;
21use PhpOffice\PhpWord\Style\Paragraph;
22
23/**
24 * Text break element.
25 */
26class TextBreak extends AbstractElement
27{
28    /**
29     * Paragraph style.
30     *
31     * @var null|\PhpOffice\PhpWord\Style\Paragraph|string
32     */
33    private $paragraphStyle;
34
35    /**
36     * Text style.
37     *
38     * @var null|\PhpOffice\PhpWord\Style\Font|string
39     */
40    private $fontStyle;
41
42    /**
43     * Create a new TextBreak Element.
44     *
45     * @param mixed $fontStyle
46     * @param mixed $paragraphStyle
47     */
48    public function __construct($fontStyle = null, $paragraphStyle = null)
49    {
50        if (null !== $paragraphStyle) {
51            $paragraphStyle = $this->setParagraphStyle($paragraphStyle);
52        }
53        if (null !== $fontStyle) {
54            $this->setFontStyle($fontStyle, $paragraphStyle);
55        }
56    }
57
58    /**
59     * Set Text style.
60     *
61     * @param mixed $style
62     * @param mixed $paragraphStyle
63     *
64     * @return \PhpOffice\PhpWord\Style\Font|string
65     */
66    public function setFontStyle($style = null, $paragraphStyle = null)
67    {
68        if ($style instanceof Font) {
69            $this->fontStyle = $style;
70            $this->setParagraphStyle($paragraphStyle);
71        } elseif (is_array($style)) {
72            $this->fontStyle = new Font('text', $paragraphStyle);
73            $this->fontStyle->setStyleByArray($style);
74        } else {
75            $this->fontStyle = $style;
76            $this->setParagraphStyle($paragraphStyle);
77        }
78
79        return $this->fontStyle;
80    }
81
82    /**
83     * Get Text style.
84     *
85     * @return null|\PhpOffice\PhpWord\Style\Font|string
86     */
87    public function getFontStyle()
88    {
89        return $this->fontStyle;
90    }
91
92    /**
93     * Set Paragraph style.
94     *
95     * @param   array|\PhpOffice\PhpWord\Style\Paragraph|string $style
96     *
97     * @return  \PhpOffice\PhpWord\Style\Paragraph|string
98     */
99    public function setParagraphStyle($style = null)
100    {
101        if (is_array($style)) {
102            $this->paragraphStyle = new Paragraph();
103            $this->paragraphStyle->setStyleByArray($style);
104        } elseif ($style instanceof Paragraph) {
105            $this->paragraphStyle = $style;
106        } else {
107            $this->paragraphStyle = $style;
108        }
109
110        return $this->paragraphStyle;
111    }
112
113    /**
114     * Get Paragraph style.
115     *
116     * @return null|\PhpOffice\PhpWord\Style\Paragraph|string
117     */
118    public function getParagraphStyle()
119    {
120        return $this->paragraphStyle;
121    }
122
123    /**
124     * Has font/paragraph style defined.
125     *
126     * @return bool
127     */
128    public function hasStyle()
129    {
130        return null !== $this->fontStyle || null !== $this->paragraphStyle;
131    }
132}