TokenOptions   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 9 4
A jsonSerialize() 0 3 1
A __construct() 0 5 1
A toJson() 0 3 1
1
<?php
2
3
namespace SquareetLabs\LaravelOpenVidu;
4
5
use JsonSerializable;
6
7
/**
8
 * Class TokenOptions
9
 * @package SquareetLabs\LaravelOpenVidu
10
 */
11
class TokenOptions implements JsonSerializable
12
{
13
    /** @var  string */
14
    private $data;
15
    /** @var  string */
16
    private $role;
17
    /** @var  KurentoOptions */
18
    private $kurentoOptions;
19
20
21
    /**
22
     * TokenOptions constructor.
23
     * @param  string  $role
24
     * @param  string|null  $data
25
     * @param  KurentoOptions|null  $kurentoOptions
26
     */
27
    public function __construct(string $role, ?string $data = null, ?KurentoOptions $kurentoOptions = null)
28
    {
29
        $this->role = $role;
30
        $this->data = $data;
31
        $this->kurentoOptions = $kurentoOptions;
32
    }
33
34
    /**
35
     * Convert the model instance to JSON.
36
     *
37
     * @param  int  $options
38
     * @return string
39
     *
40
     */
41
    public function toJson($options = 0): string
42
    {
43
        return json_encode($this->jsonSerialize(), $options);
44
    }
45
46
    /**
47
     * Specify data which should be serialized to JSON
48
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
49
     * @return mixed data which can be serialized by <b>json_encode</b>,
50
     * which is a value of any type other than a resource.
51
     * @since 5.4.0
52
     */
53
    public function jsonSerialize()
54
    {
55
        return $this->toArray();
56
    }
57
58
    /**
59
     * Convert the model instance to an array.
60
     *
61
     * @return array
62
     */
63
    public function toArray(): array
64
    {
65
        $array = ['role' => $this->role, 'data' => $this->data];
66
        foreach ($array as $key => $value) {
67
            if (is_null($value) || $value == '') {
68
                unset($array[$key]);
69
            }
70
        }
71
        return $array;
72
    }
73
74
}
75