Completed
Push — master ( 1be44d...449b6f )
by Artem
02:21
created

HttpFactory::createHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 16
ccs 0
cts 13
cp 0
crap 2
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
    public static function createHttpClient(Params $params): HttpClient
16
    {
17
        $baseUri = "{$params->getHost()}:{$params->getPort()}/";
18
19
        // Communications through JSON
20
        $headers = [
21
            'Accept' => 'application/json',
22
            'Content-Type' => 'application/json',
23
        ];
24
25
        return new \GuzzleHttp\Client([
26
            'base_uri' => $baseUri,
27
            'defaults' => [
28
                'headers' => $headers,
29
            ],
30
            'http_errors' => false,
31
        ]);
32
    }
33
}
34