1 | <?php declare(strict_types=1); |
||
76 | class FeedIo |
||
77 | { |
||
78 | |||
79 | /** |
||
80 | * @var \FeedIo\Reader |
||
81 | */ |
||
82 | protected $reader; |
||
83 | |||
84 | /** |
||
85 | * @var \FeedIo\Rule\DateTimeBuilder |
||
86 | */ |
||
87 | protected $dateTimeBuilder; |
||
88 | |||
89 | /** |
||
90 | * @var \FeedIo\Adapter\ClientInterface; |
||
91 | */ |
||
92 | protected $client; |
||
93 | |||
94 | /** |
||
95 | * @var \Psr\Log\LoggerInterface |
||
96 | */ |
||
97 | protected $logger; |
||
98 | |||
99 | /** |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $standards; |
||
103 | |||
104 | /** |
||
105 | * @var \FeedIo\Reader\FixerSet |
||
106 | */ |
||
107 | protected $fixerSet; |
||
108 | |||
109 | /** |
||
110 | * @param \FeedIo\Adapter\ClientInterface $client |
||
111 | * @param \Psr\Log\LoggerInterface $logger |
||
112 | */ |
||
113 | 12 | public function __construct(ClientInterface $client, LoggerInterface $logger, DateTimeBuilderInterface $dateTimeBuilder = null) |
|
122 | |||
123 | /** |
||
124 | * Loads main standards (RSS, RDF, Atom) in current object's attributes |
||
125 | * |
||
126 | * @return FeedIo |
||
127 | */ |
||
128 | 12 | protected function loadCommonStandards() : FeedIo |
|
137 | |||
138 | /** |
||
139 | * adds a filter to the reader |
||
140 | * |
||
141 | * @param \FeedIo\FilterInterface $filter |
||
142 | * @return FeedIo |
||
143 | */ |
||
144 | 2 | public function addFilter(FilterInterface $filter) : FeedIo |
|
150 | |||
151 | /** |
||
152 | * Returns main standards |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | 12 | public function getCommonStandards() : array |
|
162 | |||
163 | /** |
||
164 | * @param string $name |
||
165 | * @param \FeedIo\StandardAbstract $standard |
||
166 | * @return FeedIo |
||
167 | */ |
||
168 | 12 | public function addStandard(string $name, StandardAbstract $standard) : FeedIo |
|
177 | |||
178 | /** |
||
179 | * @param string $format |
||
180 | * @param StandardAbstract $standard |
||
181 | * @return ParserAbstract |
||
182 | */ |
||
183 | 11 | public function newParser(string $format, StandardAbstract $standard) : ParserAbstract |
|
193 | |||
194 | /** |
||
195 | * @return \FeedIo\Reader\FixerSet |
||
196 | */ |
||
197 | 1 | public function getFixerSet() : FixerSet |
|
201 | |||
202 | /** |
||
203 | * @return FeedIo |
||
204 | */ |
||
205 | 11 | protected function loadFixerSet() : FeedIo |
|
216 | |||
217 | /** |
||
218 | * @param FixerAbstract $fixer |
||
219 | * @return FeedIo |
||
220 | */ |
||
221 | 11 | public function addFixer(FixerAbstract $fixer) : FeedIo |
|
228 | |||
229 | /** |
||
230 | * @return array |
||
231 | */ |
||
232 | 11 | public function getBaseFixers() : array |
|
233 | { |
||
234 | return array( |
||
235 | 11 | new Reader\Fixer\HttpLastModified(), |
|
236 | 11 | new Reader\Fixer\PublicId(), |
|
237 | 11 | ); |
|
238 | 11 | } |
|
239 | |||
240 | /** |
||
241 | * @param array $formats |
||
242 | * @return FeedIo |
||
243 | */ |
||
244 | public function addDateFormats(array $formats) : FeedIo |
||
245 | { |
||
246 | foreach ($formats as $format) { |
||
247 | $this->getDateTimeBuilder()->addDateFormat($format); |
||
248 | } |
||
249 | |||
250 | return $this; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @return \FeedIo\Rule\DateTimeBuilder |
||
255 | */ |
||
256 | public function getDateTimeBuilder() : DateTimeBuilder |
||
257 | { |
||
258 | 12 | return $this->dateTimeBuilder; |
|
259 | } |
||
260 | 12 | ||
261 | /** |
||
262 | * @return \FeedIo\Reader |
||
263 | */ |
||
264 | public function getReader() : Reader |
||
265 | { |
||
266 | 4 | return $this->reader; |
|
267 | } |
||
268 | 4 | ||
269 | /** |
||
270 | * @param \FeedIo\Reader $reader |
||
271 | * @return FeedIo |
||
272 | */ |
||
273 | public function setReader(Reader $reader) : FeedIo |
||
274 | { |
||
275 | 12 | $this->reader = $reader; |
|
276 | |||
277 | 12 | return $this; |
|
278 | } |
||
279 | 12 | ||
280 | /** |
||
281 | * Discover feeds from the webpage's headers |
||
282 | * @param string $url |
||
283 | * @return array |
||
284 | */ |
||
285 | public function discover(string $url) : array |
||
286 | { |
||
287 | 1 | $explorer = new Explorer($this->client, $this->logger); |
|
288 | |||
289 | 1 | return $explorer->discover($url); |
|
290 | } |
||
291 | 1 | ||
292 | /** |
||
293 | * @param iterable $requests |
||
294 | * @param CallbackInterface $callback |
||
295 | * @param string $feedClass |
||
296 | */ |
||
297 | public function readAsync(iterable $requests, CallbackInterface $callback, string $feedClass = '\FeedIo\Feed') : void |
||
298 | { |
||
299 | $reader = new AsyncReader($this->reader, $this->reader->getClient(), $callback, $feedClass); |
||
300 | |||
301 | $reader->process($requests); |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * @param string $url |
||
306 | * @param FeedInterface $feed |
||
307 | * @param \DateTime $modifiedSince |
||
308 | * @return \FeedIo\Reader\Result |
||
309 | */ |
||
310 | public function read(string $url, FeedInterface $feed = null, \DateTime $modifiedSince = null) : Result |
||
311 | { |
||
312 | 2 | if (is_null($feed)) { |
|
313 | $feed = new Feed(); |
||
314 | 2 | } |
|
315 | 1 | ||
316 | if ($modifiedSince instanceof \DateTime) { |
||
317 | $this->addFilter(new ModifiedSince($modifiedSince)); |
||
318 | 2 | } |
|
319 | 1 | ||
320 | $this->logAction($feed, "read access : $url into a feed instance"); |
||
321 | $result = $this->reader->read($url, $feed, $modifiedSince); |
||
322 | 2 | ||
323 | 2 | $this->fixerSet->correct($result); |
|
324 | $this->resetFilters(); |
||
325 | 2 | ||
326 | 2 | return $result; |
|
327 | } |
||
328 | 2 | ||
329 | /** |
||
330 | * @param string $url |
||
331 | * @param \DateTime $modifiedSince |
||
332 | * @return \FeedIo\Reader\Result |
||
333 | */ |
||
334 | public function readSince(string $url, \DateTime $modifiedSince) : Result |
||
338 | 1 | ||
339 | /** |
||
340 | * @return FeedIo |
||
341 | */ |
||
342 | public function resetFilters() : FeedIo |
||
348 | 2 | ||
349 | /** |
||
350 | * Get a PSR-7 compliant response for the given feed |
||
351 | * |
||
352 | * @param \FeedIo\FeedInterface $feed |
||
353 | * @param string $standard |
||
354 | * @param int $maxAge |
||
355 | * @param bool $public |
||
356 | * @return ResponseInterface |
||
357 | */ |
||
358 | public function getPsrResponse(FeedInterface $feed, string $standard, int $maxAge = 600, bool $public = true) : ResponseInterface |
||
367 | 1 | ||
368 | /** |
||
369 | * @param FeedInterface $feed |
||
370 | * @param string $standard Standard's name |
||
371 | * @return string |
||
372 | */ |
||
373 | public function format(FeedInterface $feed, string $standard) : string |
||
381 | 1 | ||
382 | /** |
||
383 | * @param \FeedIo\FeedInterface $feed |
||
384 | * @return string |
||
385 | */ |
||
386 | public function toRss(FeedInterface $feed) : string |
||
390 | 1 | ||
391 | /** |
||
392 | * @param \FeedIo\FeedInterface $feed |
||
393 | * @return string |
||
394 | */ |
||
395 | public function toAtom(FeedInterface $feed) : string |
||
399 | 1 | ||
400 | /** |
||
401 | * @param \FeedIo\FeedInterface $feed |
||
402 | * @return string |
||
403 | */ |
||
404 | public function toJson(FeedInterface $feed) : string |
||
408 | 1 | ||
409 | |||
410 | /** |
||
411 | * @param string $name |
||
412 | * @return \FeedIo\StandardAbstract |
||
413 | * @throws \OutOfBoundsException |
||
414 | */ |
||
415 | public function getStandard(string $name) : StandardAbstract |
||
424 | 1 | ||
425 | /** |
||
426 | * @param \FeedIo\FeedInterface $feed |
||
427 | * @param string $message |
||
428 | * @return FeedIo |
||
429 | */ |
||
430 | protected function logAction(FeedInterface $feed, string $message) : FeedIo |
||
437 | } |
||
438 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.