Skip to content

Commit

Permalink
Merge pull request #7 from kdambekalns/task/code-cleanup
Browse files Browse the repository at this point in the history
TASK: Code cleanup and fixes
  • Loading branch information
kdambekalns authored Sep 25, 2019
2 parents 78ae6f9 + 047371e commit e41b940
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 72 deletions.
45 changes: 24 additions & 21 deletions Classes/Channel.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace RobertLemke\Rss;

/*
Expand All @@ -16,7 +18,6 @@
*/
class Channel
{

/**
* @var string
*/
Expand All @@ -37,11 +38,6 @@ class Channel
*/
protected $websiteUri;

/**
* @var string
*/
protected $imageUri;

/**
* @var string
*/
Expand All @@ -50,68 +46,75 @@ class Channel
/**
* @var array
*/
protected $items = array();
protected $items = [];

/**
* @param string $description
* @return void
* @return Channel
*/
public function setDescription($description)
public function setDescription(string $description): Channel
{
$this->description = $description;
return $this;
}

/**
* @param string $title
* @return void
* @return Channel
*/
public function setTitle($title)
public function setTitle(string $title): Channel
{
$this->title = $title;
return $this;
}

/**
* @param string $feedUri
* @return void
* @return Channel
*/
public function setFeedUri($feedUri)
public function setFeedUri(string $feedUri): Channel
{
$this->feedUri = $feedUri;
return $this;
}

/**
* @param string $websiteUri
* @return void
* @return Channel
*/
public function setWebsiteUri($websiteUri)
public function setWebsiteUri(string $websiteUri): Channel
{
$this->websiteUri = $websiteUri;
return $this;
}

/**
* @param string $language
* @return void
* @return Channel
*/
public function setLanguage($language)
public function setLanguage(string $language): Channel
{
$this->language = $language;
return $this;
}

/**
* Adds a new item to this channel
*
* @param Item $item An item
* @return void
* @return Channel
*/
public function addItem(Item $item)
public function addItem(Item $item): Channel
{
$this->items[] = $item;
return $this;
}

/**
* @return \SimpleXMLElement
* @throws \Exception
*/
public function asXML()
public function asXML(): \SimpleXMLElement
{
$date = new \DateTime('now', new \DateTimeZone('GMT'));
$nowFormatted = $date->format('D, d M Y H:i:s') . ' GMT';
Expand Down Expand Up @@ -148,4 +151,4 @@ public function asXML()

return $xml;
}
}
}
11 changes: 6 additions & 5 deletions Classes/Feed.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace RobertLemke\Rss;

/*
Expand All @@ -16,19 +18,18 @@
*/
class Feed
{

/**
* @var array<Channel>
*/
protected $channels = array();
protected $channels = [];

/**
* Adds a new channel to this feed
*
* @param Channel $channel
* @return Feed
*/
public function addChannel(Channel $channel)
public function addChannel(Channel $channel): Feed
{
$this->channels[] = $channel;

Expand All @@ -40,7 +41,7 @@ public function addChannel(Channel $channel)
*
* @return string
*/
public function render()
public function render(): string
{
$xml = new SimpleXMLElement(
'<?xml version="1.0" encoding="UTF-8" ?>
Expand All @@ -67,4 +68,4 @@ public function render()

return $dom->saveXML();
}
}
}
73 changes: 41 additions & 32 deletions Classes/Item.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace RobertLemke\Rss;

/*
Expand All @@ -16,7 +18,6 @@
*/
class Item
{

/**
* @var string
*/
Expand Down Expand Up @@ -60,167 +61,176 @@ class Item
/**
* @var array<string>
*/
protected $categories = array();
protected $categories = [];

/**
* Can be an array of either strings or arrays (with indexes "category" and "domain").
*
* @param array $categories
* @return void
* @return Item
*/
public function setCategories($categories)
public function setCategories(array $categories): Item
{
$this->categories = $categories;
return $this;
}

/**
* @return array
*/
public function getCategories()
public function getCategories(): array
{
return $this->categories;
}

/**
* @param string $commentsLink
* @return void
* @return Item
*/
public function setCommentsLink($commentsLink)
public function setCommentsLink(string $commentsLink): Item
{
$this->commentsLink = $commentsLink;
return $this;
}

/**
* @return string
*/
public function getCommentsLink()
public function getCommentsLink(): string
{
return $this->commentsLink;
}

/**
* @param string $content
* @return void
* @return Item
*/
public function setContent($content)
public function setContent(string $content): Item
{
$this->content = $content;
return $this;
}

/**
* @return string
*/
public function getContent()
public function getContent(): string
{
return $this->content;
}

/**
* @param string $creator
* @return void
* @return Item
*/
public function setCreator($creator)
public function setCreator(string $creator): Item
{
$this->creator = $creator;
return $this;
}

/**
* @return string
*/
public function getCreator()
public function getCreator(): string
{
return $this->creator;
}

/**
* @param string $description
* @return void
* @return Item
*/
public function setDescription($description)
public function setDescription(string $description): Item
{
$this->description = $description;
return $this;
}

/**
* @return string
*/
public function getDescription()
public function getDescription(): string
{
return $this->description;
}

/**
* @param string $guid
* @return void
* @return Item
*/
public function setGuid($guid)
public function setGuid(string $guid): Item
{
$this->guid = $guid;
return $this;
}

/**
* @return string
*/
public function getGuid()
public function getGuid(): string
{
return $this->guid;
}

/**
* @param string $itemLink
* @return void
* @return Item
*/
public function setItemLink($itemLink)
public function setItemLink(string $itemLink): Item
{
$this->itemLink = $itemLink;
return $this;
}

/**
* @return string
*/
public function getItemLink()
public function getItemLink(): string
{
return $this->itemLink;
}

/**
* @param \DateTime $publicationDate
* @return void
* @return Item
*/
public function setPublicationDate(\DateTime $publicationDate = null)
public function setPublicationDate(\DateTime $publicationDate = null): Item
{
$this->publicationDate = $publicationDate;
return $this;
}

/**
* @return \DateTime
*/
public function getPublicationDate()
public function getPublicationDate(): \DateTime
{
return $this->publicationDate;
}

/**
* @param string $title
* @return void
* @return Item
*/
public function setTitle($title)
public function setTitle(string $title): Item
{
$this->title = $title;
return $this;
}

/**
* @return string
*/
public function getTitle()
public function getTitle(): string
{
return $this->title;
}

/**
* @return \SimpleXMLElement
*/
public function asXml()
public function asXml(): \SimpleXMLElement
{
$xml = new SimpleXMLElement(
'<?xml version="1.0" encoding="UTF-8" ?>
Expand Down Expand Up @@ -267,5 +277,4 @@ public function asXml()

return $xml;
}

}
}
Loading

0 comments on commit e41b940

Please sign in to comment.