Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
80.00% |
4 / 5 |
CRAP | |
97.22% |
35 / 36 |
RSSParser | |
0.00% |
0 / 1 |
|
80.00% |
4 / 5 |
11 | |
97.22% |
35 / 36 |
getNodes($content) | |
0.00% |
0 / 1 |
4.01 | |
91.67% |
11 / 12 |
|||
create(DOMElement $node) | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
getPropertiesMapping() | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
setDate(DOMElement $node, Item $item) | |
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
|||
setTags(DOMElement $node, Item $item) | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
<?php | |
/** | |
* This file is part of the FastFeed package. | |
* | |
* (c) Daniel González <daniel@desarrolla2.com> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace FastFeed\Parser; | |
use DOMElement; | |
use DateTime; | |
use FastFeed\Item; | |
use FastFeed\Exception\RuntimeException; | |
/** | |
* RSSParser | |
*/ | |
class RSSParser extends AbstractParser implements ParserInterface | |
{ | |
/** | |
* Retrieve a Items's array | |
* | |
* @param $content | |
* | |
* @return array | |
* @throws \FastFeed\Exception\RuntimeException | |
*/ | |
public function getNodes($content) | |
{ | |
$items = array(); | |
$document = $this->createDocumentFromXML($content); | |
$nodes = $document->getElementsByTagName('item'); | |
if ($nodes->length) { | |
foreach ($nodes as $node) { | |
try { | |
$item = $this->create($node); | |
$items[] = $item; | |
} catch (\Exception $e) { | |
throw new RuntimeException($e->getMessage()); | |
} | |
} | |
} | |
return $items; | |
} | |
/** | |
* @param DOMElement $node | |
* | |
* @return Item | |
*/ | |
public function create(DOMElement $node) | |
{ | |
$item = new Item(); | |
$this->setProperties($node, $item); | |
$this->setDate($node, $item); | |
$this->setTags($node, $item); | |
$this->executeAggregators($node, $item); | |
return $item; | |
} | |
/** | |
* @return array | |
*/ | |
protected function getPropertiesMapping() | |
{ | |
return array( | |
'setId' => 'link', | |
'setName' => 'title', | |
'setIntro' => 'description', | |
'setContent' => 'description', | |
'setSource' => 'link', | |
'setAuthor' => 'author' | |
); | |
} | |
/** | |
* @param DOMElement $node | |
* @param Item $item | |
*/ | |
protected function setDate(DOMElement $node, Item $item) | |
{ | |
$value = $this->getNodeValueByTagName($node, 'pubDate'); | |
if ($value) { | |
if (strtotime($value)) { | |
$item->setDate(new DateTime($value)); | |
} | |
} | |
} | |
/** | |
* @param DOMElement $node | |
* @param Item $item | |
*/ | |
protected function setTags(DOMElement $node, Item $item) | |
{ | |
$tags = $this->getNodeValuesByTagName($node, 'category'); | |
foreach ($tags as $tag) { | |
$item->addTag($tag); | |
} | |
} | |
} |