Completed
Pull Request — develop (#455)
by
unknown
10:09
created

TextElement::isDirty()   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 0
Metric Value
c 0
b 0
f 0
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
    protected $dirty;
47
48
    /**
49
     * Create a new \PhpOffice\PhpPresentation\Shape\RichText\TextElement instance
50
     *
51
     * @param string $pText Text
52
     */
53 12
    public function __construct($pText = '')
54
    {
55
        // Initialise variables
56 12
        $this->text = $pText;
57 12
    }
58
59
    /**
60
     * Get text
61
     *
62
     * @return string Text
63
     */
64 32
    public function getText()
65
    {
66 32
        return $this->text;
67
    }
68
69
    /**
70
     * Set text
71
     *
72
     * @param                                            $pText string   Text
73
     * @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
74
     */
75 55
    public function setText($pText = '')
76
    {
77 55
        $this->text = $pText;
78
79 55
        return $this;
80
    }
81
82
    /**
83
     * Get font
84
     *
85
     * @return \PhpOffice\PhpPresentation\Style\Font
86
     */
87 1
    public function getFont()
88
    {
89 1
        return null;
90
    }
91
92
    /**
93
     * Has Hyperlink?
94
     *
95
     * @return boolean
96
     */
97 43
    public function hasHyperlink()
98
    {
99 43
        return !is_null($this->hyperlink);
100
    }
101
102
    /**
103
     * Get Hyperlink
104
     *
105
     * @return \PhpOffice\PhpPresentation\Shape\Hyperlink
106
     */
107 8
    public function getHyperlink()
108
    {
109 8
        if (is_null($this->hyperlink)) {
110 8
            $this->hyperlink = new Hyperlink();
111 8
        }
112
113 8
        return $this->hyperlink;
114
    }
115
116
    /**
117
     * Set Hyperlink
118
     *
119
     * @param  \PhpOffice\PhpPresentation\Shape\Hyperlink $pHyperlink
120
     * @throws \Exception
121
     * @return \PhpOffice\PhpPresentation\AbstractShape
122
     */
123 2
    public function setHyperlink(Hyperlink $pHyperlink = null)
124
    {
125 2
        $this->hyperlink = $pHyperlink;
126
127 2
        return $this;
128
    }
129
130
    /**
131
     * Get language
132
     * @return string
133
     */
134 23
    public function getLanguage()
135
    {
136 23
        return $this->language;
137
    }
138
139
    /**
140
     * Set language
141
     * @param string $language
142
     * @return TextElement
143
     */
144 3
    public function setLanguage($language)
145
    {
146 3
        $this->language = $language;
147 3
        return $this;
148
    }
149
150
    public function setDirty($value)
151
    {
152
        $this->dirty = $value;
153
        return $this;
154
    }
155
156 11
    public function isDirty()
157
    {
158 11
        return (int) $this->dirty;
159
    }
160
161
    /**
162
     * Get hash code
163
     *
164
     * @return string Hash code
165
     */
166 3
    public function getHashCode()
167
    {
168 3
        return md5($this->text . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
169
    }
170
}
171