Link::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Thepixeldeveloper\Sitemap\Subelements;
4
5
use XMLWriter;
6
use Thepixeldeveloper\Sitemap\OutputInterface;
7
use Thepixeldeveloper\Sitemap\AppendAttributeInterface;
8
9
/**
10
 * Class Link
11
 *
12
 * @package Thepixeldeveloper\Sitemap\Subelements
13
 */
14
class Link implements OutputInterface, AppendAttributeInterface
15
{
16
    /**
17
     * Language code for the page.
18
     *
19
     * @var string
20
     */
21
    protected $hrefLang;
22
23
    /**
24
     * Location of the translated page.
25
     *
26
     * @var string
27
     */
28
    protected $href;
29
30
    /**
31
     * Link constructor.
32
     *
33
     * @param string $hrefLang
34
     * @param string $href
35
     */
36
    public function __construct($hrefLang, $href)
37
    {
38
        $this->hrefLang = $hrefLang;
39
        $this->href = $href;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function generateXML(XMLWriter $XMLWriter)
46
    {
47
        $XMLWriter->startElement('xhtml:link');
48
        $XMLWriter->writeAttribute('rel', 'alternate');
49
        $XMLWriter->writeAttribute('hreflang', $this->hrefLang);
50
        $XMLWriter->writeAttribute('href', $this->href);
51
        $XMLWriter->endElement();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function appendAttributeToCollectionXML(XMLWriter $XMLWriter)
58
    {
59
        $XMLWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
60
    }
61
62
    /**
63
     * Location of the translated page.
64
     *
65
     * @return string
66
     */
67
    public function getHref()
68
    {
69
        return $this->href;
70
    }
71
72
    /**
73
     * Language code for the page.
74
     * 
75
     * @return string
76
     */
77
    public function getHrefLang()
78
    {
79
        return $this->hrefLang;
80
    }
81
}
82