Completed
Pull Request — master (#1)
by Jean-Baptiste
05:12
created

Guzzle6::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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
     * @var defaultConfig
18
     */
19
    private $config;
20
21
    /**
22
     * {@InheritDoc}
23
     */
24
    /**
25
     * Guzzle6 accept an array of constructor parameters.
26
     *
27
     * Here's an example of creating a client using a base_uri and an array of
28
     * default request options to apply to each request:
29
     *
30
     *     $client = new Client([
31
     *         'base_uri'        => 'http://www.foo.com/1.0/',
32
     *         'timeout'         => 0,
33
     *         'allow_redirects' => false,
34
     *         'proxy'           => '192.168.16.1:10',
35
     *         'auth' => ['user', 'password']
36
     *     ]);
37
     * @param array $config
38
     */
39
    public function __construct($config)
40
    {
41
        parent::__construct($config);
42
43
        $this->config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type array is incompatible with the declared type object<CanalTP\AbstractG...\Version\defaultConfig> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
        $this->setClient(new Client($config));
45
    }
46
47
    /**
48
     * @return defaultConfig
49
     */
50
    public function getConfig()
51
    {
52
        return $this->config;
53
    }
54
55
    /**
56
     * @param defaultConfig $config
57
     */
58
    public function setConfig($config)
59
    {
60
        $this->config = $config;
61
    }
62
63
    /**
64
     * @return Client
65
     */
66
    public function getClient()
67
    {
68
        return $this->client;
69
    }
70
71
    /**
72
     * @param Client $client
73
     *
74
     * @return self
75
     */
76
    public function setClient(Client $client)
77
    {
78
        $this->client = $client;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param Request $request
85
     * @return mixed|\Psr\Http\Message\ResponseInterface
86
     */
87
    public function send(Request $request)
88
    {
89
        return $this->client->send($request);
90
    }
91
92
    /**
93
     * allow to use client's magic method
94
     *
95
     * @param $method
96
     * @param $args
97
     */
98
    public function __call($method, $args)
99
    {
100
        if (count($args) < 1) {
101
            throw new \InvalidArgumentException('Magic request methods require a URI and optional options array');
102
        }
103
104
        $uri = $args[0];
105
        $opts = isset($args[1]) ? $args[1] : [];
106
107
        return $this->client->$method($uri, $opts);
108
    }
109
}
110