Completed
Push — issue/84 ( 0f4f84 )
by Alex
13s
created

PublicId   A

Complexity

Total Complexity 5

Size/Duplication

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