Completed
Push — develop ( d7bbf5...5d23e6 )
by Franck
12s
created

Paragraph::setLineSpacing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation 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/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Shape\RichText;
19
20
use PhpOffice\PhpPresentation\ComparableInterface;
21
use PhpOffice\PhpPresentation\Style\Alignment;
22
use PhpOffice\PhpPresentation\Style\Bullet;
23
use PhpOffice\PhpPresentation\Style\Font;
24
25
/**
26
 * \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
27
 */
28
class Paragraph implements ComparableInterface
29
{
30
    /**
31
     * Rich text elements
32
     *
33
     * @var \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[]
34
     */
35
    private $richTextElements;
36
37
    /**
38
     * Alignment
39
     *
40
     * @var \PhpOffice\PhpPresentation\Style\Alignment
41
     */
42
    private $alignment;
43
44
    /**
45
     * Font
46
     *
47
     * @var \PhpOffice\PhpPresentation\Style\Font
48
     */
49
    private $font;
50
51
    /**
52
     * Bullet style
53
     *
54
     * @var \PhpOffice\PhpPresentation\Style\Bullet
55
     */
56
    private $bulletStyle;
57
58
    /**
59
     * @var integer
60
     */
61
    private $lineSpacing = 100;
62
63
    /**
64
     * Hash index
65
     *
66
     * @var string
67
     */
68
    private $hashIndex;
69
70
    /**
71
     * Create a new \PhpOffice\PhpPresentation\Shape\RichText\Paragraph instance
72
     */
73 264
    public function __construct()
74
    {
75
        // Initialise variables
76 264
        $this->richTextElements = array();
77 264
        $this->alignment = new Alignment();
78 264
        $this->font = new Font();
79 264
        $this->bulletStyle = new Bullet();
80 264
    }
81
82
    /**
83
     * Get alignment
84
     *
85
     * @return \PhpOffice\PhpPresentation\Style\Alignment
86
     */
87 203
    public function getAlignment()
88
    {
89 203
        return $this->alignment;
90
    }
91
92
    /**
93
     * Set alignment
94
     *
95
     * @param  \PhpOffice\PhpPresentation\Style\Alignment $alignment
96
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
97
     */
98 13
    public function setAlignment(Alignment $alignment)
99
    {
100 13
        $this->alignment = $alignment;
101
102 13
        return $this;
103
    }
104
105
    /**
106
     * Get font
107
     *
108
     * @return \PhpOffice\PhpPresentation\Style\Font
109
     */
110 204
    public function getFont()
111
    {
112 204
        return $this->font;
113
    }
114
115
    /**
116
     * Set font
117
     *
118
     * @param  \PhpOffice\PhpPresentation\Style\Font $pFont Font
119
     * @throws \Exception
120
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
121
     */
122 13
    public function setFont(Font $pFont = null)
123
    {
124 13
        $this->font = $pFont;
125
126 13
        return $this;
127
    }
128
129
    /**
130
     * Get bullet style
131
     *
132
     * @return \PhpOffice\PhpPresentation\Style\Bullet
133
     */
134 58
    public function getBulletStyle()
135
    {
136 58
        return $this->bulletStyle;
137
    }
138
139
    /**
140
     * Set bullet style
141
     *
142
     * @param  \PhpOffice\PhpPresentation\Style\Bullet $style
143
     * @throws \Exception
144
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
145
     */
146 13
    public function setBulletStyle(Bullet $style = null)
147
    {
148 13
        $this->bulletStyle = $style;
149
150 13
        return $this;
151
    }
152
153
    /**
154
     * Create text (can not be formatted !)
155
     *
156
     * @param  string $pText Text
157
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElement
158
     * @throws \Exception
159
     */
160 4
    public function createText($pText = '')
161
    {
162 4
        $objText = new TextElement($pText);
163 4
        $this->addText($objText);
164
165 4
        return $objText;
166
    }
167
168
    /**
169
     * Add text
170
     *
171
     * @param  \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface $pText Rich text element
172
     * @throws \Exception
173
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
174
     */
175 53
    public function addText(TextElementInterface $pText = null)
176
    {
177 53
        $this->richTextElements[] = $pText;
178
179 53
        return $this;
180
    }
181
182
    /**
183
     * Create break
184
     *
185
     * @return \PhpOffice\PhpPresentation\Shape\RichText\BreakElement
186
     * @throws \Exception
187
     */
188 12
    public function createBreak()
189
    {
190 12
        $objText = new BreakElement();
191 12
        $this->addText($objText);
192
193 12
        return $objText;
194
    }
195
196
    /**
197
     * Create text run (can be formatted)
198
     *
199
     * @param  string $pText Text
200
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Run
201
     * @throws \Exception
202
     */
203 49
    public function createTextRun($pText = '')
204
    {
205 49
        $objText = new Run($pText);
206 49
        $objText->setFont(clone $this->font);
207 49
        $this->addText($objText);
208
209 49
        return $objText;
210
    }
211
212
    /**
213
     * Convert to string
214
     *
215
     * @return string
216
     */
217 1
    public function __toString()
218
    {
219 1
        return $this->getPlainText();
220
    }
221
222
    /**
223
     * Get plain text
224
     *
225
     * @return string
226
     */
227 3
    public function getPlainText()
228
    {
229
        // Return value
230 3
        $returnValue = '';
231
232
        // Loop trough all \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
233 3
        foreach ($this->richTextElements as $text) {
234 3
            if ($text instanceof TextElementInterface) {
235 3
                $returnValue .= $text->getText();
236
            }
237
        }
238
239
        // Return
240 3
        return $returnValue;
241
    }
242
243
    /**
244
     * Get Rich Text elements
245
     *
246
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[]
247
     */
248 61
    public function getRichTextElements()
249
    {
250 61
        return $this->richTextElements;
251
    }
252
253
    /**
254
     * Set Rich Text elements
255
     *
256
     * @param  \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] $pElements Array of elements
257
     * @throws \Exception
258
     * @return \PhpOffice\PhpPresentation\Shape\RichText\Paragraph
259
     */
260 6
    public function setRichTextElements($pElements = null)
261
    {
262 6
        if (is_array($pElements)) {
263 5
            $this->richTextElements = $pElements;
264
        } else {
265 1
            throw new \Exception("Invalid \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface[] array passed.");
266
        }
267
268 5
        return $this;
269
    }
270
271
    /**
272
     * Get hash code
273
     *
274
     * @return string Hash code
275
     */
276 19
    public function getHashCode()
277
    {
278 19
        $hashElements = '';
279 19
        foreach ($this->richTextElements as $element) {
280 10
            $hashElements .= $element->getHashCode();
281
        }
282
283 19
        return md5($hashElements . $this->font->getHashCode() . __CLASS__);
284
    }
285
286
    /**
287
     * Get hash index
288
     *
289
     * Note that this index may vary during script execution! Only reliable moment is
290
     * while doing a write of a workbook and when changes are not allowed.
291
     *
292
     * @return string Hash index
293
     */
294 1
    public function getHashIndex()
295
    {
296 1
        return $this->hashIndex;
297
    }
298
299
    /**
300
     * Set hash index
301
     *
302
     * Note that this index may vary during script execution! Only reliable moment is
303
     * while doing a write of a workbook and when changes are not allowed.
304
     *
305
     * @param string $value Hash index
306
     */
307 1
    public function setHashIndex($value)
308
    {
309 1
        $this->hashIndex = $value;
310 1
    }
311
312
    /**
313
     * @return int
314
     */
315 34
    public function getLineSpacing()
316
    {
317 34
        return $this->lineSpacing;
318
    }
319
320
    /**
321
     * @param int $lineSpacing
322
     * @return Paragraph
323
     */
324 2
    public function setLineSpacing($lineSpacing)
325
    {
326 2
        $this->lineSpacing = $lineSpacing;
327 2
        return $this;
328
    }
329
}
330