Completed
Push — master ( b8acd8...13d185 )
by Maciej
14:05
created

RepositoryAbstract::setClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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