ChannelBuilder::subtitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
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 ChannelBuilder
6
{
7
    const DATE_FORMAT = 'D, d M Y H:i:s O';
8
9
    /** @var FeedBuilder */
10
    private $feedBuilder;
11
12
    /** @var string */
13
    private $title;
14
15
    /** @var string */
16
    private $subtitle;
17
18
    /** @var string */
19
    private $description;
20
21
    /** @var string */
22
    private $lastBuildDate;
23
24
    /** @var string */
25
    private $language;
26
27
    /** @var string */
28
    private $generator;
29
30
    /** @var string */
31
    private $managingEditor;
32
33
    /** @var string */
34
    private $imageUrl;
35
36
    /** @var string */
37
    private $url;
38
39
    /** @var string */
40
    private $feedUrl;
41
42
    /** @var string */
43
    private $author;
44
45
    /** @var string */
46
    private $explicit;
47
48
    /** @var string */
49
    private $type;
50
51
    /** @var string */
52
    private $email;
53
54
    /** @var string */
55
    private $category;
56
57
    /** @var ItemBuilder[] */
58
    private $items = [];
59
60 4
    public function __construct(FeedBuilder $feedBuilder)
61
    {
62 4
        $this->feedBuilder = $feedBuilder;
63 4
    }
64
65 4
    public function title(string $title): ChannelBuilder
66
    {
67 4
        $this->title = $title;
68 4
        return $this;
69
    }
70
71 4
    public function subtitle(string $subtitle): ChannelBuilder
72
    {
73 4
        $this->subtitle = $subtitle;
74 4
        return $this;
75
    }
76
77 4
    public function description(string $description): ChannelBuilder
78
    {
79 4
        $this->description = $description;
80 4
        return $this;
81
    }
82
83 4
    public function lastBuildDate(string $lastBuildDate): ChannelBuilder
84
    {
85 4
        $this->lastBuildDate = $lastBuildDate;
86 4
        return $this;
87
    }
88
89 4
    public function language(string $language): ChannelBuilder
90
    {
91 4
        $this->language = $language;
92 4
        return $this;
93
    }
94
95 4
    public function generator(string $generator): ChannelBuilder
96
    {
97 4
        $this->generator = $generator;
98 4
        return $this;
99
    }
100
101 4
    public function managingEditor(string $managingEditor): ChannelBuilder
102
    {
103 4
        $this->managingEditor = $managingEditor;
104 4
        return $this;
105
    }
106
107 4
    public function imageUrl(string $imageUrl): ChannelBuilder
108
    {
109 4
        $this->imageUrl = $imageUrl;
110 4
        return $this;
111
    }
112
113 4
    public function url(string $url): ChannelBuilder
114
    {
115 4
        $this->url = $url;
116 4
        return $this;
117
    }
118
119 4
    public function feedUrl(string $feedUrl): ChannelBuilder
120
    {
121 4
        $this->feedUrl = $feedUrl;
122 4
        return $this;
123
    }
124
125 4
    public function author(string $author): ChannelBuilder
126
    {
127 4
        $this->author = $author;
128 4
        return $this;
129
    }
130
131 4
    public function explicit(string $explicit): ChannelBuilder
132
    {
133 4
        $this->explicit = $explicit;
134 4
        return $this;
135
    }
136
137 4
    public function type(string $type): ChannelBuilder
138
    {
139 4
        $this->type = $type;
140 4
        return $this;
141
    }
142
143 4
    public function email(string $email): ChannelBuilder
144
    {
145 4
        $this->email = $email;
146 4
        return $this;
147
    }
148
149 4
    public function category(string $category): ChannelBuilder
150
    {
151 4
        $this->category = $category;
152 4
        return $this;
153
    }
154
155 1
    public function addItem(): ItemBuilder
156
    {
157 1
        $itemBuilder = new ItemBuilder($this);
158 1
        $this->items[] = $itemBuilder;
159
160 1
        return $itemBuilder;
161
    }
162
163 4
    public function close(): FeedBuilder
164
    {
165 4
        return $this->feedBuilder;
166
    }
167
168 4
    public function toDOMElement(\DOMDocument $dom): \DOMElement
169
    {
170 4
        $element = $dom->createElement('channel');
171 4
        $element->appendChild($dom->createElement('title', $this->title));
172 4
        $element->appendChild($dom->createElement('link', $this->url));
173 4
        $element->appendChild($dom->createElement('description', $this->description));
174 4
        $element->appendChild($dom->createElement('lastBuildDate', $this->lastBuildDate));
175 4
        $element->appendChild($dom->createElement('language', $this->language));
176 4
        $element->appendChild($dom->createElement('generator', $this->generator));
177 4
        $element->appendChild($dom->createElement('managingEditor', $this->managingEditor));
178 4
        $element->appendChild($dom->createElement('category', htmlentities($this->category)));
179
180 4
        $image = $dom->createElement('image');
181 4
        $image->appendChild($dom->createElement('title', $this->title));
182 4
        $image->appendChild($dom->createElement('url', $this->imageUrl));
183 4
        $image->appendChild($dom->createElement('link', $this->url));
184 4
        $element->appendChild($image);
185
186 4
        $atomLink = $dom->createElement('atom:link');
187 4
        $atomLink->setAttribute('href', $this->feedUrl);
188 4
        $atomLink->setAttribute('rel', 'self');
189 4
        $atomLink->setAttribute('type', 'application/rss+xml');
190 4
        $element->appendChild($atomLink);
191
192 4
        $element->appendChild($dom->createElement('itunes:subtitle', $this->subtitle));
193 4
        $element->appendChild($dom->createElement('itunes:summary', $this->description));
194 4
        $element->appendChild($dom->createElement('itunes:author', $this->author));
195 4
        $element->appendChild($dom->createElement('itunes:explicit', $this->explicit));
196 4
        $element->appendChild($dom->createElement('itunes:type', $this->type));
197
198 4
        $category = $dom->createElement('itunes:category');
199 4
        $category->setAttribute('text', $this->category);
200 4
        $element->appendChild($category);
201
202 4
        $itunesImage = $dom->createElement('itunes:image');
203 4
        $itunesImage->setAttribute('href', $this->imageUrl);
204 4
        $element->appendChild($itunesImage);
205
206
207 4
        $itunesOwner = $dom->createElement('itunes:owner');
208 4
        $itunesOwner->appendChild($dom->createElement('itunes:name', $this->author));
209 4
        $itunesOwner->appendChild($dom->createElement('itunes:email', $this->email));
210 4
        $element->appendChild($itunesOwner);
211
212
213 4
        $element->appendChild($dom->createElement('googleplay:description', $this->description));
214
215 4
        foreach ($this->items as $item) {
216 1
            $element->appendChild($item->toDOMElement($dom));
217
        }
218
219 4
        return $element;
220
    }
221
}
222