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
44:41 queued 34:46
created

Repository::vars()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace WyriHaximus\Travis\Resource\Async;
5
6
use GuzzleHttp\Psr7\Request;
7
use React\Promise\PromiseInterface;
8
use Rx\Observable;
9
use Rx\ObservableInterface;
10
use Rx\React\Promise;
11
use WyriHaximus\Travis\Resource\Repository as BaseRepository;
12
use function React\Promise\reject;
13
use function React\Promise\resolve;
14
15
class Repository extends BaseRepository
16
{
17 View Code Duplication
    public function builds(): 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...
18
    {
19
        return Promise::toObservable(
20
            $this->getTransport()->request('repos/' . $this->slug() . '/builds')
21
        )->flatMap(function ($response) {
22
            return Observable::fromArray($response['builds']);
23
        })->map(function ($build) {
24
            return $this->getTransport()->getHydrator()->hydrate('Build', $build);
25
        });
26
    }
27
28 View Code Duplication
    public function build(int $id): PromiseInterface
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...
29
    {
30
        return $this->getTransport()->request(
31
            'repos/' . $this->slug() . '/builds/' . $id
32
        )->then(function ($response) {
33
            return resolve($this->getTransport()->getHydrator()->hydrate('Build', $response['build']));
34
        });
35
    }
36
37 View Code Duplication
    public function commits(): 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...
38
    {
39
        return Promise::toObservable(
40
            $this->getTransport()->request('repos/' . $this->slug() . '/builds')
41
        )->flatMap(function ($response) {
42
            return Observable::fromArray($response['commits']);
43
        })->map(function ($build) {
44
            return $this->getTransport()->getHydrator()->hydrate('Commit', $build);
45
        });
46
    }
47
48 View Code Duplication
    public function settings(): PromiseInterface
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...
49
    {
50
        return $this->getTransport()->request(
51
            'repos/' . $this->id() . '/settings'
52
        )->then(function ($response) {
53
            return resolve($this->getTransport()->getHydrator()->hydrate('Settings', $response['settings']));
54
        });
55
    }
56
57
    public function isActive(): PromiseInterface
58
    {
59
        return $this->getTransport()->request(
60
            'hooks'
61
        )->then(function ($response) {
62
            $active = false;
63
            foreach ($response['hooks'] as $hook) {
64
                if ($hook['id'] == $this->id()) {
65
                    $active = (bool)$hook['active'];
66
                    break;
67
                }
68
            }
69
70
            if ($active) {
71
                return resolve($active);
72
            }
73
74
            return reject($active);
75
        });
76
    }
77
78
    public function enable(): PromiseInterface
79
    {
80
        return $this->setActiveStatus(true);
81
    }
82
83
    public function disable(): PromiseInterface
84
    {
85
        return $this->setActiveStatus(false);
86
    }
87
88
    protected function setActiveStatus(bool $status)
89
    {
90
        return $this->getTransport()->requestPsr7(
91
            new Request(
92
                'PUT',
93
                $this->getTransport()->getBaseURL() . 'hooks/' . $this->id(),
94
                $this->getTransport()->getHeaders(),
95
                json_encode([
96
                    'hook' => [
97
                        'active' => $status,
98
                    ],
99
                ])
100
            )
101
        );
102
    }
103
104 View Code Duplication
    public function branches(): 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...
105
    {
106
        return Promise::toObservable(
107
            $this->getTransport()->request('repos/' . $this->slug() . '/branches')
108
        )->flatMap(function ($response) {
109
            return Observable::fromArray($response['branches']);
110
        })->map(function ($branch) {
111
            return $this->getTransport()->getHydrator()->hydrate('Branch', $branch);
112
        });
113
    }
114
115 View Code Duplication
    public function vars(): 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...
116
    {
117
        return Promise::toObservable(
118
            $this->getTransport()->request('/settings/env_vars?repository_id=' . $this->id())
119
        )->flatMap(function ($response) {
120
            return Observable::fromArray($response['env_vars']);
121
        })->map(function ($var) {
122
            return $this->getTransport()->getHydrator()->hydrate('EnvironmentVariable', $var);
123
        });
124
    }
125
126 View Code Duplication
    public function caches(): 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...
127
    {
128
        return Promise::toObservable(
129
            $this->getTransport()->request('repos/' . $this->slug() . '/caches')
130
        )->flatMap(function ($response) {
131
            return Observable::fromArray($response['caches']);
132
        })->map(function ($cache) {
133
            return $this->getTransport()->getHydrator()->hydrate('Cache', $cache);
134
        });
135
    }
136
137
    public function key(): PromiseInterface
138
    {
139
        return $this->getTransport()->request('repos/' . $this->slug() . '/key')->then(function ($key) {
140
            return resolve($this->getTransport()->getHydrator()->hydrate('RepositoryKey', $key));
141
        });
142
    }
143
}
144