Publisher::__construct()   A
last analyzed

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 Publisher
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
    public function __toString(): string
101
    {
102
        return $this->getStreamId();
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getStreamId(): string
109
    {
110
        return $this->streamId;
111
    }
112
113
    /**
114
     * Convert the model instance to JSON.
115
     *
116
     * @param  int  $options
117
     * @return string
118
     *
119
     */
120
    public function toJson($options = 0): string
121
    {
122
        return json_encode($this->jsonSerialize(), $options);
123
    }
124
125
    /**
126
     * Specify data which should be serialized to JSON
127
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
128
     * @return mixed data which can be serialized by <b>json_encode</b>,
129
     * which is a value of any type other than a resource.
130
     * @since 5.4.0
131
     */
132
    public function jsonSerialize()
133
    {
134
        return $this->toArray();
135
    }
136
137
    /**
138
     * Convert the model instance to an array.
139
     *
140
     * @return array
141
     */
142
    public function toArray(): array
143
    {
144
        $array = [
145
            'streamId' => $this->streamId,
146
            'createdAt' => $this->createdAt,
147
            'hasAudio' => $this->hasAudio,
148
            'hasVideo' => $this->hasVideo,
149
            'audioActive' => $this->audioActive,
150
            'videoActive' => $this->videoActive,
151
            'frameRate' => $this->frameRate,
152
            'typeOfVideo' => $this->typeOfVideo,
153
            'videoDimensions' => $this->videoDimensions
154
        ];
155
        foreach ($array as $key => $value) {
156
            if (is_null($value) || $value == '') {
157
                unset($array[$key]);
158
            }
159
        }
160
        return $array;
161
    }
162
163
    /**
164
     * @param  Publisher  $other
165
     * @return bool
166
     */
167
    public function equalTo(Publisher $other): bool
168
    {
169
        return (
170
            $this->streamId === $other->getStreamId() &&
171
            $this->createdAt === $other->getCreatedAt() &&
172
            $this->hasAudio === $other->hasAudio() &&
173
            $this->hasVideo === $other->hasVideo() &&
174
            $this->audioActive === $other->isAudioActive() &&
175
            $this->videoActive === $other->isVideoActive() &&
176
            $this->frameRate === $other->getFrameRate() &&
177
            $this->typeOfVideo === $other->getTypeOfVideo() &&
178
            $this->videoDimensions === $other->getVideoDimensions()
179
        );
180
    }
181
182
    /**
183
     * @return int
184
     */
185
    public function getCreatedAt(): int
186
    {
187
        return $this->createdAt;
188
    }
189
190
    /**
191
     * @return bool
192
     */
193
    public function hasAudio(): bool
194
    {
195
        return $this->hasAudio;
196
    }
197
198
    /**
199
     * @return bool
200
     */
201
    public function hasVideo(): bool
202
    {
203
        return $this->hasVideo;
204
    }
205
206
    /**
207
     * @return bool
208
     */
209
    public function isAudioActive(): bool
210
    {
211
        return $this->audioActive;
212
    }
213
214
    /**
215
     * @return bool
216
     */
217
    public function isVideoActive(): bool
218
    {
219
        return $this->videoActive;
220
    }
221
222
    /**
223
     * @return int
224
     */
225
    public function getFrameRate(): int
226
    {
227
        return $this->frameRate;
228
    }
229
230
    /**
231
     * @return string
232
     */
233
    public function getTypeOfVideo(): string
234
    {
235
        return $this->typeOfVideo;
236
    }
237
238
    /**
239
     * @return string
240
     */
241
    public function getVideoDimensions(): string
242
    {
243
        return $this->videoDimensions;
244
    }
245
}
246