RelatedItem::appendTo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace sokolnikov911\YandexTurboPages;
4
5
/**
6
 * Class RelatedItem
7
 * @package sokolnikov911\YandexTurboPages
8
 */
9
class RelatedItem implements RelatedItemInterface
10
{
11
    /** @var string */
12
    protected $title;
13
14
    /** @var string */
15
    protected $link;
16
17
    /** @var string */
18
    protected $img;
19
20 35
    public function __construct($title, $link, $img = '')
21
    {
22 35
        $this->link = $link;
23 35
        $this->title = $title;
24 35
        $this->img = $img;
25 35
    }
26
27 7
    public function appendTo(RelatedItemsListInterface $relatedItemsList)
28
    {
29 7
        $relatedItemsList->addItem($this);
30 7
        return $this;
31
    }
32
33 14
    public function asXML()
34
    {
35 14
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><link>'
36 14
            . $this->title . '</link>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
37
38 14
        $xml->addAttribute('url', $this->link);
39
40 14
        if (!empty($this->img)) {
41 14
            $xml->addAttribute('img', $this->img);
42 6
        }
43
44 14
        return $xml;
45
    }
46
}
47