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::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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