Service   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createRequest() 0 11 1
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