PatchRequestBuilder::build()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 4
nc 4
nop 6
1
<?php
2
3
namespace Knp\FriendlyContexts\Builder;
4
5
class PatchRequestBuilder extends AbstractRequestBuilder
6
{
7
    public function build($uri = null, array $queries = null, array $headers = null, array $postBody = null, $body = null, array $options = [])
8
    {
9
        parent::build($uri, $queries, $headers, $postBody, $body, $options);
10
11
        if (is_array($body)) {
12
            // format the body request to a corect x-www-form-urlencoded
13
            $body = $this->formatQueryString($body);
14
            // Set a defaut form content type
15
            $headers = $headers ?: [];
16
            $headers['Content-Type'] = 'application/x-www-form-urlencoded';
17
        }
18
19
        $resource = $queries ? sprintf('%s?%s', $uri, $this->formatQueryString($queries)) : $uri;
20
21
        return $this->getClient()->patch($resource, $headers, $body, $options);
22
    }
23
}
24