Completed
Push — issue/127 ( 820451 )
by Alex
03:52
created

Reader::newFeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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\Async;
12
13
use \GuzzleHttp\Client as GuzzleClient;
14
use \GuzzleHttp\Promise\EachPromise;
15
use \FeedIo\Reader as MainReader;
16
use \FeedIo\Reader\Result;
17
use \FeedIo\FeedInterface;
18
19
class Reader
20
{
21
    /**
22
     * @var \FeedIo\Reader
23
     */
24
    protected $reader;
25
26
    /**
27
     * @var CallbackInterface
28
     */
29
    protected $callback;
30
31
    /**
32
     * @var string
33
     */
34
    protected $feedClass;
35
36
37
    /**
38
     * Reader constructor.
39
     * @param MainReader $reader
40
     * @param CallbackInterface $callback
41
     * @param string $feedClass
42
     */
43
    public function __construct(MainReader $reader, CallbackInterface $callback, string $feedClass)
44
    {
45
        $this->reader = $reader;
46
        $this->callback = $callback;
47
        $this->feedClass = $feedClass;
48
    }
49
50
    /**
51
     * @param iterable $requests
52
     */
53
    public function process(iterable $requests) : void
54
    {
55
        $client = new Client(new GuzzleClient(), $this);
56
        $promises = $client->getPromises($requests);
57
58
        (new EachPromise($promises))->promise()->wait();
59
    }
60
61
    /**
62
     * @param Request $request
63
     */
64
    public function handle(Request $request) : void
65
    {
66
        $feed = $this->newFeed();
67
        #$document = $this->reader->handleResponse($request->getResponse(), $feed);
68
        $document = new MainReader\Document('toto');
69
70
        $result = new Result($document, $feed, $request->getModifiedSince(), $request->getResponse(), $request->getUrl());
71
72
        $this->callback->process($result);
73
    }
74
75
    /**
76
     * @return FeedInterface
77
     */
78
    public function newFeed() : FeedInterface
79
    {
80
        $reflection = new \ReflectionClass($this->feedClass);
81
82
        return $reflection->newInstanceArgs();
83
    }
84
}
85