1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace WyriHaximus\Travis\Resource\Async; |
5
|
|
|
|
6
|
|
|
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand; |
7
|
|
|
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
use React\Promise\PromiseInterface; |
10
|
|
|
use Rx\Observable; |
11
|
|
|
use Rx\ObservableInterface; |
12
|
|
|
use Rx\React\Promise; |
13
|
|
|
use WyriHaximus\Travis\Resource\Build as BaseBuild; |
14
|
|
|
use function React\Promise\resolve; |
15
|
|
|
|
16
|
|
|
class Build extends BaseBuild |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @return ObservableInterface |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function jobs(): ObservableInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
return Promise::toObservable( |
24
|
|
|
$this->handleCommand(new SimpleRequestCommand('builds/' . $this->id())) |
25
|
|
|
)->flatMap(function ($response) { |
26
|
|
|
return Observable::fromArray($response->getBody()->getJson()['jobs']); |
27
|
|
|
})->flatMap(function ($job) { |
28
|
|
|
return Promise::toObservable($this->handleCommand(new HydrateCommand('Job', $job))); |
29
|
|
|
}); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param int $id |
34
|
|
|
* @return PromiseInterface |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function job(int $id): PromiseInterface |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
return $this->handleCommand( |
39
|
|
|
new SimpleRequestCommand('jobs/' . $id) |
40
|
|
|
)->then(function (ResponseInterface $response) { |
41
|
|
|
return $this->handleCommand( |
42
|
|
|
new HydrateCommand('Job', $response->getBody()->getJson()['job']) |
|
|
|
|
43
|
|
|
); |
44
|
|
|
}); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function refresh(): PromiseInterface |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
return $this->handleCommand( |
50
|
|
|
new SimpleRequestCommand('builds/' . $this->id) |
51
|
|
|
)->then(function (ResponseInterface $response) { |
52
|
|
|
return resolve($this->handleCommand( |
53
|
|
|
new SimpleRequestCommand('Build', $response->getBody()->getJson()['build']) |
|
|
|
|
54
|
|
|
)); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.