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

LastModified::searchLastModified()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 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