Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
17 / 17 |
AbstractParser | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
17 / 17 |
popAggregator() | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
pushAggregator(AggregatorInterface $aggregator) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
executeAggregators(DOMElement $node, Item $item) | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
getPropertiesMapping() | |
100.00% |
1 / 1 |
1 | ||||||
setProperties(DOMElement $node, Item $item) | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
<?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 FastFeed\Item; | |
use FastFeed\Aggregator\AggregatorInterface; | |
use FastFeed\Exception\LogicException; | |
/** | |
* AbstractParser | |
*/ | |
abstract class AbstractParser extends AbstractDomParser | |
{ | |
/** | |
* @var array | |
*/ | |
protected $aggregators = array(); | |
/** | |
* @return mixed | |
* @throws \FastFeed\Exception\LogicException | |
*/ | |
public function popAggregator() | |
{ | |
if (!$this->aggregators) { | |
throw new LogicException('You tried to pop from an empty Aggregator stack.'); | |
} | |
return array_shift($this->aggregators); | |
} | |
/** | |
* @param AggregatorInterface $aggregator | |
*/ | |
public function pushAggregator(AggregatorInterface $aggregator) | |
{ | |
$this->aggregators[] = $aggregator; | |
} | |
/** | |
* @param DOMElement $node | |
* @param Item $item | |
*/ | |
protected function executeAggregators(DOMElement $node, Item $item) | |
{ | |
foreach ($this->aggregators as $aggregator) { | |
$aggregator->process($node, $item); | |
} | |
} | |
/** | |
* @return array | |
*/ | |
abstract protected function getPropertiesMapping(); | |
/** | |
* @param DOMElement $node | |
* @param Item $item | |
*/ | |
protected function setProperties(DOMElement $node, Item $item) | |
{ | |
$propertiesMapping = $this->getPropertiesMapping(); | |
foreach ($propertiesMapping as $methodName => $propertyName) { | |
$value = $this->getNodeValueByTagName($node, $propertyName); | |
if ($value) { | |
$item->$methodName($value); | |
} | |
} | |
} | |
} |