GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5e68ac...cec8b8 )
by Cees-Jan
10s
created

StreamingClient::filtered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Twitter;
4
5
use ApiClients\Foundation\Hydrator\CommandBus\Command\BuildSyncFromAsyncCommand;
6
use ApiClients\Foundation\Resource\ResourceInterface;
7
use ApiClients\Tools\CommandBus\CommandBusInterface;
8
use React\EventLoop\LoopInterface;
9
use ReflectionObject;
10
use Rx\ObservableInterface;
11
use Rx\React\Promise;
12
13
final class StreamingClient implements StreamingClientInterface
14
{
15
    /**
16
     * @var LoopInterface
17
     */
18
    protected $loop;
19
20
    /**
21
     * @var CommandBusInterface
22
     */
23
    protected $commandBus;
24
25
    /**
26
     * @var AsyncStreamingClientInterface
27
     */
28
    protected $client;
29
30
    /**
31
     * @var array
32
     */
33
    protected $hydrateClassConstantCache = [];
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $hydrateClassConstantCache exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
34
35
    /**
36
     * StreamingClient constructor.
37
     * @param LoopInterface $loop
38
     * @param CommandBusInterface $commandBus
39
     * @param AsyncStreamingClientInterface $client
40
     */
41
    public function __construct(
42
        LoopInterface $loop,
43
        CommandBusInterface $commandBus,
44
        AsyncStreamingClientInterface $client
45
    ) {
46
        $this->loop = $loop;
47
        $this->commandBus = $commandBus;
48
        $this->client = $client;
49
    }
50
51
    public function sample(callable $listener)
52
    {
53
        $this->stream($this->client->sample(), $listener);
54
    }
55
56
    public function filtered(callable $listener, array $filter = [])
57
    {
58
        $this->stream($this->client->filtered($filter), $listener);
59
    }
60
61
    protected function stream(ObservableInterface $observable, callable $listener)
62
    {
63
        $observable->flatMap(function (ResourceInterface $resource) {
64
            return Promise::toObservable(
65
                $this->commandBus->handle(
66
                    new BuildSyncFromAsyncCommand(
67
                        $this->loopUpHydrateClassConstant($resource),
68
                        $resource
69
                    )
70
                )
71
            );
72
        })->subscribeCallback(
73
            $listener,
74
            function ($error) {
75
                throw $error;
76
            }
77
        );
78
        $this->loop->run();
79
    }
80
81
    protected function loopUpHydrateClassConstant(ResourceInterface $resource)
82
    {
83
        $class = get_class($resource);
84
        if (!isset($this->hydrateClassConstantCache[$class])) {
85
            $this->hydrateClassConstantCache[$class] = (new ReflectionObject($resource))->getConstant('HYDRATE_CLASS');
86
        }
87
88
        return $this->hydrateClassConstantCache[$class];
89
    }
90
}
91