Completed
Push — refactoring ( f58f49 )
by Josef
45:19
created

RequestFactory::createRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace HelePartnerSyncApi\Request;
4
5
use HelePartnerSyncApi\Client;
6
7
class RequestFactory
8
{
9
10
	/**
11
	 * @var string
12
	 */
13
	private $secret;
14
15
	/**
16
	 * @param string $secret
17
	 */
18
	public function __construct($secret)
19
	{
20
		$this->secret = $secret;
21
	}
22
23
	/**
24
	 * @param string $body
25
	 * @param string[] $headers
26
	 * @return Request
27
	 */
28
	public function createRequest($body, array $headers)
29
	{
30
		if (!isset($headers[Client::HEADER_SIGNATURE])) {
31
			throw new RequestException(sprintf('Missing %s header in HTTP request', Client::HEADER_SIGNATURE));
32
		}
33
34
		if (!isset($headers[Client::HEADER_SIGNATURE_ALGORITHM])) {
35
			throw new RequestException(sprintf('Missing %s header in HTTP request', Client::HEADER_SIGNATURE_ALGORITHM));
36
		}
37
38
		return new Request($body, $this->secret, $headers[Client::HEADER_SIGNATURE], $headers[Client::HEADER_SIGNATURE_ALGORITHM]);
39
	}
40
41
}
42