Completed
Pull Request — master (#257)
by
unknown
01:57
created

PublicId::fixNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Reader\Fixer;
12
13
use FeedIo\FeedInterface;
14
use FeedIo\Feed\NodeInterface;
15
use FeedIo\Reader\FixerAbstract;
16
17
class PublicId extends FixerAbstract
18
{
19
20
    /**
21
     * @param  FeedInterface $feed
22
     * @return $this
23
     */
24
    public function correct(FeedInterface $feed) : FixerAbstract
25
    {
26
        $this->fixNode($feed);
27
28
        $this->fixItems($feed);
29
30
        return $this;
31
    }
32
33
    /**
34
     * @param  NodeInterface $node
35
     */
36
    protected function fixNode(NodeInterface $node) : void
37
    {
38
        if (is_null($node->getPublicId())) {
39
            $this->logger->notice("correct public id for node {$node->getTitle()}");
40
            $node->setPublicId($node->getLink());
41
        }
42
    }
43
44
    /**
45
     * @param  FeedInterface $feed
46
     */
47
    protected function fixItems(FeedInterface $feed) : void
48
    {
49
        foreach ($feed as $item) {
50
            $this->fixNode($item);
51
        }
52
    }
53
}
54