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 ( cc1167...8f32c7 )
by Cees-Jan
04:30
created

StreamingClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 96.55%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 78
ccs 28
cts 29
cp 0.9655
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A sample() 0 4 1
A filtered() 0 4 1
A loopUpHydrateClassConstant() 0 9 2
A stream() 0 19 1
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 6
    public function __construct(
42
        LoopInterface $loop,
43
        CommandBusInterface $commandBus,
44
        AsyncStreamingClientInterface $client
45
    ) {
46 6
        $this->loop = $loop;
47 6
        $this->commandBus = $commandBus;
48 6
        $this->client = $client;
49 6
    }
50
51 1
    public function sample(callable $listener)
52
    {
53 1
        $this->stream($this->client->sample(), $listener);
54 1
    }
55
56 5
    public function filtered(callable $listener, array $filter = [])
57
    {
58 5
        $this->stream($this->client->filtered($filter), $listener);
59 5
    }
60
61 6
    protected function stream(ObservableInterface $observable, callable $listener)
62
    {
63
        $observable->flatMap(function (ResourceInterface $resource) {
64 6
            return Promise::toObservable(
65 6
                $this->commandBus->handle(
66 6
                    new BuildSyncFromAsyncCommand(
67 6
                        $this->loopUpHydrateClassConstant($resource),
68 6
                        $resource
69
                    )
70
                )
71
            );
72 6
        })->subscribe(
73 6
            $listener,
74 6
            function ($error) {
75
                throw $error;
76 6
            }
77
        );
78 6
        $this->loop->run();
79 6
    }
80
81 6
    protected function loopUpHydrateClassConstant(ResourceInterface $resource)
82
    {
83 6
        $class = get_class($resource);
84 6
        if (!isset($this->hydrateClassConstantCache[$class])) {
85 6
            $this->hydrateClassConstantCache[$class] = (new ReflectionObject($resource))->getConstant('HYDRATE_CLASS');
86
        }
87
88 6
        return $this->hydrateClassConstantCache[$class];
89
    }
90
}
91