Completed
Push — issue/134 ( 534dd9 )
by Alex
02:01
created

LastModified   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

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
    public function correct(FeedInterface $feed)
24
    {
25
        if (is_null($feed->getLastModified())) {
26
            $this->logger->notice("correct last modified date for feed {$feed->getTitle()}");
27
            $feed->setLastModified(
28
                        $this->searchLastModified($feed)
29
            );
30
        }
31
32
        return $this;
33
    }
34
35
    /**
36
     * @param  FeedInterface $feed
37
     * @return \DateTime
38
     */
39
    public function searchLastModified(FeedInterface $feed)
40
    {
41
        $latest = new \DateTime('@0');
42
43
        foreach ($feed as $item) {
44
            if ($item->getLastModified() > $latest) {
45
                $latest = $item->getLastModified();
46
            }
47
        }
48
49
        return $latest;
50
    }
51
}
52