Completed
Push — issue/134 ( d0dc5e...07c20b )
by Alex
01:47
created

PublicId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A correct() 0 8 1
A fixNode() 0 7 2
A fixItems() 0 8 2
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
     */
24 2
    public function correct(FeedInterface $feed)
25
    {
26 2
        $this->fixNode($feed);
27
28 2
        $this->fixItems($feed);
29
30 2
        return $this;
31
    }
32
33
    /**
34
     * @param  NodeInterface $node
35
     * @return $this
36
     */
37 2
    protected function fixNode(NodeInterface $node)
38
    {
39 2
        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 2
    }
44
45
    /**
46
     * @param  FeedInterface $feed
47
     * @return $this
48
     */
49 2
    protected function fixItems(FeedInterface $feed)
50
    {
51 2
        foreach ($feed as $item) {
52 1
            $this->fixNode($item);
53 2
        }
54
55 2
        return $this;
56
    }
57
}
58