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 ( 2a68b7...deb6f2 )
by Cees-Jan
03:03
created

AddLabelHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 0
cts 20
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 16 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\CommandBus\Handler\Repository;
4
5
use ApiClients\Client\Github\CommandBus\Command\Repository\AddLabelCommand;
6
use ApiClients\Client\Github\Resource\LabelInterface;
7
use ApiClients\Foundation\Hydrator\Hydrator;
8
use ApiClients\Foundation\Transport\JsonStream;
9
use ApiClients\Foundation\Transport\Service\RequestService;
10
use React\Promise\PromiseInterface;
11
use RingCentral\Psr7\Request;
12
use Rx\Observable;
13
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
14
use function React\Promise\resolve;
15
use function WyriHaximus\React\futureFunctionPromise;
16
17
final class AddLabelHandler
18
{
19
    /**
20
     * @var RequestService
21
     */
22
    private $requestService;
23
24
    /**
25
     * @var Hydrator
26
     */
27
    private $hydrator;
28
29
    /**
30
     * @param RequestService $requestService
31
     * @param Hydrator $hydrator
32
     */
33
    public function __construct(RequestService $requestService, Hydrator $hydrator)
34
    {
35
        $this->requestService = $requestService;
36
        $this->hydrator = $hydrator;
37
    }
38
39
    /**
40
     * @param AddLabelCommand $command
41
     * @return PromiseInterface
42
     */
43
    public function handle(AddLabelCommand $command): PromiseInterface
44
    {
45
        return $this->requestService->handle(
46
            new Request(
47
                'POST',
48
                'repos/' . $command->getRepository() . '/labels',
49
                [],
50
                new JsonStream([
51
                    'name' => $command->getName(),
52
                    'color' => $command->getColour(),
53
                ])
54
            )
55
        )->then(function ($label) {
56
            return $this->hydrator->hydrate(LabelInterface::HYDRATE_CLASS, $label->getBody()->getJson());
57
        });
58
    }
59
}
60