Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
13 / 13
CRAP
100.00% covered (success)
100.00%
21 / 21
Hyperlink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
13 / 13
13
100.00% covered (success)
100.00%
21 / 21
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getUrl
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setUrl
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getTooltip
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setTooltip
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getSlideNumber
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setSlideNumber
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 isInternal
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getHashCode
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setHashIndex
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 isTextColorUsed
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setIsTextColorUsed
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 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 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @copyright   2009-2015 PHPPresentation contributors
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpPresentation\Shape;
22
23/**
24 * Hyperlink element.
25 */
26class Hyperlink
27{
28    /**
29     * URL to link the shape to.
30     *
31     * @var string
32     */
33    private $url;
34
35    /**
36     * Tooltip to display on the hyperlink.
37     *
38     * @var string
39     */
40    private $tooltip;
41
42    /**
43     * Slide number to link to.
44     *
45     * @var int
46     */
47    private $slideNumber = null;
48
49    /**
50     * Slide relation ID (should not be used by user code!).
51     *
52     * @var string
53     */
54    public $relationId = null;
55
56    /**
57     * Hash index.
58     *
59     * @var int
60     */
61    private $hashIndex;
62
63    /**
64     * If true, uses the text color, instead of theme color
65     *
66     * @var bool
67     */
68    private $isTextColorUsed = false;
69
70    /**
71     * Create a new \PhpOffice\PhpPresentation\Shape\Hyperlink.
72     *
73     * @param string $pUrl Url to link the shape to
74     * @param string $pTooltip Tooltip to display on the hyperlink
75     */
76    public function __construct(string $pUrl = '', string $pTooltip = '')
77    {
78        $this->setUrl($pUrl);
79        $this->setTooltip($pTooltip);
80    }
81
82    /**
83     * Get URL.
84     *
85     * @return string
86     */
87    public function getUrl(): string
88    {
89        return $this->url;
90    }
91
92    /**
93     * Set URL.
94     *
95     * @param string $value
96     *
97     * @return self
98     */
99    public function setUrl(string $value = ''): self
100    {
101        $this->url = $value;
102
103        return $this;
104    }
105
106    /**
107     * Get tooltip.
108     *
109     * @return string
110     */
111    public function getTooltip(): string
112    {
113        return $this->tooltip;
114    }
115
116    /**
117     * Set tooltip.
118     *
119     * @param string $value
120     *
121     * @return self
122     */
123    public function setTooltip(string $value = ''): self
124    {
125        $this->tooltip = $value;
126
127        return $this;
128    }
129
130    /**
131     * Get slide number.
132     *
133     * @return int
134     */
135    public function getSlideNumber(): int
136    {
137        return $this->slideNumber;
138    }
139
140    /**
141     * Set slide number.
142     *
143     * @param int $value
144     *
145     * @return self
146     */
147    public function setSlideNumber(int $value = 1): self
148    {
149        $this->url = 'ppaction://hlinksldjump';
150        $this->slideNumber = $value;
151
152        return $this;
153    }
154
155    /**
156     * Is this hyperlink internal? (to another slide).
157     *
158     * @return bool
159     */
160    public function isInternal(): bool
161    {
162        return false !== strpos($this->url, 'ppaction://');
163    }
164
165    /**
166     * Get hash code.
167     *
168     * @return string Hash code
169     */
170    public function getHashCode(): string
171    {
172        return md5($this->url . $this->tooltip . __CLASS__);
173    }
174
175    /**
176     * Get hash index.
177     *
178     * Note that this index may vary during script execution! Only reliable moment is
179     * while doing a write of a workbook and when changes are not allowed.
180     *
181     * @return int|null Hash index
182     */
183    public function getHashIndex(): ?int
184    {
185        return $this->hashIndex;
186    }
187
188    /**
189     * Set hash index.
190     *
191     * Note that this index may vary during script execution! Only reliable moment is
192     * while doing a write of a workbook and when changes are not allowed.
193     *
194     * @param int $value Hash index
195     *
196     * @return $this
197     */
198    public function setHashIndex(int $value)
199    {
200        $this->hashIndex = $value;
201
202        return $this;
203    }
204
205    /**
206     * Get whether or not to use text color for a hyperlink, instead of theme color.
207     *
208     * @see https://docs.microsoft.com/en-us/openspecs/office_standards/ms-odrawxml/014fbc20-3705-4812-b8cd-93f5af05b504
209     *
210     * @return bool whether or not to use text color for a hyperlink, instead of theme color
211     */
212    public function isTextColorUsed(): bool
213    {
214        return $this->isTextColorUsed;
215    }
216
217    /**
218     * Set whether or not to use text color for a hyperlink, instead of theme color.
219     *
220     * @see https://docs.microsoft.com/en-us/openspecs/office_standards/ms-odrawxml/014fbc20-3705-4812-b8cd-93f5af05b504
221     *
222     * @param bool $isTextColorUsed
223     *
224     * @return self
225     */
226    public function setIsTextColorUsed(bool $isTextColorUsed): self
227    {
228        $this->isTextColorUsed = $isTextColorUsed;
229
230        return $this;
231    }
232}