Completed
Pull Request — master (#1)
by Martin
12:07
created

JsonFormat   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 23
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
	/**
12
	 * @param callable $handler
13
	 * @return callable
14
	 */
15
	public function setFormat(callable $handler): callable
16
	{
17
		return function (RequestInterface $request, array $options) use ($handler) {
18
			return $handler($request->withAddedHeader('Content-Type', 'application/json')->withAddedHeader('Accept', 'application/json'), $options);
19
		};
20
	}
21
22
	/**
23
	 * @param array $params
24
	 * @return string
25
	 */
26
	public function formatParams(array $params): string
27
	{
28
		return \GuzzleHttp\json_encode($params);
29
	}
30
}
31