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 (#33)
by Cees-Jan
27:08 queued 17:56
created

AsyncClient   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 68.33 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 41
loc 60
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 15 3
A repository() 0 6 1
A hooks() 10 10 1
A accounts() 10 10 1
A broadcasts() 10 10 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
2
declare(strict_types=1);
3
4
namespace WyriHaximus\Travis;
5
6
use React\EventLoop\LoopInterface;
7
use React\Promise\PromiseInterface;
8
use Rx\Observable;
9
use Rx\ObservableInterface;
10
use Rx\React\Promise;
11
use WyriHaximus\ApiClient\Transport\Client as Transport;
12
use WyriHaximus\ApiClient\Transport\Factory;
13
use function React\Promise\resolve;
14
15
class AsyncClient
16
{
17
    protected $transport;
18
19
    public function __construct(LoopInterface $loop, string $token = '', Transport $transport = null)
20
    {
21 View Code Duplication
        if (!($transport instanceof Transport)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
22
            $options = [
23
                'resource_namespace' => 'Async',
24
            ] + ApiSettings::TRANSPORT_OPTIONS;
25
26
            if ($token !== '') {
27
                $options['headers']['Authorization'] = 'token ' . $token;
28
            }
29
30
            $transport = Factory::create($loop, $options);
31
        }
32
        $this->transport = $transport;
33
    }
34
35
    public function repository(string $repository): PromiseInterface
36
    {
37
        return $this->transport->request('repos/' . $repository)->then(function ($json) {
38
            return resolve($this->transport->getHydrator()->hydrate('Repository', $json['repo']));
39
        });
40
    }
41
42 View Code Duplication
    public function hooks(): ObservableInterface
0 ignored issues
show
Duplication introduced by
This method 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...
43
    {
44
        return Promise::toObservable(
45
            $this->transport->request('hooks')
46
        )->flatMap(function ($response) {
47
            return Observable::fromArray($response['hooks']);
48
        })->map(function ($hook) {
49
            return $this->transport->getHydrator()->hydrate('Hook', $hook);
50
        });
51
    }
52
53 View Code Duplication
    public function accounts(): ObservableInterface
0 ignored issues
show
Duplication introduced by
This method 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...
54
    {
55
        return Promise::toObservable(
56
            $this->transport->request('accounts')
57
        )->flatMap(function ($response) {
58
            return Observable::fromArray($response['accounts']);
59
        })->map(function ($account) {
60
            return $this->transport->getHydrator()->hydrate('Account', $account);
61
        });
62
    }
63
64 View Code Duplication
    public function broadcasts(): ObservableInterface
0 ignored issues
show
Duplication introduced by
This method 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...
65
    {
66
        return Promise::toObservable(
67
            $this->transport->request('broadcasts')
68
        )->flatMap(function ($response) {
69
            return Observable::fromArray($response['broadcasts']);
70
        })->map(function ($broadcast) {
71
            return $this->getTransport()->getHydrator()->hydrate('Broadcast', $broadcast);
0 ignored issues
show
Bug introduced by
The method getTransport() does not seem to exist on object<WyriHaximus\Travis\AsyncClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
        });
73
    }
74
}
75