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 ( 490bf5...2ea53f )
by Cees-Jan
06:11
created

CreateStatusHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 31 4
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\CommandBus\Handler\Repository\Commit;
4
5
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\CreateStatusCommand;
6
use ApiClients\Client\Github\Resource\Repository\Commit\StatusInterface;
7
use ApiClients\Foundation\Hydrator\Hydrator;
8
use ApiClients\Foundation\Transport\Service\RequestService;
9
use ApiClients\Middleware\Json\JsonStream;
10
use React\Promise\PromiseInterface;
11
use RingCentral\Psr7\Request;
12
13
final class CreateStatusHandler
14
{
15
    /**
16
     * @var RequestService
17
     */
18
    private $requestService;
19
20
    /**
21
     * @var Hydrator
22
     */
23
    private $hydrator;
24
25
    /**
26
     * @param RequestService $requestService
27
     * @param Hydrator       $hydrator
28
     */
29
    public function __construct(RequestService $requestService, Hydrator $hydrator)
30
    {
31
        $this->requestService = $requestService;
32
        $this->hydrator = $hydrator;
33
    }
34
35
    /**
36
     * @param  CreateStatusCommand $command
37
     * @return PromiseInterface
38
     */
39
    public function handle(CreateStatusCommand $command): PromiseInterface
40
    {
41
        $json = [
42
            'state' => $command->getState(),
43
        ];
44
45
        $targetUrl = $command->getTargetUrl();
46
        if ($targetUrl !== null) {
47
            $json['target_url'] = $targetUrl;
48
        }
49
        $description = $command->getDescription();
50
        if ($description !== null) {
51
            $json['description'] = $description;
52
        }
53
        $context = $command->getContext();
54
        if ($context !== null) {
55
            $json['context'] = $context;
56
        }
57
        unset($targetUrl, $description, $context);
58
59
        return $this->requestService->request(
60
            new Request(
61
                'POST',
62
                \str_replace('/commits/', '/statuses/', $command->getCommit()->url()),
63
                [],
64
                new JsonStream($json)
65
            )
66
        )->then(function ($status) {
67
            return $this->hydrator->hydrate(StatusInterface::HYDRATE_CLASS, $status->getBody()->getParsedContents());
68
        });
69
    }
70
}
71