Completed
Push — master ( f82605...39b80f )
by Lukáš
36:49 queued 30:33
created

JsonFormat   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setFormat() 0 6 1
A formatParams() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\Rundeck\Api\Format;
5
6
use Psr\Http\Message\RequestInterface;
7
8
class JsonFormat implements FormatInterface
9
{
10
	/**
11
	 * @param callable $handler
12
	 * @return callable
13
	 */
14
	public function setFormat(callable $handler): callable
15
	{
16
		return function (RequestInterface $request, array $options) use ($handler) {
17
			return $handler($request->withAddedHeader('Content-Type', 'application/json')->withAddedHeader('Accept', 'application/json'), $options);
18
		};
19
	}
20
21
	/**
22
	 * @param array $params
23
	 * @return string
24
	 */
25
	public function formatParams(array $params): string
26
	{
27
		return \GuzzleHttp\json_encode($params);
28
	}
29
}
30