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