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

Output::output()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 11
nc 4
nop 4
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 Output
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
	 * @param string|null $node
28
	 * @param string|null $step
29
	 * @param array $params
30
	 * @return PromiseInterface
31
	 */
32 View Code Duplication
	public function output(string $id, string $node = null, string $step = null, 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...
33
	{
34
		if ($node && $step) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $node of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $step of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
35
			$path = sprintf('/execution/%s/output/node/%s/step/%s', urlencode($id), urlencode($node), urlencode($step));
36
		} elseif ($node && !$step) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $node of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $step of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
37
			$path = sprintf('/execution/%s/output/node/%s', urlencode($id), urlencode($node));
38
		} elseif (!$node && $step) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $node of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $step of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
39
			$path = sprintf('/execution/%s/output/step/%s', urlencode($id), urlencode($step));
40
		} else {
41
			$path = sprintf('/execution/%s/output', urlencode($id));
42
		}
43
44
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
45
			new Request('GET', $this->client->getConfiguration()->getBaseUri() . $path, [], $this->client->getConfiguration()->getFormat()->formatParams($params))
46
		);
47
	}
48
49
	/**
50
	 * @param string $id
51
	 * @param bool $stateOnly
52
	 * @return PromiseInterface
53
	 */
54
	public function outputWithState(string $id, bool $stateOnly = false): PromiseInterface
55
	{
56
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
57
			new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/output/state%s', urlencode($id), $stateOnly ? '?stateOnly=true' : ''))
58
		);
59
	}
60
}
61