Completed
Pull Request — master (#83)
by Alex
18:31 queued 08:29
created

PublicId::fixItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
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 1
     */
24
    public function correct(FeedInterface $feed)
25 1
    {
26 1
        $this->fixNode($feed);
27 1
28 1
        $this->fixItems($feed);
29 1
30
        return $this;
31 1
    }
32
33
    /**
34
     * @param  NodeInterface $node
35
     * @return $this
36
     */
37
    protected function fixNode(NodeInterface $node)
38 1
    {
39
        if (is_null($node->getPublicId())) {
40 1
            $this->logger->notice("correct public id for node {$node->getTitle()}");
41 1
            $node->setPublicId($node->getLink());
42 1
        }
43
    }
44 1
45
    /**
46
     * @param  FeedInterface $feed
47
     * @return $this
48
     */
49
    protected function fixItems(FeedInterface $feed)
50
    {
51
        foreach ($feed as $item) {
52
            $this->fixNode($item);
53
        }
54
55
        return $this;
56
    }
57
58
}
59