Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Link
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getSource
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getText
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFontStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getParagraphStyle
100.00% covered (success)
100.00%
1 / 1
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
1<?php
2
3/**
4 * This file is part of PHPWord - A pure PHP library for reading and writing
5 * word processing documents.
6 *
7 * PHPWord is free software distributed under the terms of the GNU Lesser
8 * General Public License version 3 as published by the Free Software Foundation.
9 *
10 * For the full copyright and license information, please read the LICENSE
11 * file that was distributed with this source code. For the full list of
12 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13 *
14 * @see         https://github.com/PHPOffice/PHPWord
15 *
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19namespace PhpOffice\PhpWord\Element;
20
21use PhpOffice\PhpWord\Shared\Text as SharedText;
22use PhpOffice\PhpWord\Style\Font;
23use PhpOffice\PhpWord\Style\Paragraph;
24
25/**
26 * Link element.
27 */
28class Link extends AbstractElement
29{
30    /**
31     * Link source.
32     *
33     * @var string
34     */
35    private $source;
36
37    /**
38     * Link text.
39     *
40     * @var string
41     */
42    private $text;
43
44    /**
45     * Font style.
46     *
47     * @var null|Font|string
48     */
49    private $fontStyle;
50
51    /**
52     * Paragraph style.
53     *
54     * @var null|Paragraph|string
55     */
56    private $paragraphStyle;
57
58    /**
59     * Has media relation flag; true for Link, Image, and Object.
60     *
61     * @var bool
62     */
63    protected $mediaRelation = true;
64
65    /**
66     * Has internal flag - anchor to internal bookmark.
67     *
68     * @var bool
69     */
70    protected $internal = false;
71
72    /**
73     * Create a new Link Element.
74     *
75     * @param string $source
76     * @param string $text
77     * @param mixed $fontStyle
78     * @param mixed $paragraphStyle
79     * @param bool $internal
80     */
81    public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
82    {
83        $this->source = SharedText::toUTF8($source);
84        $this->text = null === $text ? $this->source : SharedText::toUTF8($text);
85        $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
86        $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
87        $this->internal = $internal;
88    }
89
90    /**
91     * Get link source.
92     *
93     * @return string
94     */
95    public function getSource()
96    {
97        return $this->source;
98    }
99
100    /**
101     * Get link text.
102     */
103    public function getText(): string
104    {
105        return $this->text;
106    }
107
108    /**
109     * Get Text style.
110     *
111     * @return null|Font|string
112     */
113    public function getFontStyle()
114    {
115        return $this->fontStyle;
116    }
117
118    /**
119     * Get Paragraph style.
120     *
121     * @return null|Paragraph|string
122     */
123    public function getParagraphStyle()
124    {
125        return $this->paragraphStyle;
126    }
127
128    /**
129     * is internal.
130     *
131     * @return bool
132     */
133    public function isInternal()
134    {
135        return $this->internal;
136    }
137}