Guzzle6::setDefaultAuth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace CanalTP\AbstractGuzzle\Version;
4
5
use GuzzleHttp\Psr7\Request;
6
use GuzzleHttp\Client;
7
use CanalTP\AbstractGuzzle\Guzzle;
8
9
class Guzzle6 extends Guzzle
10
{
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
16
    /**
17
     * {@InheritDoc}
18
     */
19
    public function __construct($baseUri, $options = [])
20
    {
21
        $this->defaultOptions = array_merge(['base_uri' => $baseUri], $options);
22
23
        $this->client = new Client($this->defaultOptions);
24
    }
25
26
    public function setBaseUri($baseUri)
27
    {
28
        $this->setDefaultOptions(array_merge($this->defaultOptions, ['base_uri' => $baseUri]));
29
    }
30
31
    public function getBaseUri()
32
    {
33
        return (string) $this->client->getConfig('base_uri');
34
    }
35
36
    public function setDefaultOptions($options = [])
37
    {
38
        $this->__construct($this->getBaseUri(), $options);
39
    }
40
41
    public function getDefaultOptions()
42
    {
43
        return $this->client->getConfig();
44
    }
45
46
    public function setDefaultAuth($username, $password, $type = 'basic')
47
    {
48
        $this->setDefaultOptions(['auth' => [$username, $password, $type]]);
49
    }
50
51
    /**
52
     * @return Client
53
     */
54
    public function getClient()
55
    {
56
        return $this->client;
57
    }
58
59
    /**
60
     * @param Client $client
61
     *
62
     * @return self
63
     */
64
    public function setClient(Client $client)
65
    {
66
        $this->client = $client;
67
68
        return $this;
69
    }
70
71
    /**
72
     * {@InheritDoc}
73
     */
74
    public function send(Request $request)
75
    {
76
        return $this->client->send($request);
77
    }
78
}
79