Completed
Pull Request — master (#127)
by Alexandr
04:00
created

ThreadRequest::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 3
     * @param ThreadControl $threadControl
23
     */
24 3
    public function __construct(string $path, ThreadControl $threadControl)
25
    {
26 3
        parent::__construct($path);
27 3
28
        $this->threadControl = $threadControl;
29
    }
30
31
    /**
32 3
     * @param string|null $method
33
     *
34
     * @return RequestInterface
35 3
     */
36
    public function build(?string $method = null): RequestInterface
37
    {
38
        return $this->origin
39
            ->withMethod('post')
40
            ->withBody(stream_for($this->buildBody()));
41
    }
42 3
43
    /**
44 3
     * @return string
45
     */
46
    public function buildBody(): string
47
    {
48
        return json_encode($this->threadControl);
49
    }
50
}
51