Completed
Push — master ( 7b15fd...5c92ba )
by Petro
04:28
created

RelatedItemsList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 30
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A appendTo() 0 5 1
A addItem() 0 5 1
A asXML() 0 12 2
1
<?php
2
3
namespace sokolnikov911\YandexTurboPages;
4
5
/**
6
 * Class RelatedItemsList
7
 * @package sokolnikov911\YandexTurboPages
8
 */
9
class RelatedItemsList implements RelatedItemsListInterface
10
{
11
    /** @var RelatedItemInterface[] */
12
    protected $relatedItems = [];
13
14 6
    public function appendTo(ItemInterface $item)
15
    {
16 6
        $item->addRelatedItemsList($this);
17 6
        return $this;
18
    }
19
20 18
    public function addItem(RelatedItem $relatedItem)
21
    {
22 18
        $this->relatedItems[] = $relatedItem;
23 18
        return $this;
24
    }
25
26 18
    public function asXML()
27
    {
28 18
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><yandex:related xmlns:yandex="http://news.yandex.ru"></yandex:related>', LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL);
29
30 18
        foreach ($this->relatedItems as $item) {
31 6
            $toDom = dom_import_simplexml($xml);
32 6
            $fromDom = dom_import_simplexml($item->asXML());
33 6
            $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
34 9
        }
35
36 18
        return $xml;
37
    }
38
}
39