Completed
Push — issue/280 ( a6a6bd...e9a2b3 )
by Alex
02:05
created

Result::getFeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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;
12
13
use FeedIo\Adapter\ResponseInterface;
14
use FeedIo\FeedInterface;
15
use FeedIo\Reader\Result\UpdateStats;
16
17
/**
18
 * Result of the read() operation
19
 *
20
 * a Result instance holds the following :
21
 *
22
 * - the Feed instance
23
 * - Date and time of the request
24
 * - value of the 'modifiedSince' header sent through the request
25
 * - the raw response
26
 * - the DOM document
27
 * - URL of the feed
28
 */
29
class Result
30
{
31
32
    /**
33
     * @var \DateTime
34
     */
35
    protected $modifiedSince;
36
37
    /**
38
     * @var \DateTime
39
     */
40
    protected $date;
41
42
    /**
43
     * @var \FeedIo\FeedInterface
44
     */
45
    protected $feed;
46
47
    /**
48
     * @var \FeedIo\Adapter\ResponseInterface
49
     */
50
    protected $response;
51
52
    /**
53
     * @var Document
54
     */
55
    protected $document;
56
57
    /**
58
     * @var string
59
     */
60
    protected $url;
61
62
    /**
63
     * @param Document      $document
64
     * @param FeedInterface     $feed
65
     * @param \DateTime         $modifiedSince
66
     * @param ResponseInterface $response
67
     * @param $url
68
     */
69 11
    public function __construct(
70
        Document $document,
71
        FeedInterface $feed,
72
        \DateTime $modifiedSince,
73
        ResponseInterface $response,
74
        string $url
75
    ) {
76 11
        $this->date = new \DateTime();
77 11
        $this->document = $document;
78 11
        $this->feed = $feed;
79 11
        $this->modifiedSince = $modifiedSince;
80 11
        $this->response = $response;
81 11
        $this->url = $url;
82 11
    }
83
84
    /**
85
     * @return \DateTime
86
     */
87 1
    public function getDate() : \DateTime
88
    {
89 1
        return $this->date;
90
    }
91
92
    /**
93
     * @return Document
94
     */
95 1
    public function getDocument() : Document
96
    {
97 1
        return $this->document;
98
    }
99
100
    /**
101
     * @return FeedInterface
102
     */
103 9
    public function getFeed() : FeedInterface
104
    {
105 9
        return $this->feed;
106
    }
107
108
    /**
109
     * @return \DateTime|null
110
     */
111 2
    public function getModifiedSince() : ? \DateTime
112
    {
113 2
        return $this->modifiedSince;
114
    }
115
116
    /**
117
     * @return ResponseInterface
118
     */
119 4
    public function getResponse() : ResponseInterface
120
    {
121 4
        return $this->response;
122
    }
123
124
    /**
125
     * @return string
126
     */
127 1
    public function getUrl() : string
128
    {
129 1
        return $this->url;
130
    }
131
132
    /**
133
     * @param int $minDelay
134
     * @param float $marginRatio
135
     * @return \DateTime
136
     */
137
    public function getNextUpdate(
138
        int $minDelay = UpdateStats::DEFAULT_MIN_DELAY,
139
        float $marginRatio = UpdateStats::DEFAULT_MARGIN_RATIO
140
    ): \DateTime
141
    {
142
        $updateStats = new UpdateStats($this->getFeed());
143
        return $updateStats->computeNextUpdate($minDelay, $marginRatio);
144
    }
145
}
146