ClientSoap   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 17
dl 0
loc 33
rs 10
c 2
b 0
f 2
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaderString() 0 7 1
A __construct() 0 9 1
A getClient() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Fns;
5
6
use Psr\SimpleCache\CacheInterface;
7
use SoapClient;
8
9
class ClientSoap
10
{
11
    private $storage;
12
    private $userToken;
13
    private $client;
14
    private $wsdl = 'https://openapi.nalog.ru:8090/open-api/ais3/KktService/0.1?wsdl';
15
16
    public function __construct(string $userToken, CacheInterface $cache, $debug = false)
17
    {
18
        $this->storage = $cache;
19
        $this->userToken = $userToken;
20
        $this->client = new SoapClient(
21
            $this->wsdl,
22
            [
23
                'trace' => $debug,
24
                'stream_context' => stream_context_create(['http' => ['header' => $this->getHeaderString()]])
25
            ]
26
        );
27
    }
28
29
    private function getHeaderString() : string
30
    {
31
        return sprintf(
32
            'FNS-OpenApi-Token:%s
33
                    FNS-OpenApi-UserToken:%s',
34
            $this->storage->get('temp_token'),
35
            $this->userToken
36
        );
37
    }
38
39
    public function getClient() : SoapClient
40
    {
41
        return $this->client;
42
    }
43
}
44