StreamClient::buildClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Ytake\KsqlClient;
5
6
use GuzzleHttp\Client as GuzzleClient;
7
use GuzzleHttp\ClientInterface;
8
use Ytake\KsqlClient\Exception\StreamQueryException;
9
use Ytake\KsqlClient\Query\AbstractStreamQuery;
10
use Ytake\KsqlClient\Query\QueryInterface;
11
use Ytake\KsqlClient\Result\AbstractResult;
12
13
/**
14
 * Class StreamClient
15
 */
16
final class StreamClient extends RestClient
17
{
18
    /**
19
     * build GuzzleHttp Client
20
     *
21
     * @return ClientInterface
22
     */
23
    protected function buildClient(): ClientInterface
24
    {
25
        return new GuzzleClient([
26
            'headers' => [
27
                'User-Agent' => self::USER_AGENT,
28
                'Accept'     => 'application/json',
29
            ],
30
            'stream'  => true,
31
        ]);
32
    }
33
34
    /**
35
     * @param QueryInterface $query
36
     * @param int            $timeout
37
     * @param bool           $debug
38
     *
39
     * @return AbstractResult
40
     * @throws \GuzzleHttp\Exception\GuzzleException
41
     */
42
    public function requestQuery(
43
        QueryInterface $query,
44
        int $timeout = 500000,
45
        bool $debug = false
46
    ): AbstractResult {
47
        if ($query instanceof AbstractStreamQuery) {
48
            return parent::requestQuery($query, $timeout, $debug);
49
        }
50
        throw new StreamQueryException(
51
            "You must extends " . AbstractStreamQuery::class
52
        );
53
    }
54
}
55