Completed
Pull Request — develop (#180)
by Szymon
06:21
created

TextElement::getHyperlink()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
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
    private $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 46
    public function getText()
63
    {
64 46
        return $this->text;
65
    }
66
67
    /**
68
     * Set text
69
     *
70
     * @param                                            $pText string   Text
71
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
72
     */
73 52
    public function setText($pText = '')
74
    {
75 52
        $this->text = $pText;
76
77 52
        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 38
    public function hasHyperlink()
96
    {
97 38
        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 hash code
130
     *
131
     * @return string Hash code
132
     */
133 3
    public function getHashCode()
134
    {
135 3
        return md5($this->text . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
136
    }
137
138
    /**
139
     * Set language
140
     *
141
     * @param $lang
142
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
143
     */
144 2
    public function setLanguage($lang)
145
    {
146 2
        $this->language = $lang;
147
148 2
        return $this;
149
    }
150
151
    /**
152
     * Get language
153
     *
154
     * @return string Language
155
     */
156 27
    public function getLanguage()
157
    {
158 27
        return $this->language;
159
    }
160
}
161