Completed
Pull Request — develop (#194)
by Franck
07:01
created

TextElement::getLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Shape\Hyperlink;
21
22
/**
23
 * Rich text text element
24
 */
25
class TextElement implements TextElementInterface
26
{
27
    /**
28
     * Text
29
     *
30
     * @var string
31
     */
32
    private $text;
33
34
    /**
35
     * @var string
36
     */
37
    protected $language;
38
39
    /**
40
     * Hyperlink
41
     *
42
     * @var \PhpOffice\PhpPresentation\Shape\Hyperlink
43
     */
44
    protected $hyperlink;
45
46
    /**
47
     * Create a new \PhpOffice\PhpPresentation\Shape\RichText\TextElement instance
48
     *
49
     * @param string $pText Text
50
     */
51 12
    public function __construct($pText = '')
52
    {
53
        // Initialise variables
54 12
        $this->text = $pText;
55 12
    }
56
57
    /**
58
     * Get text
59
     *
60
     * @return string Text
61
     */
62 48
    public function getText()
63
    {
64 48
        return $this->text;
65
    }
66
67
    /**
68
     * Set text
69
     *
70
     * @param                                            $pText string   Text
71
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
72
     */
73 54
    public function setText($pText = '')
74
    {
75 54
        $this->text = $pText;
76
77 54
        return $this;
78
    }
79
80
    /**
81
     * Get font
82
     *
83
     * @return \PhpOffice\PhpPresentation\Style\Font
84
     */
85 1
    public function getFont()
86
    {
87 1
        return null;
88
    }
89
90
    /**
91
     * Has Hyperlink?
92
     *
93
     * @return boolean
94
     */
95 40
    public function hasHyperlink()
96
    {
97 40
        return !is_null($this->hyperlink);
98
    }
99
100
    /**
101
     * Get Hyperlink
102
     *
103
     * @return \PhpOffice\PhpPresentation\Shape\Hyperlink
104
     */
105 11
    public function getHyperlink()
106
    {
107 11
        if (is_null($this->hyperlink)) {
108 11
            $this->hyperlink = new Hyperlink();
109
        }
110
111 11
        return $this->hyperlink;
112
    }
113
114
    /**
115
     * Set Hyperlink
116
     *
117
     * @param  \PhpOffice\PhpPresentation\Shape\Hyperlink $pHyperlink
118
     * @throws \Exception
119
     * @return \PhpOffice\PhpPresentation\AbstractShape
120
     */
121 2
    public function setHyperlink(Hyperlink $pHyperlink = null)
122
    {
123 2
        $this->hyperlink = $pHyperlink;
124
125 2
        return $this;
126
    }
127
128
    /**
129
     * Get language
130
     * @return string
131
     */
132 38
    public function getLanguage()
133
    {
134 38
        return $this->language;
135
    }
136
137
    /**
138
     * Set language
139
     * @param string $language
140
     * @return TextElement
141
     */
142 4
    public function setLanguage($language)
143
    {
144 4
        $this->language = $language;
145 4
        return $this;
146
    }
147
148
    /**
149
     * Get hash code
150
     *
151
     * @return string Hash code
152
     */
153 3
    public function getHashCode()
154
    {
155 3
        return md5($this->text . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
156
    }
157
}
158