Completed
Pull Request — master (#262)
by Alex
62:38 queued 61:26
created

HttpLastModified::isInvalid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php declare(strict_types=1);
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
use FeedIo\Reader\Result;
16
17
class HttpLastModified extends FixerAbstract
18
{
19
20
    /**
21
     * @param Result $result
22
     * @return FixerAbstract
23
     */
24 3
    public function correct(Result $result): FixerAbstract
25
    {
26 3
        $feed = $result->getFeed();
27 3
        $response = $result->getResponse();
28
29 3
        if ($this->isInvalid($feed) && $response->getLastModified() instanceof \DateTime) {
30 1
            $this->logger->debug("found last modified: " . $response->getLastModified()->format(\DateTime::RSS));
31 1
            $feed->setLastModified($response->getLastModified());
32
        }
33
34 3
        return $this;
35
    }
36
37
    /**
38
     * @param  FeedInterface $feed
39
     * @return bool
40
     */
41 3
    protected function isInvalid(FeedInterface $feed): bool
42
    {
43 3
        return is_null($feed->getLastModified()) || $feed->getLastModified() == new \DateTime('@0');
44
    }
45
}
46