Completed
Branch master (c90d5b)
by Riccardo
02:51
created

ClientBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
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 2
    public static function build(string $endpoint)
11
    {
12 2
        return new \Softonic\GraphQL\Client(
13 2
            new \GuzzleHttp\Client(['base_uri' => $endpoint]),
14 2
            new \Softonic\GraphQL\ResponseBuilder()
15
        );
16
    }
17
18 2
    public static function buildWithOAuth2Provider(
19
        string $endpoint,
20
        OAuth2Provider $oauthProvider,
21
        array $tokenOptions,
22
        Cache $cache
23
    ): Client {
24
        $guzzleOptions = [
25 2
            'base_uri' => $endpoint,
26
        ];
27
28 2
        return new \Softonic\GraphQL\Client(
29 2
            \Softonic\OAuth2\Guzzle\Middleware\ClientBuilder::build(
30 1
                $oauthProvider,
31 1
                $tokenOptions,
32 1
                $cache,
33 1
                $guzzleOptions
34
            ),
35 2
            new \Softonic\GraphQL\ResponseBuilder()
36
        );
37
    }
38
}
39