PublicId::fixNode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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
use FeedIo\Reader\Result;
17
18
class PublicId extends FixerAbstract
19
{
20
21
    /**
22
     * @param  Result $result
23
     * @return $this
24
     */
25 2
    public function correct(Result $result) : FixerAbstract
26
    {
27 2
        $feed = $result->getFeed();
28
29 2
        $this->fixNode($feed);
30 2
        $this->fixItems($feed);
31
32 2
        return $this;
33
    }
34
35
    /**
36
     * @param  NodeInterface $node
37
     */
38 2
    protected function fixNode(NodeInterface $node) : void
39
    {
40 2
        if (is_null($node->getPublicId())) {
41 1
            $this->logger->notice("correct public id for node {$node->getTitle()}");
42 1
            $node->setPublicId($node->getLink());
43
        }
44 2
    }
45
46
    /**
47
     * @param  FeedInterface $feed
48
     */
49 2
    protected function fixItems(FeedInterface $feed) : void
50
    {
51 2
        foreach ($feed as $item) {
52 1
            $this->fixNode($item);
53
        }
54 2
    }
55
}
56