Client   A
last analyzed

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