Completed
Pull Request — master (#2)
by Josef
02:44
created

RequestFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createRequest() 0 12 3
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