TokenHeaderAuthentication   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A authenticate() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\Rundeck\Api\Authentication;
5
6
use Psr\Http\Message\RequestInterface;
7
8
class TokenHeaderAuthentication implements AuthenticationInterface
9
{
10
	/**
11
	 * @var string
12
	 */
13
	private $token;
14
15
	/**
16
	 * @param string $token
17
	 */
18
	public function __construct(string $token)
19
	{
20
		$this->token = $token;
21
	}
22
23
	/**
24
	 * @param callable $handler
25
	 * @return callable
26
	 */
27
	public function authenticate(callable $handler): callable
28
	{
29
		return function (RequestInterface $request, array $options) use ($handler) {
30
			return $handler($request->withAddedHeader('X-Rundeck-Auth-Token', $this->token), $options);
31
		};
32
	}
33
}
34