ItemBuilder::addCategory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
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 PODEntender\Domain\Model\Feed;
4
5
class ItemBuilder
6
{
7
    const DATE_FORMAT = 'D, d M Y H:i:s O';
8
9
    private $channelBuilder;
10
11
    private $guid;
12
13
    private $title;
14
15
    private $subtitle;
16
17
    private $link;
18
19
    private $image;
20
21
    private $comments;
22
23
    private $pubDate;
24
25
    private $description;
26
27
    private $author;
28
29
    private $explicit;
30
31
    private $duration;
32
33
    private $categories = [];
34
35
    private $enclosures = [];
36
37 1
    public function __construct(ChannelBuilder $channelBuilder)
38
    {
39 1
        $this->channelBuilder = $channelBuilder;
40 1
    }
41
42 1
    public function guid(string $guid): self
43
    {
44 1
        $this->guid = $guid;
45 1
        return $this;
46
    }
47
48 1
    public function title(string $title): self
49
    {
50 1
        $this->title = $title;
51 1
        return $this;
52
    }
53
54 1
    public function subtitle(string $subtitle): self
55
    {
56 1
        $this->subtitle = $subtitle;
57 1
        return $this;
58
    }
59
60 1
    public function link(string $link): self
61
    {
62 1
        $this->link = $link;
63 1
        return $this;
64
    }
65
66 1
    public function image(string $image): self
67
    {
68 1
        $this->image = $image;
69 1
        return $this;
70
    }
71
72 1
    public function comments(string $comments): self
73
    {
74 1
        $this->comments = $comments;
75 1
        return $this;
76
    }
77
78 1
    public function pubDate(string $pubDate): self
79
    {
80 1
        $this->pubDate = $pubDate;
81 1
        return $this;
82
    }
83
84 1
    public function description(string $description): self
85
    {
86 1
        $this->description = $description;
87 1
        return $this;
88
    }
89
90 1
    public function author(string $author): self
91
    {
92 1
        $this->author = $author;
93 1
        return $this;
94
    }
95
96 1
    public function explicit(string $explicit): self
97
    {
98 1
        $this->explicit = $explicit;
99 1
        return $this;
100
    }
101
102 1
    public function duration(string $duration): self
103
    {
104 1
        $this->duration = $duration;
105 1
        return $this;
106
    }
107
108 1
    public function addCategory(string $category): self {
109 1
        $this->categories[] = $category;
110 1
        return $this;
111
    }
112
113 1
    public function addEnclosure(): EnclosureBuilder
114
    {
115 1
        $enclosureBuilder = new EnclosureBuilder($this);
116 1
        $this->enclosures[] = $enclosureBuilder;
117
118 1
        return $enclosureBuilder;
119
    }
120
121 1
    public function toDOMElement(\DOMDocument $dom): \DOMElement
122
    {
123 1
        $element = $dom->createElement('item');
124 1
        $element->appendChild($dom->createElement('title', $this->title));
125 1
        $element->appendChild($dom->createElement('description', $this->description));
126 1
        $element->appendChild($dom->createElement('link', $this->link));
127 1
        $element->appendChild($dom->createElement('comments', $this->comments));
128 1
        $element->appendChild($dom->createElement('pubDate', $this->pubDate));
129 1
        $guid = $dom->createElement('guid', $this->guid);
130 1
        $guid->setAttribute('isPermaLink', 'false');
131 1
        $element->appendChild($guid);
132
133 1
        foreach ($this->categories as $category) {
134 1
            $categoryElement = $dom->createElement('category');
135 1
            $categoryElement->appendChild(
136 1
                $dom->createCDATASection($category)
137
            );
138 1
            $element->appendChild($categoryElement);
139
        }
140
141 1
        foreach ($this->enclosures as $enclosure) {
142 1
            $element->appendChild($enclosure->toDOMElement($dom));
143
        }
144
145 1
        $element->appendChild($dom->createElement('itunes:subtitle', $this->subtitle));
146 1
        $element->appendChild($dom->createElement('itunes:summary', $this->description));
147 1
        $element->appendChild($dom->createElement('itunes:author', $this->author));
148 1
        $element->appendChild($dom->createElement('itunes:explicit', $this->explicit));
149 1
        $element->appendChild($dom->createElement('itunes:duration', $this->duration));
150
151 1
        if ($this->image) {
152 1
            $coverImage = $dom->createElement('itunes:image');
153 1
            $coverImage->setAttribute('href', $this->image);
154
155 1
            $element->appendChild($coverImage);
156
        }
157
158 1
        return $element;
159
    }
160
}
161