Completed
Push — master ( 449b6f...296164 )
by Artem
02:13
created

HttpFactory::createHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 16
ccs 6
cts 6
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Gockets\Factory;
4
5
use Gockets\Model\Params;
6
use GuzzleHttp\Client as HttpClient;
7
8
/**
9
 * Http Client Factory
10
 *
11
 * Responsible for creating instance of HTTP client.
12
 */
13
class HttpFactory
14
{
15 1
    public static function createHttpClient(Params $params): HttpClient
16
    {
17 1
        $baseUri = "{$params->getHost()}:{$params->getPort()}/";
18
19
        // Communications through JSON
20
        $headers = [
21 1
            'Accept' => 'application/json',
22
            'Content-Type' => 'application/json',
23
        ];
24
25 1
        return new \GuzzleHttp\Client([
26 1
            'base_uri' => $baseUri,
27
            'defaults' => [
28 1
                'headers' => $headers,
29
            ],
30
            'http_errors' => false,
31
        ]);
32
    }
33
}
34