ClientSoap::getClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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