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 15
cts 15
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 20
    public function __construct(string $title, string $link, string $img = '')
21
    {
22 20
        $this->link = $link;
23 20
        $this->title = $title;
24 20
        $this->img = $img;
25 20
    }
26
27 4
    public function appendTo(RelatedItemsListInterface $relatedItemsList): RelatedItemInterface
28
    {
29 4
        $relatedItemsList->addItem($this);
30 4
        return $this;
31
    }
32
33 8
    public function asXML(): SimpleXMLElement
34
    {
35 8
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><link>'
36 8
            . $this->title . '</link>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
37
38 8
        $xml->addAttribute('url', $this->link);
39
40 8
        if (!empty($this->img)) {
41 8
            $xml->addAttribute('img', $this->img);
42
        }
43
44 8
        return $xml;
45
    }
46
}
47