Completed
Pull Request — master (#127)
by Alexandr
04:00
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 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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