Completed
Push — master ( fa5ac7...eb2a5f )
by Jan
06:08
created

Client   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 52
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A send() 0 19 4
A getSoapClient() 0 8 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatEET;
4
5
use SlevomatEET\Cryptography\CryptographyService;
6
use SlevomatEET\Driver\DriverRequestFailedException;
7
use SlevomatEET\Driver\SoapClientDriver;
8
9
class Client
10
{
11
12
	/** @var \SlevomatEET\Cryptography\CryptographyService */
13
	private $cryptographyService;
14
15
	/** @var \SlevomatEET\Configuration */
16
	private $configuration;
17
18
	/** @var \SlevomatEET\SoapClient|null */
19
	private $soapClient;
20
21
	/** @var \SlevomatEET\Driver\SoapClientDriver */
22
	private $soapClientDriver;
23
24 3
	public function __construct(CryptographyService $cryptographyService, Configuration $configuration, SoapClientDriver $soapClientDriver)
25
	{
26 3
		$this->cryptographyService = $cryptographyService;
27 3
		$this->configuration = $configuration;
28 3
		$this->soapClientDriver = $soapClientDriver;
29 3
	}
30
31 3
	public function send(Receipt $receipt): EvidenceResponse
32
	{
33 3
		$request = new EvidenceRequest($receipt, $this->configuration, $this->cryptographyService);
34
35
		try {
36 3
			$response = $this->getSoapClient()->OdeslaniTrzby($request->getRequestData());
37 1
		} catch (DriverRequestFailedException $e) {
38 1
			throw new FailedRequestException($request, $e);
39
		} catch (\SoapFault $e) {
40
			throw new FailedRequestException($request, $e);
41
		}
42
43 2
		$response = new EvidenceResponse($response, $request);
44 2
		if (!$response->isValid()) {
45 1
			throw new InvalidResponseReceivedException($response);
46
		}
47
48 1
		return $response;
49
	}
50
51 3
	private function getSoapClient(): SoapClient
52
	{
53 3
		if ($this->soapClient === null) {
54 1
			$this->soapClient = new SoapClient($this->configuration->getEvidenceEnvironment()->getWsdlPath(), $this->cryptographyService, $this->soapClientDriver);
55
		}
56
57 3
		return $this->soapClient;
58
	}
59
60
}
61