Completed
Pull Request — develop (#180)
by Szymon
09:40
created

TextElement   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.46%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 12
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 136
ccs 23
cts 26
cp 0.8846
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getText() 0 4 1
A setText() 0 6 1
A getFont() 0 4 1
A hasHyperlink() 0 4 1
A getHyperlink() 0 8 2
A setHyperlink() 0 6 1
A getHashCode() 0 4 2
A setLanguage() 0 6 1
A getLanguage() 0 4 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
    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 11
    public function __construct($pText = '')
52
    {
53
        // Initialise variables
54 11
        $this->text = $pText;
55 11
    }
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 51
    public function setText($pText = '')
74
    {
75 51
        $this->text = $pText;
76
77 51
        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
    public function setLanguage($lang)
145
    {
146
        $this->language = $lang;
147
148
        return $this;
149
    }
150
151
    /**
152
     * Get language
153
     *
154
     * @return string Language
155
     */
156 25
    public function getLanguage()
157
    {
158 25
        return $this->language;
159
    }
160
}
161