ThreadControl   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 64
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 4 1
A setMetadata() 0 6 1
A toArray() 0 12 1
A jsonSerialize() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model;
6
7
use Kerox\Messenger\Helper\ValidatorTrait;
8
9
class ThreadControl implements \JsonSerializable
10
{
11
    use ValidatorTrait;
12
13
    /**
14
     * @var int
15
     */
16
    protected $recipientId;
17
18
    /**
19
     * @var int|null
20
     */
21
    protected $targetAppId;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $metadata;
27
28
    /**
29
     * PassThreadControl constructor.
30
     */
31 3
    public function __construct(int $recipientId, ?int $targetAppId = null)
32
    {
33 3
        $this->recipientId = $recipientId;
34 3
        $this->targetAppId = $targetAppId;
35 3
    }
36
37
    /**
38
     * @return \Kerox\Messenger\Model\ThreadControl
39
     */
40 3
    public static function create(int $recipientId, ?int $targetAppId = null): self
41
    {
42 3
        return new self($recipientId, $targetAppId);
43
    }
44
45
    /**
46
     * @throws \Exception
47
     */
48 3
    public function setMetadata(string $metadata): void
49
    {
50 3
        $this->isValidString($metadata, 1000);
51
52 3
        $this->metadata = $metadata;
53 3
    }
54
55 3
    public function toArray(): array
56
    {
57
        $array = [
58
            'recipient' => [
59 3
                'id' => $this->recipientId,
60
            ],
61 3
            'target_app_id' => $this->targetAppId,
62 3
            'metadata' => $this->metadata,
63
        ];
64
65 3
        return array_filter($array);
66
    }
67
68 3
    public function jsonSerialize(): array
69
    {
70 3
        return $this->toArray();
71
    }
72
}
73