Completed
Push — master ( e7e23d...4acac6 )
by Andrea Marco
22:12 queued 12:16
created

GuzzleAdapter::getQueryByOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace Cerbero\FluentApi\Clients;
4
5
use Closure;
6
use GuzzleHttp\ClientInterface as Guzzle;
7
use Guzzle\Http\Client;
8
9
/**
10
 * Adapter for the Guzzle HTTP client.
11
 *
12
 * @author    Andrea Marco Sartori
13
 */
14
class GuzzleAdapter implements AsyncClientInterface
15
{
16
    /**
17
     * The Guzzle client.
18
     *
19
     * @author  Andrea Marco Sartori
20
     * @var     GuzzleHttp\ClientInterface
21
     */
22
    protected $client;
23
24
    /**
25
     * Set the dependencies.
26
     *
27
     * @author    Andrea Marco Sartori
28
     * @param    GuzzleHttp\ClientInterface    $client
29
     * @return    void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
     */
31
    public function __construct(Guzzle $client)
32
    {
33
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type object<GuzzleHttp\ClientInterface> is incompatible with the declared type object<Cerbero\FluentApi...leHttp\ClientInterface> of property $client.

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...
34
    }
35
36
    /**
37
     * Process the HTTP request synchronously.
38
     *
39
     * @author    Andrea Marco Sartori
40
     * @param    string    $verb
41
     * @param    string    $endpoint
42
     * @param    array    $options
43
     * @return    mixed
44
     */
45
    public function call($verb, $endpoint, array $options = [])
46
    {
47
        return $this->client->request($verb, $endpoint, $options);
48
    }
49
50
    /**
51
     * Process the HTTP request asynchronously.
52
     *
53
     * @author    Andrea Marco Sartori
54
     * @param    string    $verb
55
     * @param    string    $endpoint
56
     * @param    array    $options
57
     * @param    Closure    $success
58
     * @param    Closure|null    $failure
59
     * @return    mixed
60
     */
61
    public function then($verb, $endpoint, array $options = [], Closure $success, Closure $failure = null)
62
    {
63
        return $this->client->requestAsync($verb, $endpoint, $options)->then($success, $failure);
64
    }
65
66
    /**
67
     * Retrieve the query string parameters from the given options.
68
     *
69
     * @param    array    $options
70
     * @return    array
71
     */
72
    public function getQueryByOptions(array $options)
73
    {
74
        return isset($options['query']) ? $options['query'] : [];
75
    }
76
}
77