Completed
Push — master ( 631b00...2fe979 )
by Alex
01:43
created

CheckLastModified::perform()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 3
nc 4
nop 3
1
<?php declare(strict_types=1);
2
3
4
namespace FeedIo\Check;
5
6
use FeedIo\Feed;
7
use FeedIo\FeedIo;
8
9
/**
10
 * Class CheckLastModified
11
 * @codeCoverageIgnore
12
 */
13
class CheckLastModified implements CheckInterface
14
{
15
    public function perform(FeedIo $feedIo, Feed $feed, Result $result): bool
16
    {
17
        $lastModifiedDates = [];
18
        $result->setModifiedSince($feed->getLastModified());
19
        /** @var \FeedIo\Feed\ItemInterface $item */
20
        foreach ($feed as $i => $item) {
21
            $lastModifiedDates[] = $item->getLastModified();
22
        }
23
        sort($lastModifiedDates);
24
        $first = current($lastModifiedDates);
25
        $last = end($lastModifiedDates);
26
27
        $result->setItemDates($lastModifiedDates);
28
        if (!($last > $first)) {
29
            $result->markAsFailed(Result::TEST_NORMAL_DATE_FLOW);
30
        }
31
        return true;
32
    }
33
}
34