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.

AddWebHookHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
ccs 14
cts 14
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\CommandBus\Handler\Organization;
4
5
use ApiClients\Client\Github\CommandBus\Command\Organization\AddWebHookCommand;
6
use ApiClients\Client\Github\Resource\WebHookInterface;
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 View Code Duplication
final class AddWebHookHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 1
    public function __construct(RequestService $requestService, Hydrator $hydrator)
30
    {
31 1
        $this->requestService = $requestService;
32 1
        $this->hydrator = $hydrator;
33 1
    }
34
35
    /**
36
     * @param  AddWebHookCommand $command
37
     * @return PromiseInterface
38
     */
39 1
    public function handle(AddWebHookCommand $command): PromiseInterface
40
    {
41 1
        return $this->requestService->request(
42 1
            new Request(
43 1
                'POST',
44 1
                'orgs/' . $command->getOrganization() . '/hooks',
45 1
                [],
46 1
                new JsonStream([
47 1
                    'name'   => $command->getName(),
48 1
                    'config' => $command->getConfig(),
49 1
                    'events' => $command->getEvents(),
50 1
                    'active' => $command->isActive(),
51
                ])
52
            )
53 1
        )->then(function ($hook) {
54 1
            return $this->hydrator->hydrate(WebHookInterface::HYDRATE_CLASS, $hook->getBody()->getParsedContents());
55 1
        });
56
    }
57
}
58