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

ThreadControl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 57
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0

3 Methods

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