Completed
Push — master ( dbe861...0207b1 )
by Lukáš
32:10 queued 12:27
created

Execution   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 12.05 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 10
loc 83
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A info() 0 6 1
A delete() 0 6 1
A bulkDelete() 0 6 1
A state() 0 6 1
A abort() 10 10 1
A output() 0 4 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 Lookyman\Rundeck\Api\Endpoints\Execution;
5
6
use GuzzleHttp\Promise\PromiseInterface;
7
use GuzzleHttp\Psr7\Request;
8
use Lookyman\Rundeck\Api\Client;
9
10
class Execution
11
{
12
	/**
13
	 * @var Client
14
	 */
15
	private $client;
16
17
	/**
18
	 * @param Client $client
19
	 */
20
	public function __construct(Client $client)
21
	{
22
		$this->client = $client;
23
	}
24
25
	/**
26
	 * @param string $id
27
	 * @return PromiseInterface
28
	 */
29
	public function info(string $id): PromiseInterface
30
	{
31
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
32
			new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s', urlencode($id)))
33
		);
34
	}
35
36
	/**
37
	 * @param string $id
38
	 * @return PromiseInterface
39
	 */
40
	public function delete(string $id): PromiseInterface
41
	{
42
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
43
			new Request('DELETE', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s', urlencode($id)))
44
		);
45
	}
46
47
	/**
48
	 * @param int[] $ids
49
	 * @return PromiseInterface
50
	 */
51
	public function bulkDelete(array $ids): PromiseInterface
52
	{
53
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
54
			new Request('POST', $this->client->getConfiguration()->getBaseUri() . '/executions/delete', [], $this->client->getConfiguration()->getFormat()->formatParams(['ids' => $ids]))
55
		);
56
	}
57
58
	/**
59
	 * @param string $id
60
	 * @return PromiseInterface
61
	 */
62
	public function state(string $id): PromiseInterface
63
	{
64
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
65
			new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/state', urlencode($id)))
66
		);
67
	}
68
69
	/**
70
	 * @param string $id
71
	 * @param array $params
72
	 * @return PromiseInterface
73
	 */
74 View Code Duplication
	public function abort(string $id, array $params = []): 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...
75
	{
76
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
77
			new Request(
78
				'GET',
79
				$this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/abort', urlencode($id)),
80
				[],
81
				$this->client->getConfiguration()->getFormat()->formatParams($params))
82
		);
83
	}
84
85
	/**
86
	 * @return Output
87
	 */
88
	public function output(): Output
89
	{
90
		return new Output($this->client);
91
	}
92
}
93