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

JsonFormat::formatParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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