Completed
Pull Request — master (#127)
by Alexandr
05:03
created

UserRequest::buildHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Request;
6
7
use GuzzleHttp\Psr7\Uri;
8
use Psr\Http\Message\RequestInterface;
9
10
class UserRequest extends AbstractRequest implements QueryRequestInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $fields;
16
17
    /**
18
     * UserRequest constructor.
19
     *
20
     * @param string $path
21
     * @param array  $fields
22
     */
23 2
    public function __construct(string $path, array $fields)
24
    {
25 2
        parent::__construct($path);
26
27 2
        $this->fields = $fields;
28 2
    }
29
30
    /**
31
     * @param string $method
32
     *
33
     * @return RequestInterface
34
     */
35 2
    public function build(string $method = 'post'): RequestInterface
36
    {
37 2
        $uri = Uri::fromParts([
38 2
            'path' => $this->origin->getUri()->getPath(),
39 2
            'query' => $this->buildQuery(),
40
        ]);
41
42 2
        return $this->origin
43 2
            ->withUri($uri);
44
    }
45
46
    /**
47
     * @return string
48
     */
49 2
    public function buildQuery(): string
50
    {
51 2
        $fields = implode(',', $this->fields);
52
53
        $query = [
54 2
            'fields' => $fields,
55
        ];
56
57 2
        return http_build_query($query);
58
    }
59
}
60