RelatedItem   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 38
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A appendTo() 0 5 1
A asXML() 0 13 2
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