Completed
Push — master ( 46d7d4...59ec59 )
by Jignesh
01:12
created

Bbb::source()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton;
5
6
use BigBlueButton\BigBlueButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, JoisarJignesh\Bigbluebutton\BigBlueButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use BigBlueButton\Parameters\CreateMeetingParameters;
8
use BigBlueButton\Parameters\DeleteRecordingsParameters;
9
use BigBlueButton\Parameters\EndMeetingParameters;
10
use BigBlueButton\Parameters\GetMeetingInfoParameters;
11
use BigBlueButton\Parameters\GetRecordingsParameters;
12
use BigBlueButton\Parameters\HooksCreateParameters;
13
use BigBlueButton\Parameters\HooksDestroyParameters;
14
use BigBlueButton\Parameters\IsMeetingRunningParameters;
15
use BigBlueButton\Parameters\JoinMeetingParameters;
16
use BigBlueButton\Parameters\PublishRecordingsParameters;
17
use BigBlueButton\Parameters\SetConfigXMLParameters;
18
use JoisarJignesh\Bigbluebutton\Services\initConfigXml;
19
use JoisarJignesh\Bigbluebutton\Services\initExtra;
20
use JoisarJignesh\Bigbluebutton\Services\initHooks;
21
use JoisarJignesh\Bigbluebutton\Services\initMeeting;
22
use JoisarJignesh\Bigbluebutton\Services\initRecordings;
23
24
class Bbb
25
{
26
    use initMeeting,
27
        initRecordings,
28
        initHooks,
29
        initConfigXml,
30
        initExtra;
31
32
    /**
33
     * @var
34
     */
35
    private $response;
36
    /**
37
     * @var BigBlueButton
38
     */
39
    protected $bbb;
40
41
42
    /**
43
     * Bbb constructor.
44
     *
45
     * @param BigBlueButton $bbb
46
     */
47
    public function __construct(BigBlueButton $bbb)
48
    {
49
        $this->bbb = $bbb;
50
    }
51
52
    /**
53
     * @return self
54
     */
55
    public function make()
56
    {
57
        return $this;
58
    }
59
60
    /**
61
     * @return BigBlueButton
62
     */
63
    public function source()
64
    {
65
        return $this->bbb;
66
    }
67
68
    /**
69
     * check url and secret is working
70
     * @return bool
71
     */
72
    public function isConnect()
73
    {
74
        $response = $this->initIsConnect();
75
        if ($response['flag'] === true) {
76
            return true;
77
        }
78
79
        return false;
80
    }
81
82
    /**
83
     *  Return a list of all meetings
84
     *
85
     * @return \Illuminate\Support\Collection
86
     */
87
    public function all()
88
    {
89
        $this->response = $this->bbb->getMeetings();
90 View Code Duplication
        if ($this->response->success()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
            if (count($this->response->getRawXml()->meetings->meeting) > 0) {
92
                $meetings = [];
93
                foreach ($this->response->getRawXml()->meetings->meeting as $meeting) {
94
                    $meetings[] = XmlToArray($meeting);
95
                }
96
97
                return collect(XmlToArray($meetings));
98
            }
99
        }
100
101
        return collect([]);
102
    }
103
104
105
    /**
106
     * $meeting
107
     *
108
     * @param $meeting
109
     *
110
     * required fields
111
     * meetingID
112
     * meetingName
113
     *
114
     * @return mixed
115
     */
116 View Code Duplication
    public function create($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        if (!$meeting instanceof CreateMeetingParameters) {
119
            $meeting = $this->initCreateMeeting($meeting);
120
        }
121
122
        $this->response = $this->bbb->createMeeting($meeting);
123
        if ($this->response->failed()) {
124
            return $this->response->getMessage();
125
        } else {
126
            return collect(XmlToArray($this->response->getRawXml()));
127
        }
128
    }
129
130
    /**
131
     * @param $meeting
132
     *
133
     * required fields:
134
     * meetingID
135
     *
136
     * @return bool
137
     */
138 View Code Duplication
    public function isMeetingRunning($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    {
140
        if (!$meeting instanceof IsMeetingRunningParameters) {
141
            $meeting = $this->initIsMeetingRunning($meeting);
142
        }
143
144
        $this->response = $this->bbb->isMeetingRunning($meeting);
145
        if ($this->response->success()) {
146
            $response = XmlToArray($this->response->getRawXml());
147
            if (isset($response['running']) && $response['running'] == "true") {
148
                return true;
149
            }
150
        }
151
152
        return false;
153
    }
154
155
    /**
156
     *  Join meeting
157
     *
158
     * @param $meeting
159
     * required fields
160
     *
161
     *  meetingID
162
     *  userName join by name
163
     *  password which role want to join
164
     *
165
     * @return string
166
     */
167
    public function join($meeting)
168
    {
169
        if (!$meeting instanceof JoinMeetingParameters) {
170
            $meeting = $this->initJoinMeeting($meeting);
171
        }
172
173
        if ($meeting->isRedirect()) {
174
            return $this->bbb->getJoinMeetingURL($meeting);
175
        }
176
177
        return $this->bbb->joinMeeting($meeting)->getUrl();
178
    }
179
180
    /**
181
     *  Returns information about the meeting
182
     *
183
     * @param $meeting
184
     * required fields
185
     * meetingID
186
     * moderatorPW must be there moderator password
187
     *
188
     * @return \Illuminate\Support\Collection
189
     */
190 View Code Duplication
    public function getMeetingInfo($meeting)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
191
    {
192
        if (!$meeting instanceof GetMeetingInfoParameters) {
193
            $meeting = $this->initGetMeetingInfo($meeting);
194
        }
195
196
        $this->response = $this->bbb->getMeetingInfo($meeting);
197
        if ($this->response->success()) {
198
            return collect(XmlToArray($this->response->getRawXml()));
199
        }
200
201
        return collect([]);
202
    }
203
204
    /**
205
     * @param $parameters
206
     *
207
     *  required fields
208
     * meetingID
209
     * meetingName
210
     * userName
211
     * attendeePW
212
     * moderatorPW
213
     *
214
     * @return mixed
215
     */
216
    public function start($parameters)
217
    {
218
        return $this->initStart($parameters);
219
    }
220
221
    /**
222
     *  Close meeting
223
     *
224
     * @param  $meeting
225
     * required fields:
226
     * meetingID
227
     * moderatorPW close meeting must be there moderator password
228
     *
229
     * @return bool
230
     */
231
    public function close($meeting)
232
    {
233
        if (!$meeting instanceof EndMeetingParameters) {
234
            $meeting = $this->initCloseMeeting($meeting);
235
        }
236
237
        $this->response = $this->bbb->endMeeting($meeting);
238
        if ($this->response->success()) {
239
            return true;
240
        }
241
242
        return false;
243
    }
244
245
    /**
246
     *
247
     * @param $recording
248
     * required fields
249
     * meetingID
250
     *
251
     * optional fields
252
     * recordID
253
     * state
254
     *
255
     * @return \Illuminate\Support\Collection
256
     */
257
    public function getRecordings($recording)
258
    {
259
        if (!$recording instanceof GetRecordingsParameters) {
260
            $recording = $this->initGetRecordings($recording);
261
        }
262
263
        $this->response = $this->bbb->getRecordings($recording);
264 View Code Duplication
        if (count($this->response->getRawXml()->recordings->recording) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
265
            $recordings = [];
266
            foreach ($this->response->getRawXml()->recordings->recording as $r) {
267
                $recordings[] = XmlToArray($r);
268
            }
269
270
            return collect($recordings);
271
        }
272
273
        return collect([]);
274
    }
275
276
    /**
277
     * @param $recording
278
     * recordID as string(separated by comma)
279
     * publish as bool
280
     *
281
     * @return bool
282
     */
283 View Code Duplication
    public function publishRecordings($recording)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
284
    {
285
        if (!$recording instanceof PublishRecordingsParameters) {
286
            $recording = $this->initPublishRecordings($recording);
287
        }
288
289
        $this->response = $this->bbb->publishRecordings($recording);
290
        if ($this->response->success()) {
291
            $response = XmlToArray($this->response->getRawXml());
292
            if (isset($response['published']) && $response['published'] == "true") {
293
                return true;
294
            }
295
        }
296
297
        return false;
298
    }
299
300
    /**
301
     * @param $recording
302
     *
303
     * required fields
304
     * recordingID
305
     *
306
     * @return \Illuminate\Support\Collection
307
     */
308
    public function deleteRecordings($recording)
309
    {
310
        if (!$recording instanceof DeleteRecordingsParameters) {
311
            $recording = $this->initDeleteRecordings($recording);
312
        }
313
314
        $this->response = $this->bbb->deleteRecordings($recording);
315
316
        return collect(XmlToArray($this->response->getRawXml()));
317
    }
318
319
    /**
320
     * @param $configXml
321
     *
322
     * @return \Illuminate\Support\Collection
323
     * @throws \Exception
324
     */
325
    public function setConfigXml($configXml)
326
    {
327
        if (!$configXml instanceof SetConfigXMLParameters) {
328
            $configXml = $this->initSetConfigXml($configXml);
329
        }
330
331
        $this->response = $this->bbb->setConfigXML($configXml);
332
333
        return collect(XmlToArray($this->response->getRawXml()));
334
    }
335
336
    /**
337
     * @return \BigBlueButton\Responses\GetDefaultConfigXMLResponse
338
     */
339
    public function getDefaultConfigXml()
340
    {
341
        $this->response = $this->bbb->getDefaultConfigXML();
342
343
        return $this->response;
344
    }
345
346
    /**
347
     * @return \Illuminate\Support\Collection
348
     */
349
    public function getApiVersion()
350
    {
351
        $this->response = $this->bbb->getApiVersion();
352
353
        return collect(XmlToArray($this->response->getRawXml()));
354
    }
355
356
    /**
357
     * @param $hooks
358
     *
359
     * @return \Illuminate\Support\Collection
360
     */
361
    public function hooksCreate($hooks)
362
    {
363
        if (!$hooks instanceof HooksCreateParameters) {
364
            $hooks = $this->initHooksCreate($hooks);
365
        }
366
367
        $this->response = $this->bbb->hooksCreate($hooks);
368
369
        return collect(XmlToArray($this->response->getRawXml()));
370
    }
371
372
    /**
373
     * @param $hooks
374
     *
375
     * @return  \Illuminate\Support\Collection
376
     */
377
    public function hooksDestroy($hooks)
378
    {
379
        if (!$hooks instanceof HooksDestroyParameters) {
380
            $hooks = $this->initHooksDestroy($hooks);
381
        }
382
383
        $this->response = $this->bbb->hooksDestroy($hooks);
384
385
        return collect(XmlToArray($this->response->getRawXml()));
386
    }
387
388
}
389