Service::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Promopult\Dadata;
4
5
use Psr\Http\Client\ClientInterface;
6
7
abstract class Service implements RequestFactoryInterface
8
{
9
    protected ClientInterface $httpClient;
10
    protected CredentialsInterface $credentials;
11
12
    public function __construct(
13
        CredentialsInterface $credentials,
14
        ClientInterface $httpClient
15
    ) {
16
        $this->httpClient = $httpClient;
17
        $this->credentials = $credentials;
18
    }
19
20
    /**
21
     * Creates request with necessary headers & encoded body.
22
     */
23
    public function createRequest(
24
        string $method,
25
        string $uri,
26
        array $args = []
27
    ): \Psr\Http\Message\RequestInterface {
28
        return new \GuzzleHttp\Psr7\Request($method, $uri, [
29
            'Content-Type' => 'application/json',
30
            'Accept' => 'application/json',
31
            'Authorization' => 'Token ' . $this->credentials->getToken(),
32
            'X-Secret' => $this->credentials->getSecret()
33
        ], \json_encode($args));
34
    }
35
}
36