PhraseappHttpClient   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 15
dl 0
loc 58
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A createWithToken() 0 5 1
A createWithBasicAuth() 0 5 1
1
<?php
2
3
namespace VictorAvelar\Phraseapp;
4
5
use GuzzleHttp\Client;
6
7
class PhraseappHttpClient extends Client
8
{
9
    /**
10
     * API main URL.
11
     *
12
     * @var string
13
     */
14
    const BASE_PATH = "https://api.phraseapp.com/v2/";
15
16
    /**
17
     * Timeout to wait for a response.
18
     *
19
     * @var int
20
     */
21
    const CLIENT_TIMEOUT = 10;
22
23
    /**
24
     * PhraseappHttpClient constructor.
25
     * @param array  $configuration
26
     */
27 12
    public function __construct(array $configuration = [])
28
    {
29 12
        $configuration = array_merge_recursive([
30 12
                'base_uri' => self::BASE_PATH,
31 12
                'timeout' => self::CLIENT_TIMEOUT,
32
                'allow_redirects' => false,
33
                'headers' => [
34
                    'Accept' => 'application/json'
35
                ]
36 8
            ], $configuration);
37 12
        parent::__construct($configuration);
38 12
    }
39
40
    /**
41
     * Create a new instance using the config defaults and the Oauth2 token auth strategy.
42
     *
43
     * @param string $phraseappToken
44
     * @return PhraseappHttpClient
45
     */
46 3
    public static function createWithToken(string $phraseappToken)
47
    {
48 3
        $config = ['headers' => ['Authorization' => "token $phraseappToken"]];
49
50 3
        return new self($config);
51
    }
52
53
    /**
54
     * Create a new instance using the config defaults and user:password auth strategy.
55
     *
56
     * @param string $user
57
     * @param string $password
58
     * @return PhraseappHttpClient
59
     */
60 3
    public static function createWithBasicAuth(string $user, string $password)
61
    {
62 3
        $config = ['headers' => ['Authorization' => [$user, $password]]];
63
64 3
        return new self($config);
65
    }
66
}
67