Token   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A list() 0 6 2
A get() 0 6 1
A create() 0 6 1
A delete() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\Rundeck\Api\Endpoints\Token;
5
6
use GuzzleHttp\Promise\PromiseInterface;
7
use Lookyman\Rundeck\Api\Client;
8
use GuzzleHttp\Psr7\Request;
9
10
class Token
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|null $user
27
	 * @return PromiseInterface
28
	 */
29
	public function list(string $user = null): PromiseInterface
30
	{
31
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
32
			new Request('GET', $this->client->getConfiguration()->getBaseUri() . '/tokens' . ($user ? sprintf('/%s', urlencode($user)) : ''))
33
		);
34
	}
35
36
	/**
37
	 * @param string $token
38
	 * @return PromiseInterface
39
	 */
40
	public function get(string $token): PromiseInterface
41
	{
42
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
43
			new Request('GET', $this->client->getConfiguration()->getBaseUri() . '/token/' . urlencode($token))
44
		);
45
	}
46
47
	/**
48
	 * @param string $user
49
	 * @return PromiseInterface
50
	 */
51
	public function create(string $user): PromiseInterface
52
	{
53
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
54
			new Request('POST', $this->client->getConfiguration()->getBaseUri() . '/tokens/' . urlencode($user))
55
		);
56
	}
57
58
	/**
59
	 * @param string $token
60
	 * @return PromiseInterface
61
	 */
62
	public function delete(string $token): PromiseInterface
63
	{
64
		return $this->client->getConfiguration()->getGuzzle()->sendAsync(
65
			new Request('DELETE', $this->client->getConfiguration()->getBaseUri() . '/token/' . urlencode($token))
66
		);
67
	}
68
}
69