Passed
Push — master ( 77f1b4...a6165e )
by Jacobo
03:07
created

Publisher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 9
dl 0
loc 11
rs 9.9666
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace SquareetLabs\LaravelOpenVidu;
4
5
use JsonSerializable;
6
7
/**
8
 * Class Connection
9
 * @package SquareetLabs\LaravelOpenVidu
10
 * This is a backend representation of a published media stream (see [OpenVidu Browser Stream class](/api/openvidu-browser/classes/stream.html)
11
 * {@see Connection::getPublishers()}
12
 */
13
class Publisher implements JsonSerializable
14
{
15
16
    /** @var  string
17
     * Unique identifier of the Stream {@link https://api/openvidu-browser/classes/stream.html} associated to this Publisher.
18
     * Each Publisher is paired with only one Stream, so you can identify each Publisher by its
19
     * Stream.streamId {@link https://api/openvidu-browser/classes/stream.html#streamid}
20
     */
21
    private $streamId;
22
23
    /** @var int
24
     * Timestamp when this connection was established, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC)
25
     */
26
    private $createdAt;
27
28
29
    /** @var bool
30
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html} object in OpenVidu Browser library to find out more
31
     */
32
    private $hasAudio;
33
34
35
    /** @var  bool
36
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html}object in OpenVidu Browser library to find out more
37
     */
38
    private $hasVideo;
39
40
41
    /** @var  bool
42
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html} object in OpenVidu Browser library to find out more
43
     */
44
    private $audioActive;
45
46
47
    /** @var  bool
48
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html} object in OpenVidu Browser library to find out more
49
     */
50
    private $videoActive;
51
52
53
    /**
54
     * @var int
55
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html} object in OpenVidu Browser library to find out more
56
     */
57
    private $frameRate;
58
59
60
    /**
61
     * @var string
62
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html} object in OpenVidu Browser library to find out more
63
     */
64
    private $typeOfVideo;
65
66
67
    /**
68
     * var string
69
     * See properties of Stream {@link https://api/openvidu-browser/classes/stream.html} object in OpenVidu Browser library to find out more
70
     */
71
    private $videoDimensions;
72
73
74
    /**
75
     * Publisher constructor.
76
     * @param string $streamId
77
     * @param int $createdAt
78
     * @param bool $hasAudio
79
     * @param bool $hasVideo
80
     * @param bool $audioActive
81
     * @param bool $videoActive
82
     * @param int $frameRate
83
     * @param string $typeOfVideo
84
     * @param string $videoDimensions
85
     */
86
    public function __construct(string $streamId, int $createdAt, bool $hasAudio, bool $hasVideo, bool $audioActive, bool $videoActive, int $frameRate, string $typeOfVideo, string $videoDimensions)
87
    {
88
        $this->streamId = $streamId;
89
        $this->createdAt = $createdAt;
90
        $this->hasAudio = $hasAudio;
91
        $this->hasVideo = $hasVideo;
92
        $this->audioActive = $audioActive;
93
        $this->videoActive = $videoActive;
94
        $this->frameRate = $frameRate;
95
        $this->typeOfVideo = $typeOfVideo;
96
        $this->videoDimensions = $videoDimensions;
97
98
    }
99
100
    /**
101
     * @return int
102
     */
103
    public function getCreatedAt(): int
104
    {
105
        return $this->createdAt;
106
    }
107
108
    /**
109
     * @return bool
110
     */
111
    public function hasAudio(): bool
112
    {
113
        return $this->hasAudio;
114
    }
115
116
    /**
117
     * @return bool
118
     */
119
    public function hasVideo(): bool
120
    {
121
        return $this->hasVideo;
122
    }
123
124
    /**
125
     * @return bool
126
     */
127
    public function isAudioActive(): bool
128
    {
129
        return $this->audioActive;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function isVideoActive(): bool
136
    {
137
        return $this->videoActive;
138
    }
139
140
    /**
141
     * @return int
142
     */
143
    public function getFrameRate(): int
144
    {
145
        return $this->frameRate;
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public function getTypeOfVideo(): string
152
    {
153
        return $this->typeOfVideo;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getVideoDimensions(): string
160
    {
161
        return $this->videoDimensions;
162
    }
163
164
    public function __toString(): string
165
    {
166
        return $this->getStreamId();
167
    }
168
169
    /**
170
     * @return string
171
     */
172
    public function getStreamId(): string
173
    {
174
        return $this->streamId;
175
    }
176
177
    /**
178
     * Convert the model instance to JSON.
179
     *
180
     * @param int $options
181
     * @return string
182
     *
183
     */
184
    public function toJson($options = 0): string
185
    {
186
        $json = json_encode($this->jsonSerialize(), $options);
187
        return $json;
188
    }
189
190
    /**
191
     * Specify data which should be serialized to JSON
192
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
193
     * @return mixed data which can be serialized by <b>json_encode</b>,
194
     * which is a value of any type other than a resource.
195
     * @since 5.4.0
196
     */
197
    public function jsonSerialize()
198
    {
199
        return $this->toArray();
200
    }
201
202
    /**
203
     * Convert the model instance to an array.
204
     *
205
     * @return array
206
     */
207
    public function toArray(): array
208
    {
209
        $array = ['streamId' => $this->streamId,
210
            'createdAt' => $this->createdAt,
211
            'hasAudio' => $this->hasAudio,
212
            'hasVideo' => $this->hasVideo,
213
            'audioActive' => $this->audioActive,
214
            'videoActive' => $this->videoActive,
215
            'frameRate' => $this->frameRate,
216
            'typeOfVideo' => $this->typeOfVideo,
217
            'videoDimensions' => $this->videoDimensions];
218
        foreach ($array as $key => $value) {
219
            if (is_null($value) || $value == '')
220
                unset($array[$key]);
221
        }
222
        return $array;
223
    }
224
225
    /**
226
     * @param Publisher $other
227
     * @return bool
228
     */
229
    public function equalTo(Publisher $other): bool
230
    {
231
        return (
232
            $this->streamId === $other->getStreamId() &&
233
            $this->createdAt === $other->getCreatedAt() &&
234
            $this->hasAudio === $other->hasAudio() &&
235
            $this->hasVideo === $other->hasVideo() &&
236
            $this->audioActive === $other->isAudioActive() &&
237
            $this->videoActive === $other->isVideoActive() &&
238
            $this->frameRate === $other->getFrameRate() &&
239
            $this->typeOfVideo === $other->getTypeOfVideo() &&
240
            $this->videoDimensions === $other->getVideoDimensions()
241
        );
242
    }
243
}
244