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
Pull Request — master (#1)
by Cees-Jan
03:10
created

FetchAndIterateService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 20 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis\Service;
4
5
use ApiClients\Client\Travis\CommandBus\Command\BroadcastsCommand;
6
use ApiClients\Client\Travis\Resource\BroadcastInterface;
7
use ApiClients\Foundation\Hydrator\Hydrator;
8
use ApiClients\Foundation\Service\ServiceInterface;
9
use ApiClients\Foundation\Transport\Service\RequestService;
10
use Psr\Http\Message\ResponseInterface;
11
use React\Promise\CancellablePromiseInterface;
12
use React\Promise\PromiseInterface;
13
use RingCentral\Psr7\Request;
14
use Rx\Observable;
15
use Rx\React\Promise;
16
use function React\Promise\resolve;
17
use function igorw\get_in;
18
use function WyriHaximus\React\futureFunctionPromise;
19
20
class FetchAndIterateService implements ServiceInterface
21
{
22
    /**
23
     * @var RequestService
24
     */
25
    private $requestService;
26
27
    /**
28
     * @var Hydrator
29
     */
30
    private $hydrator;
31
32
    /**
33
     * @param RequestService $requestService
34
     * @param Hydrator $hydrator
35
     */
36
    public function __construct(RequestService $requestService, Hydrator $hydrator)
37
    {
38
        $this->requestService = $requestService;
39
        $this->hydrator = $hydrator;
40
    }
41
42
    /**
43
     * @param string|null $path
44
     * @param string|null $index
45
     * @param string|null $hydrateClass
46
     * @return CancellablePromiseInterface
47
     */
48
    public function handle(
49
        string $path = null,
50
        string $index = null,
51
        string $hydrateClass = null
52
    ): CancellablePromiseInterface {
53
        return resolve(
54
            Promise::toObservable(
55
                $this->requestService->handle(
56
                    new Request('GET', $path)
57
                )
58
            )->flatMap(function ($response) use ($index) {
59
                return Observable::fromArray(get_in($response->getBody()->getJson(), explode('.', $index), []));
60
            })->map(function ($json) use ($hydrateClass) {
61
                return $this->hydrator->hydrate(
62
                    $hydrateClass,
63
                    $json
64
                );
65
            })
66
        );
67
    }
68
}
69