From cf146523bed450181ec8656ecff4be4334e8dcfe Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 29 Aug 2016 19:47:21 +0200 Subject: [PATCH] [formats] Rename variable 'data' to 'item' This makes the intend of the variable more clear and is now coherent with all Bridges --- formats/AtomFormat.php | 12 ++++++------ formats/HtmlFormat.php | 12 ++++++------ formats/JsonFormat.php | 4 ++-- formats/MrssFormat.php | 12 ++++++------ formats/PlaintextFormat.php | 4 ++-- lib/Format.php | 11 +++++------ 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index e1b88c99..238dc884 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -19,12 +19,12 @@ class AtomFormat extends FormatAbstract{ $uri = $this->xml_encode($uri); $entries = ''; - foreach($this->getItems() as $data){ - $entryAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; - $entryTitle = isset($data['title']) ? $this->xml_encode($data['title']) : ''; - $entryUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; - $entryTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $data['timestamp'])) : ''; - $entryContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; + foreach($this->getItems() as $item){ + $entryAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : ''; + $entryTitle = isset($item['title']) ? $this->xml_encode($item['title']) : ''; + $entryUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : ''; + $entryTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_ATOM, $item['timestamp'])) : ''; + $entryContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : ''; $entries .= << diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php index 4a8f9359..d7c927b0 100644 --- a/formats/HtmlFormat.php +++ b/formats/HtmlFormat.php @@ -9,12 +9,12 @@ class HtmlFormat extends FormatAbstract{ $mrssquery = str_replace('format=Html', 'format=Mrss', htmlentities($_SERVER['QUERY_STRING'])); $entries = ''; - foreach($this->getItems() as $data){ - $entryAuthor = isset($data['author']) ? '

by: ' . $data['author'] . '

' : ''; - $entryTitle = isset($data['title']) ? $this->sanitizeHtml(strip_tags($data['title'])) : ''; - $entryUri = isset($data['uri']) ? $data['uri'] : $uri; - $entryTimestamp = isset($data['timestamp']) ? '' : ''; - $entryContent = isset($data['content']) ? '
' . $this->sanitizeHtml($data['content']). '
' : ''; + foreach($this->getItems() as $item){ + $entryAuthor = isset($item['author']) ? '

by: ' . $item['author'] . '

' : ''; + $entryTitle = isset($item['title']) ? $this->sanitizeHtml(strip_tags($item['title'])) : ''; + $entryUri = isset($item['uri']) ? $item['uri'] : $uri; + $entryTimestamp = isset($item['timestamp']) ? '' : ''; + $entryContent = isset($item['content']) ? '
' . $this->sanitizeHtml($item['content']). '
' : ''; $entries .= << diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php index 261f2250..ce259531 100644 --- a/formats/JsonFormat.php +++ b/formats/JsonFormat.php @@ -7,9 +7,9 @@ class JsonFormat extends FormatAbstract{ public function stringify(){ // FIXME : sometime content can be null, transform to empty string - $datas = $this->getItems(); + $items = $this->getItems(); - return json_encode($datas, JSON_PRETTY_PRINT); + return json_encode($items, JSON_PRETTY_PRINT); } public function display(){ diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 0f707548..d0a74177 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -17,12 +17,12 @@ class MrssFormat extends FormatAbstract{ $uri = $this->xml_encode(!empty($extraInfos['uri']) ? $extraInfos['uri'] : 'https://github.com/sebsauvage/rss-bridge'); $items = ''; - foreach($this->getItems() as $data){ - $itemAuthor = isset($data['author']) ? $this->xml_encode($data['author']) : ''; - $itemTitle = strip_tags(isset($data['title']) ? $this->xml_encode($data['title']) : ''); - $itemUri = isset($data['uri']) ? $this->xml_encode($data['uri']) : ''; - $itemTimestamp = isset($data['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $data['timestamp'])) : ''; - $itemContent = isset($data['content']) ? $this->xml_encode($this->sanitizeHtml($data['content'])) : ''; + foreach($this->getItems() as $item){ + $itemAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : ''; + $itemTitle = strip_tags(isset($item['title']) ? $this->xml_encode($item['title']) : ''); + $itemUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : ''; + $itemTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $item['timestamp'])) : ''; + $itemContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : ''; $items .= << diff --git a/formats/PlaintextFormat.php b/formats/PlaintextFormat.php index 059db4c5..e2cf0b94 100644 --- a/formats/PlaintextFormat.php +++ b/formats/PlaintextFormat.php @@ -6,8 +6,8 @@ class PlaintextFormat extends FormatAbstract{ public function stringify(){ - $datas = $this->getItems(); - return print_r($datas, true); + $items = $this->getItems(); + return print_r($items, true); } public function display(){ diff --git a/lib/Format.php b/lib/Format.php index d01a3cd1..142b4c87 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -16,7 +16,7 @@ abstract class FormatAbstract implements FormatInterface{ protected $contentType, $charset, - $datas, + $items, $extraInfos ; @@ -48,17 +48,16 @@ abstract class FormatAbstract implements FormatInterface{ return $this; } - public function setItems(array $datas){ - $this->datas = $datas; + public function setItems(array $items){ + $this->items = $items; return $this; } public function getItems(){ - if( !is_array($this->datas) ){ + if(!is_array($this->items)) throw new \LogicException('Feed the ' . get_class($this) . ' with "setItems" method before !'); - } - return $this->datas; + return $this->items; } /**