Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
TextRun | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getParagraphStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setParagraphStyle | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
getText | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 |
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 | |
18 | namespace PhpOffice\PhpWord\Element; |
19 | |
20 | use PhpOffice\PhpWord\Style\Paragraph; |
21 | |
22 | /** |
23 | * Textrun/paragraph element. |
24 | */ |
25 | class TextRun extends AbstractContainer |
26 | { |
27 | /** |
28 | * @var string Container type |
29 | */ |
30 | protected $container = 'TextRun'; |
31 | |
32 | /** |
33 | * Paragraph style. |
34 | * |
35 | * @var Paragraph|string |
36 | */ |
37 | protected $paragraphStyle; |
38 | |
39 | /** |
40 | * Create new instance. |
41 | * |
42 | * @param array|Paragraph|string $paragraphStyle |
43 | */ |
44 | public function __construct($paragraphStyle = null) |
45 | { |
46 | $this->paragraphStyle = $this->setParagraphStyle($paragraphStyle); |
47 | } |
48 | |
49 | /** |
50 | * Get Paragraph style. |
51 | * |
52 | * @return Paragraph|string |
53 | */ |
54 | public function getParagraphStyle() |
55 | { |
56 | return $this->paragraphStyle; |
57 | } |
58 | |
59 | /** |
60 | * Set Paragraph style. |
61 | * |
62 | * @param array|Paragraph|string $style |
63 | * |
64 | * @return Paragraph|string |
65 | */ |
66 | public function setParagraphStyle($style = null) |
67 | { |
68 | if (is_array($style)) { |
69 | $this->paragraphStyle = new Paragraph(); |
70 | $this->paragraphStyle->setStyleByArray($style); |
71 | } elseif ($style instanceof Paragraph) { |
72 | $this->paragraphStyle = $style; |
73 | } elseif (null === $style) { |
74 | $this->paragraphStyle = new Paragraph(); |
75 | } else { |
76 | $this->paragraphStyle = $style; |
77 | } |
78 | |
79 | return $this->paragraphStyle; |
80 | } |
81 | |
82 | public function getText(): string |
83 | { |
84 | $outstr = ''; |
85 | foreach ($this->getElements() as $element) { |
86 | if ($element instanceof Text) { |
87 | $outstr .= $element->getText(); |
88 | } |
89 | } |
90 | |
91 | return $outstr; |
92 | } |
93 | } |