Skip to content

Commit 047371e

Browse files
committed
TASK: Code cleanup and fixes
- add strict typing (and thus raise the PHP dependency to 7.0 - add dependency on ext-dom and ext-simplexml - remove an unused variable - make fluid interface available (as documented) - fix documentation (see PR robertlemke#2)
1 parent 78ae6f9 commit 047371e

6 files changed

Lines changed: 88 additions & 72 deletions

File tree

Classes/Channel.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Rss;
35

46
/*
@@ -16,7 +18,6 @@
1618
*/
1719
class Channel
1820
{
19-
2021
/**
2122
* @var string
2223
*/
@@ -37,11 +38,6 @@ class Channel
3738
*/
3839
protected $websiteUri;
3940

40-
/**
41-
* @var string
42-
*/
43-
protected $imageUri;
44-
4541
/**
4642
* @var string
4743
*/
@@ -50,68 +46,75 @@ class Channel
5046
/**
5147
* @var array
5248
*/
53-
protected $items = array();
49+
protected $items = [];
5450

5551
/**
5652
* @param string $description
57-
* @return void
53+
* @return Channel
5854
*/
59-
public function setDescription($description)
55+
public function setDescription(string $description): Channel
6056
{
6157
$this->description = $description;
58+
return $this;
6259
}
6360

6461
/**
6562
* @param string $title
66-
* @return void
63+
* @return Channel
6764
*/
68-
public function setTitle($title)
65+
public function setTitle(string $title): Channel
6966
{
7067
$this->title = $title;
68+
return $this;
7169
}
7270

7371
/**
7472
* @param string $feedUri
75-
* @return void
73+
* @return Channel
7674
*/
77-
public function setFeedUri($feedUri)
75+
public function setFeedUri(string $feedUri): Channel
7876
{
7977
$this->feedUri = $feedUri;
78+
return $this;
8079
}
8180

8281
/**
8382
* @param string $websiteUri
84-
* @return void
83+
* @return Channel
8584
*/
86-
public function setWebsiteUri($websiteUri)
85+
public function setWebsiteUri(string $websiteUri): Channel
8786
{
8887
$this->websiteUri = $websiteUri;
88+
return $this;
8989
}
9090

9191
/**
9292
* @param string $language
93-
* @return void
93+
* @return Channel
9494
*/
95-
public function setLanguage($language)
95+
public function setLanguage(string $language): Channel
9696
{
9797
$this->language = $language;
98+
return $this;
9899
}
99100

100101
/**
101102
* Adds a new item to this channel
102103
*
103104
* @param Item $item An item
104-
* @return void
105+
* @return Channel
105106
*/
106-
public function addItem(Item $item)
107+
public function addItem(Item $item): Channel
107108
{
108109
$this->items[] = $item;
110+
return $this;
109111
}
110112

111113
/**
112114
* @return \SimpleXMLElement
115+
* @throws \Exception
113116
*/
114-
public function asXML()
117+
public function asXML(): \SimpleXMLElement
115118
{
116119
$date = new \DateTime('now', new \DateTimeZone('GMT'));
117120
$nowFormatted = $date->format('D, d M Y H:i:s') . ' GMT';
@@ -148,4 +151,4 @@ public function asXML()
148151

149152
return $xml;
150153
}
151-
}
154+
}

Classes/Feed.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Rss;
35

46
/*
@@ -16,19 +18,18 @@
1618
*/
1719
class Feed
1820
{
19-
2021
/**
2122
* @var array<Channel>
2223
*/
23-
protected $channels = array();
24+
protected $channels = [];
2425

2526
/**
2627
* Adds a new channel to this feed
2728
*
2829
* @param Channel $channel
2930
* @return Feed
3031
*/
31-
public function addChannel(Channel $channel)
32+
public function addChannel(Channel $channel): Feed
3233
{
3334
$this->channels[] = $channel;
3435

@@ -40,7 +41,7 @@ public function addChannel(Channel $channel)
4041
*
4142
* @return string
4243
*/
43-
public function render()
44+
public function render(): string
4445
{
4546
$xml = new SimpleXMLElement(
4647
'<?xml version="1.0" encoding="UTF-8" ?>
@@ -67,4 +68,4 @@ public function render()
6768

6869
return $dom->saveXML();
6970
}
70-
}
71+
}

Classes/Item.php

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace RobertLemke\Rss;
35

46
/*
@@ -16,7 +18,6 @@
1618
*/
1719
class Item
1820
{
19-
2021
/**
2122
* @var string
2223
*/
@@ -60,167 +61,176 @@ class Item
6061
/**
6162
* @var array<string>
6263
*/
63-
protected $categories = array();
64+
protected $categories = [];
6465

6566
/**
6667
* Can be an array of either strings or arrays (with indexes "category" and "domain").
6768
*
6869
* @param array $categories
69-
* @return void
70+
* @return Item
7071
*/
71-
public function setCategories($categories)
72+
public function setCategories(array $categories): Item
7273
{
7374
$this->categories = $categories;
75+
return $this;
7476
}
7577

7678
/**
7779
* @return array
7880
*/
79-
public function getCategories()
81+
public function getCategories(): array
8082
{
8183
return $this->categories;
8284
}
8385

8486
/**
8587
* @param string $commentsLink
86-
* @return void
88+
* @return Item
8789
*/
88-
public function setCommentsLink($commentsLink)
90+
public function setCommentsLink(string $commentsLink): Item
8991
{
9092
$this->commentsLink = $commentsLink;
93+
return $this;
9194
}
9295

9396
/**
9497
* @return string
9598
*/
96-
public function getCommentsLink()
99+
public function getCommentsLink(): string
97100
{
98101
return $this->commentsLink;
99102
}
100103

101104
/**
102105
* @param string $content
103-
* @return void
106+
* @return Item
104107
*/
105-
public function setContent($content)
108+
public function setContent(string $content): Item
106109
{
107110
$this->content = $content;
111+
return $this;
108112
}
109113

110114
/**
111115
* @return string
112116
*/
113-
public function getContent()
117+
public function getContent(): string
114118
{
115119
return $this->content;
116120
}
117121

118122
/**
119123
* @param string $creator
120-
* @return void
124+
* @return Item
121125
*/
122-
public function setCreator($creator)
126+
public function setCreator(string $creator): Item
123127
{
124128
$this->creator = $creator;
129+
return $this;
125130
}
126131

127132
/**
128133
* @return string
129134
*/
130-
public function getCreator()
135+
public function getCreator(): string
131136
{
132137
return $this->creator;
133138
}
134139

135140
/**
136141
* @param string $description
137-
* @return void
142+
* @return Item
138143
*/
139-
public function setDescription($description)
144+
public function setDescription(string $description): Item
140145
{
141146
$this->description = $description;
147+
return $this;
142148
}
143149

144150
/**
145151
* @return string
146152
*/
147-
public function getDescription()
153+
public function getDescription(): string
148154
{
149155
return $this->description;
150156
}
151157

152158
/**
153159
* @param string $guid
154-
* @return void
160+
* @return Item
155161
*/
156-
public function setGuid($guid)
162+
public function setGuid(string $guid): Item
157163
{
158164
$this->guid = $guid;
165+
return $this;
159166
}
160167

161168
/**
162169
* @return string
163170
*/
164-
public function getGuid()
171+
public function getGuid(): string
165172
{
166173
return $this->guid;
167174
}
168175

169176
/**
170177
* @param string $itemLink
171-
* @return void
178+
* @return Item
172179
*/
173-
public function setItemLink($itemLink)
180+
public function setItemLink(string $itemLink): Item
174181
{
175182
$this->itemLink = $itemLink;
183+
return $this;
176184
}
177185

178186
/**
179187
* @return string
180188
*/
181-
public function getItemLink()
189+
public function getItemLink(): string
182190
{
183191
return $this->itemLink;
184192
}
185193

186194
/**
187195
* @param \DateTime $publicationDate
188-
* @return void
196+
* @return Item
189197
*/
190-
public function setPublicationDate(\DateTime $publicationDate = null)
198+
public function setPublicationDate(\DateTime $publicationDate = null): Item
191199
{
192200
$this->publicationDate = $publicationDate;
201+
return $this;
193202
}
194203

195204
/**
196205
* @return \DateTime
197206
*/
198-
public function getPublicationDate()
207+
public function getPublicationDate(): \DateTime
199208
{
200209
return $this->publicationDate;
201210
}
202211

203212
/**
204213
* @param string $title
205-
* @return void
214+
* @return Item
206215
*/
207-
public function setTitle($title)
216+
public function setTitle(string $title): Item
208217
{
209218
$this->title = $title;
219+
return $this;
210220
}
211221

212222
/**
213223
* @return string
214224
*/
215-
public function getTitle()
225+
public function getTitle(): string
216226
{
217227
return $this->title;
218228
}
219229

220230
/**
221231
* @return \SimpleXMLElement
222232
*/
223-
public function asXml()
233+
public function asXml(): \SimpleXMLElement
224234
{
225235
$xml = new SimpleXMLElement(
226236
'<?xml version="1.0" encoding="UTF-8" ?>
@@ -267,5 +277,4 @@ public function asXml()
267277

268278
return $xml;
269279
}
270-
271-
}
280+
}

0 commit comments

Comments
 (0)