1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace WyriHaximus\Travis\Resource\Async; |
5
|
|
|
|
6
|
|
|
use React\Promise\PromiseInterface; |
7
|
|
|
use Rx\Observable; |
8
|
|
|
use Rx\ObservableInterface; |
9
|
|
|
use Rx\React\Promise; |
10
|
|
|
use WyriHaximus\Travis\Resource\Repository as BaseRepository; |
11
|
|
|
use function React\Promise\resolve; |
12
|
|
|
|
13
|
|
|
class Repository extends BaseRepository |
14
|
|
|
{ |
15
|
|
View Code Duplication |
public function builds(): ObservableInterface |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
return Promise::toObservable( |
18
|
|
|
$this->getTransport()->request('repos/' . $this->slug() . '/builds') |
19
|
|
|
)->flatMap(function ($response) { |
20
|
|
|
return Observable::fromArray($response['builds']); |
21
|
|
|
})->map(function ($build) { |
22
|
|
|
return $this->getTransport()->getHydrator()->hydrate('Build', $build); |
23
|
|
|
}); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function build(int $id): PromiseInterface |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
return $this->getTransport()->request( |
29
|
|
|
'repos/' . $this->slug() . '/builds/' . $id |
30
|
|
|
)->then(function ($response) { |
31
|
|
|
return resolve($this->getTransport()->getHydrator()->hydrate('Build', $response['build'])); |
32
|
|
|
}); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function commits(): ObservableInterface |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
return Promise::toObservable( |
38
|
|
|
$this->getTransport()->request('repos/' . $this->slug() . '/builds') |
39
|
|
|
)->flatMap(function ($response) { |
40
|
|
|
return Observable::fromArray($response['commits']); |
41
|
|
|
})->map(function ($build) { |
42
|
|
|
return $this->getTransport()->getHydrator()->hydrate('Commit', $build); |
43
|
|
|
}); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function refresh(): PromiseInterface |
47
|
|
|
{ |
48
|
|
|
return $this->getTransport()->request('repos/' . $this->slug)->then(function ($json) { |
49
|
|
|
return resolve($this->getTransport()->getHydrator()->hydrate('Repository', $json['repo'])); |
50
|
|
|
}); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
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.