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

LastModified   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A correct() 0 11 2
A searchLastModified() 0 12 3
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\Reader\FixerAbstract;
15
16
class LastModified extends FixerAbstract
17
{
18
19
    /**
20
     * @param  FeedInterface $feed
21
     * @return $this
22
     */
23 2
    public function correct(FeedInterface $feed)
24
    {
25 2
        if (is_null($feed->getLastModified())) {
26 1
            $this->logger->notice("correct last modified date for feed {$feed->getTitle()}");
27 1
            $feed->setLastModified(
28 1
                        $this->searchLastModified($feed)
29 1
            );
30 1
        }
31
32 2
        return $this;
33
    }
34
35
    /**
36
     * @param  FeedInterface $feed
37
     * @return \DateTime
38
     */
39 2
    public function searchLastModified(FeedInterface $feed)
40
    {
41 2
        $latest = new \DateTime('@0');
42
43 2
        foreach ($feed as $item) {
44 2
            if ($item->getLastModified() > $latest) {
45 2
                $latest = $item->getLastModified();
46 2
            }
47 2
        }
48
49 2
        return $latest;
50
    }
51
}
52