Skip to content

Commit

Permalink
Merge pull request #187 from alexdebril/issue/186
Browse files Browse the repository at this point in the history
Issue/186
  • Loading branch information
alexdebril authored Jun 22, 2018
2 parents ed66d0f + 3f5284a commit 0a64aeb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/FeedIo/Rule/Atom/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public function setProperty(NodeInterface $node, \DOMElement $element) : void
*/
protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
{
$element = $document->createElement(static::NODE_NAME);
$element->appendChild($document->createElement('name', $node->getAuthor()->getName()));
$element->appendChild($document->createElement('uri', $node->getAuthor()->getUri()));
$element->appendChild($document->createElement('email', $node->getAuthor()->getEmail()));
if ($node instanceof ItemInterface ) {
$element = $document->createElement(static::NODE_NAME);
$this->appendNonEmptyChild($document, $element, 'name', $node->getAuthor()->getName());
$this->appendNonEmptyChild($document, $element, 'uri', $node->getAuthor()->getUri());
$this->appendNonEmptyChild($document, $element, 'email', $node->getAuthor()->getEmail());

$rootElement->appendChild($element);
$rootElement->appendChild($element);
}
}
}
13 changes: 0 additions & 13 deletions src/FeedIo/Rule/Atom/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,4 @@ public function createCategoryElement(\DomDocument $document, CategoryInterface

return $element;
}

/**
* Sets the attribute only if the value is not emtpy
* @param DomElement $element
* @param string $name
* @param string $value
*/
protected function setNonEmptyAttribute(\DomElement $element, string $name, string $value = null) : void
{
if (! is_null($value)) {
$element->setAttribute($name, $value);
}
}
}
27 changes: 27 additions & 0 deletions src/FeedIo/RuleAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ public function apply(\DomDocument $document, \DOMElement $rootElement, NodeInte
}
}

/**
* Sets the attribute only if the value is not empty
* @param DomElement $element
* @param string $name
* @param string $value
*/
protected function setNonEmptyAttribute(\DomElement $element, string $name, string $value = null) : void
{
if (! is_null($value)) {
$element->setAttribute($name, $value);
}
}

/**
* Appends a child node only if the value is not null
* @param DomDocument $document
* @param DOMElement $element
* @param string $name
* @param string $value
*/
protected function appendNonEmptyChild(\DomDocument $document, \DOMElement $element, string $name, string $value = null) : void
{
if (! is_null($value)) {
$element->appendChild($document->createElement($name, $value));
}
}

/**
* Sets the accurate $item property according to the DomElement content
*
Expand Down

0 comments on commit 0a64aeb

Please sign in to comment.