ClientBuilder::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Softonic\GraphQL;
4
5
use League\OAuth2\Client\Provider\AbstractProvider as OAuth2Provider;
6
use Psr\Cache\CacheItemPoolInterface as Cache;
7
8
class ClientBuilder
9
{
10 4
    public static function build(string $endpoint, array $guzzleOptions = []): Client
11
    {
12 4
        $guzzleOptions = array_merge(['base_uri' => $endpoint], $guzzleOptions);
13
14 4
        return new \Softonic\GraphQL\Client(
15 4
            new \GuzzleHttp\Client($guzzleOptions),
16 4
            new \Softonic\GraphQL\ResponseBuilder()
17
        );
18
    }
19
20 4
    public static function buildWithOAuth2Provider(
21
        string $endpoint,
22
        OAuth2Provider $oauthProvider,
23
        array $tokenOptions,
24
        Cache $cache,
25
        array $guzzleOptions = []
26
    ): Client {
27 4
        $guzzleOptions = array_merge(['base_uri' => $endpoint], $guzzleOptions);
28
29
30 4
        return new \Softonic\GraphQL\Client(
31 4
            \Softonic\OAuth2\Guzzle\Middleware\ClientBuilder::build(
32 4
                $oauthProvider,
33 2
                $tokenOptions,
34 2
                $cache,
35 2
                $guzzleOptions
36
            ),
37 4
            new \Softonic\GraphQL\ResponseBuilder()
38
        );
39
    }
40
}
41