Completed
Push — master ( 0cb84b...609616 )
by Maciej
07:36 queued 01:06
created

RepositoryAbstract::getReducers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Created by Maciej Paprocki for Bureau-VA.
4
 * Date: 17/02/2016
5
 * Project Name: MaciekPaprocki\WordpressGuzzle
6
 * Time: 10:46.
7
 */
8
namespace BureauVa\WordpressGuzzle\Repository;
9
10
use GuzzleHttp\Promise\Promise;
11
use GuzzleHttp\Client;
12
13
/**
14
 * Class AbstractRepository.
15
 */
16
abstract class RepositoryAbstract implements RepositoryInterface
17
{
18
    protected $client;
19
20
    /**
21
     * let us keep reference to our client.
22
     *
23
     * @return mixed
24
     */
25
    public function getClient()
26
    {
27
        return $this->client;
28
    }
29
30
    /**
31
     * Let us set our client reference taken from transaction.
32
     *
33
     * @param $client
34
     *
35
     * @return RepositoryAbstract
36
     */
37
    public function setClient(Client $client)
38
    {
39
        $this->client = $client;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @param $data
46
     *
47
     * @return string
48
     */
49
    public function createRequestQuery($data)
50
    {
51
        if (empty($data)) {
52
            return '';
53
        }
54
55
        return http_build_query([
56
            'filter' => $data,
57
        ]);
58
    }
59
60
    /**
61
     * @param $address
62
     * @param null|array|object $parameters
63
     *
64
     * @return Promise
65
     */
66
    public function createPromise($address, $parameters = null)
67
    {
68
        $encodedParam = $this->createRequestQuery($parameters);
69
        $query = $encodedParam ? '?'.$encodedParam : '';
70
71
        return $this->client->requestAsync('GET', $address.$query);
72
    }
73
}
74