SignalProperties::session()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SquareetLabs\LaravelOpenVidu;
4
5
use JsonSerializable;
6
7
/**
8
 * Class SignalProperties
9
 * @package SquareetLabs\LaravelOpenVidu
10
 */
11
class SignalProperties implements JsonSerializable
12
{
13
    /** @var  string */
14
    private $session;
15
    /** @var  array */
16
    private $to;
17
    /** @var  string */
18
    private $type;
19
    /** @var  string */
20
    private $data;
21
22
    /**
23
     * SignalProperties constructor.
24
     * @param  string  $session
25
     * @param  string|null  $data
26
     * @param  string|null  $type
27
     * @param  array|null  $to
28
     */
29
    public function __construct(string $session, ?string $data = null, ?string $type = null, ?array $to = null)
30
    {
31
        $this->session = $session;
32
        $this->data = $data;
33
        $this->type = $type;
34
        $this->to = $to;
35
    }
36
37
    /**
38
     * Session name of the recording
39
     *
40
     * @return string
41
     */
42
    public function session()
43
    {
44
        return $this->session;
45
    }
46
47
    /**
48
     * Convert the model instance to JSON.
49
     *
50
     * @param  int  $options
51
     * @return string
52
     *
53
     */
54
    public function toJson($options = 0): string
55
    {
56
        return json_encode($this->jsonSerialize(), $options);
57
    }
58
59
    /**
60
     * Specify data which should be serialized to JSON
61
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
62
     * @return mixed data which can be serialized by <b>json_encode</b>,
63
     * which is a value of any type other than a resource.
64
     * @since 5.4.0
65
     */
66
    public function jsonSerialize()
67
    {
68
        return $this->toArray();
69
    }
70
71
    /**
72
     * Convert the model instance to an array.
73
     *
74
     * @return array
75
     */
76
    public function toArray(): array
77
    {
78
        $array = [
79
            'session' => $this->session,
80
            'data' => $this->data,
81
            'type' => $this->type,
82
            'to' => $this->to
83
        ];
84
        foreach ($array as $key => $value) {
85
            if (is_null($value) || $value == '') {
86
                unset($array[$key]);
87
            }
88
        }
89
        return $array;
90
    }
91
}
92