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 ( a58b9e...c0537b )
by Cees-Jan
18s
created

JobLogHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis\CommandBus\Handler;
4
5
use ApiClients\Client\Pusher\AsyncClient as PusherAsyncClient;
6
use ApiClients\Client\Pusher\Event;
7
use ApiClients\Client\Pusher\Service\SharedAppClientService;
8
use ApiClients\Client\Travis\ApiSettings;
9
use ApiClients\Client\Travis\CommandBus\Command\JobLogCommand;
10
use ApiClients\Client\Travis\Resource\LogLineInterface;
11
use ApiClients\Foundation\Hydrator\Hydrator;
12
use React\Promise\PromiseInterface;
13
use Rx\Observable;
14
use Rx\ObserverInterface;
15
use Rx\SchedulerInterface;
16
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
17
use function React\Promise\resolve;
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->share(
52
            ApiSettings::PUSHER_KEY
53
        )->then(function (PusherAsyncClient $pusher) use ($command) {
54
            return resolve(Observable::create(function (
55
                ObserverInterface $observer,
56
                SchedulerInterface $scheduler
57
            ) use (
58
                $pusher,
59
                $command
60
            ) {
61
                $subscription = $pusher->channel('job-' . (string)$command->getId())->filter(function (Event $event) {
0 ignored issues
show
Unused Code introduced by
$subscription is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
                    return $event->getEvent() === 'job:log';
63
                })->map(function (Event $event) {
64
                    return $this->hydrator->hydrate(LogLineInterface::HYDRATE_CLASS, $event->getData());
65
                })->subscribeCallback(
66
                    function (LogLineInterface $line) use ($observer, &$subscription) {
67
                        $observer->onNext($line);
68
69
                        if ($line->final()) {
70
                            $subscription->dispose();
71
                        }
72
                    },
73
                    function ($error) use ($observer) {
74
                        $observer->onError($error);
75
                    },
76
                    function () use ($observer) {
77
                        $observer->onComplete();
0 ignored issues
show
Bug introduced by
The method onComplete() does not exist on Rx\ObserverInterface. Did you maybe mean onCompleted()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
78
                    },
79
                    $scheduler
80
                );
81
            }));
82
        });
83
    }
84
}
85