Passed
Pull Request — master (#62)
by Romain
02:05
created

ThreadControl::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Kerox\Messenger\Model;
4
5
use Kerox\Messenger\Helper\ValidatorTrait;
6
7
class ThreadControl implements \JsonSerializable
8
{
9
    use ValidatorTrait;
10
11
    /**
12
     * @var int
13
     */
14
    protected $recipientId;
15
16
    /**
17
     * @var null|int
18
     */
19
    protected $targetAppId;
20
21
    /**
22
     * @var null|string
23
     */
24
    protected $metadata;
25
26
    /**
27
     * PassThreadControl constructor.
28
     *
29
     * @param int      $recipientId
30
     * @param int|null $targetAppId
31
     */
32 2
    public function __construct(int $recipientId, int $targetAppId = null)
33
    {
34 2
        $this->recipientId = $recipientId;
35 2
        $this->targetAppId = $targetAppId;
36 2
    }
37
38
    /**
39
     * @param string $metadata
40
     */
41
    public function setMetadata(string $metadata): void
42
    {
43
        $this->isValidString($metadata, 1000);
44
45
        $this->metadata = $metadata;
46
    }
47
48
    /**
49
     * @return array
50
     */
51 2
    public function jsonSerialize(): array
52
    {
53
        $json = [
54
            'recipient'     => [
55 2
                'id' => $this->recipientId
56
            ],
57 2
            'target_app_id' => $this->targetAppId,
58 2
            'metadata'      => $this->metadata,
59
        ];
60
61 2
        return array_filter($json);
62
    }
63
}
64