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

UserRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A buildQuery() 0 9 1
A build() 0 9 1
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