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