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
Pull Request — master (#65)
by Cees-Jan
14:43 queued 04:45
created

PullRequestsHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 38
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A handle() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\CommandBus\Handler\Repository;
4
5
use ApiClients\Client\Github\CommandBus\Command\Repository\BranchesCommand;
6
use ApiClients\Client\Github\CommandBus\Command\Repository\MilestonesCommand;
7
use ApiClients\Client\Github\CommandBus\Command\Repository\PullRequestsCommand;
8
use ApiClients\Client\Github\Resource\Repository\BranchInterface;
9
use ApiClients\Client\Github\Resource\Repository\MilestoneInterface;
10
use ApiClients\Client\Github\Resource\Repository\PullRequestInterface;
11
use ApiClients\Client\Github\Service\IteratePagesService;
12
use ApiClients\Foundation\Hydrator\Hydrator;
13
use function ApiClients\Tools\Rx\observableFromArray;
14
use React\Promise\PromiseInterface;
15
use function React\Promise\resolve;
16
17 View Code Duplication
final class PullRequestsHandler
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...
18
{
19
    /**
20
     * @var IteratePagesService
21
     */
22
    private $iteratePagesService;
23
24
    /**
25
     * @var Hydrator
26
     */
27
    private $hydrator;
28
29
    /**
30
     * @param IteratePagesService $iteratePagesService
31
     * @param Hydrator            $hydrator
32
     */
33
    public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
34
    {
35
        $this->iteratePagesService = $iteratePagesService;
36
        $this->hydrator = $hydrator;
37
    }
38
39
    /**
40
     * @param  PullRequestsCommand  $command
41
     * @return PromiseInterface
42
     */
43
    public function handle(PullRequestsCommand $command): PromiseInterface
44
    {
45
        return resolve(
46
            $this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/pulls')
47
                ->flatMap(function ($milestones) {
48
                    return observableFromArray($milestones);
49
                })->map(function ($milestone) {
50
                    return $this->hydrator->hydrate(PullRequestInterface::HYDRATE_CLASS, $milestone);
51
                })
52
        );
53
    }
54
}
55