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

RequestFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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