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 ( 2d5dc2...c17ad1 )
by Cees-Jan
09:41
created

CommitHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 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\CommitCommand;
6
use ApiClients\Client\Github\Resource\Git\CommitInterface;
7
use ApiClients\Foundation\Hydrator\Hydrator;
8
use ApiClients\Foundation\Transport\Service\RequestService;
9
use ApiClients\Middleware\Json\JsonStream;
10
use React\EventLoop\LoopInterface;
11
use React\Promise\PromiseInterface;
12
use RingCentral\Psr7\Request;
13
14 View Code Duplication
final class CommitHandler
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...
15
{
16
    /**
17
     * @var RequestService
18
     */
19
    private $requestService;
20
21
    /**
22
     * @var Hydrator
23
     */
24
    private $hydrator;
25
26
    /**
27
     * @var LoopInterface
28
     */
29
    private $loop;
30
31
    /**
32
     * @param RequestService $requestService
33
     * @param Hydrator       $hydrator
34
     * @param LoopInterface  $loop
35
     */
36
    public function __construct(RequestService $requestService, Hydrator $hydrator, LoopInterface $loop)
37
    {
38
        $this->requestService = $requestService;
39
        $this->hydrator = $hydrator;
40
        $this->loop = $loop;
41
    }
42
43
    /**
44
     * @param  CommitCommand    $command
45
     * @return PromiseInterface
46
     */
47
    public function handle(CommitCommand $command): PromiseInterface
48
    {
49
        return $this->requestService->request(
50
            new Request(
51
                'POST',
52
                'repos/' . $command->getRepository() . '/git/commits',
53
                [],
54
                new JsonStream([
55
                    'message' => $command->getMessage(),
56
                    'tree' => $command->getTree(),
57
                    'parents' => $command->getCommit(),
58
                ])
59
            )
60
        )->then(function ($tree) {
61
            return $this->hydrator->hydrate(CommitInterface::HYDRATE_CLASS, $tree->getBody()->getParsedContents());
62
        });
63
    }
64
}
65