AbstractRequestBuilder::formatQueryString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Builder;
4
5
use Guzzle\Http\ClientInterface;
6
7
abstract class AbstractRequestBuilder implements RequestBuilderInterface
8
{
9
    private $client;
10
11
    public function build($uri = null, array $queries = null, array $headers = null, array $postBody = null, $body = null, array $options = [])
12
    {
13
        if (null === $this->client) {
14
            throw new \RuntimeException('You must precised a valid client before build a request');
15
        }
16
    }
17
18
    public function setClient(ClientInterface $client = null)
19
    {
20
        $this->client = $client;
21
    }
22
23
    /**
24
     * Return a clone of guzzle client if available.
25
     *
26
     * This is useful to ensure executions isolation.
27
     *
28
     * @return ClientInterface|null
29
     */
30
    public function getClient()
31
    {
32
        if ($this->client instanceof ClientInterface) {
33
            return clone $this->client;
34
        }
35
    }
36
37
    protected function formatQueryString(array $queries = null)
38
    {
39
        if (null === $queries) {
40
            return;
41
        }
42
43
        return http_build_query($queries);
44
    }
45
}
46