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

ThreadRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 5 1
A __construct() 0 5 1
A buildBody() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Request;
6
7
use Kerox\Messenger\Model\ThreadControl;
8
use Psr\Http\Message\RequestInterface;
9
use function GuzzleHttp\Psr7\stream_for;
10
11
class ThreadRequest extends AbstractRequest implements BodyRequestInterface
12
{
13
    /**
14
     * @var \Kerox\Messenger\Model\ThreadControl
15
     */
16
    protected $threadControl;
17
18
    /**
19
     * TagRequest constructor.
20
     *
21
     * @param string        $path
22
     * @param ThreadControl $threadControl
23
     */
24 6
    public function __construct(string $path, ThreadControl $threadControl)
25
    {
26 6
        parent::__construct($path);
27
28 6
        $this->threadControl = $threadControl;
29 6
    }
30
31
    /**
32
     * @param string $method
33
     *
34
     * @return RequestInterface
35
     */
36 6
    public function build(string $method = 'post'): RequestInterface
37
    {
38 6
        return $this->origin
39 6
            ->withMethod($method)
40 6
            ->withBody(stream_for($this->buildBody()));
41
    }
42
43
    /**
44
     * @return string
45
     */
46 6
    public function buildBody(): string
47
    {
48 6
        return json_encode($this->threadControl);
49
    }
50
}
51