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 (#9)
by Cees-Jan
03:34
created

JobLogHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 0
loc 44
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 14 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis\CommandBus\Handler;
4
5
use ApiClients\Client\Pusher\Event;
6
use ApiClients\Client\Pusher\Service\SharedAppClientService;
7
use ApiClients\Client\Travis\ApiSettings;
8
use ApiClients\Client\Travis\AsyncClient;
9
use ApiClients\Client\Pusher\AsyncClient as PusherAsyncClient;
10
use ApiClients\Client\Travis\CommandBus\Command\JobCommand;
11
use ApiClients\Client\Travis\CommandBus\Command\JobLogCommand;
12
use ApiClients\Client\Travis\Resource\LogLineInterface;
13
use ApiClients\Foundation\Hydrator\Hydrator;
14
use React\Promise\PromiseInterface;
15
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
16
use function React\Promise\resolve;
17
use Rx\React\Promise;
18
use function WyriHaximus\React\futureFunctionPromise;
19
20
final class JobLogHandler
21
{
22
    /**
23
     * @var SharedAppClientService
24
     */
25
    private $pusher;
26
27
    /**
28
     * @var Hydrator
29
     */
30
    private $hydrator;
31
32
    /**
33
     * JobLogHandler constructor.
34
     * @param SharedAppClientService $pusher
35
     * @param Hydrator $hydrator
36
     */
37
    public function __construct(SharedAppClientService $pusher, Hydrator $hydrator)
38
    {
39
        $this->pusher = $pusher;
40
        $this->hydrator = $hydrator;
41
    }
42
43
    /**
44
     * Fetch the given repository and hydrate it
45
     *
46
     * @param JobLogCommand $command
47
     * @return PromiseInterface
48
     */
49
    public function handle(JobLogCommand $command): PromiseInterface
50
    {
51
        return $this->pusher->handle(
52
            ApiSettings::PUSHER_KEY
53
        )->then(function (PusherAsyncClient $pusher) use ($command) {
54
            return resolve(
55
                $pusher->channel('job-' . (string)$command->getId())->filter(function (Event $event) {
56
                    return $event->getEvent() === 'job:log';
57
                })->map(function (Event $event) {
58
                    return $this->hydrator->hydrate(LogLineInterface::HYDRATE_CLASS, $event->getData());
59
                })
60
            );
61
        });
62
    }
63
}
64