Completed
Push — issue/300 ( fd6ec3 )
by Alex
01:38
created

CheckLastModified   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

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