<?php

declare (strict_types=1);
namespace OCA\News\Vendor\FeedIo\Rule;

use OCA\News\Vendor\FeedIo\Feed\NodeInterface;
use OCA\News\Vendor\FeedIo\RuleAbstract;
class PublicId extends RuleAbstract
{
    public const NODE_NAME = 'guid';
    /**
     * @param  NodeInterface $node
     * @param  \DOMElement   $element
     */
    public function setProperty(NodeInterface $node, \DOMElement $element): void
    {
        $node->setPublicId($element->nodeValue);
        if ($element->nodeName === 'guid' && $element->getAttribute('isPermaLink') === 'true' && $node->getLink() === null) {
            $node->setLink($element->nodeValue);
        }
    }
    /**
     * @inheritDoc
     */
    protected function hasValue(NodeInterface $node): bool
    {
        return !!$node->getPublicId();
    }
    /**
     * @inheritDoc
     */
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node): void
    {
        $rootElement->appendChild($document->createElement($this->getNodeName(), $node->getPublicId()));
    }
}
