Bbb   B
last analyzed

Complexity

Total Complexity 51

Size/Duplication

Total Lines 383
Duplicated Lines 19.84 %

Coupling/Cohesion

Components 1
Dependencies 21

Importance

Changes 0
Metric Value
dl 76
loc 383
rs 7.92
c 0
b 0
f 0
wmc 51
lcom 1
cbo 21

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A server() 0 13 2
A make() 0 4 1
A source() 0 4 1
A isConnect() 0 9 2
A create() 13 13 3
A isMeetingRunning() 16 16 5
A join() 0 12 3
A getMeetingInfo() 13 13 3
A start() 0 4 1
A close() 0 13 3
A publishRecordings() 16 16 5
A deleteRecordings() 0 10 2
A setConfigXml() 0 10 2
A getDefaultConfigXml() 0 6 1
A getApiVersion() 0 6 1
A hooksCreate() 0 10 2
A hooksDestroy() 0 10 2
A all() 10 16 5
A getRecordings() 8 18 6

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Bbb often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Bbb, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace JoisarJignesh\Bigbluebutton;
4
5
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...
6
use BigBlueButton\Parameters\CreateMeetingParameters;
7
use BigBlueButton\Parameters\DeleteRecordingsParameters;
8
use BigBlueButton\Parameters\EndMeetingParameters;
9
use BigBlueButton\Parameters\GetMeetingInfoParameters;
10
use BigBlueButton\Parameters\GetRecordingsParameters;
11
use BigBlueButton\Parameters\HooksCreateParameters;
12
use BigBlueButton\Parameters\HooksDestroyParameters;
13
use BigBlueButton\Parameters\IsMeetingRunningParameters;
14
use BigBlueButton\Parameters\JoinMeetingParameters;
15
use BigBlueButton\Parameters\PublishRecordingsParameters;
16
use BigBlueButton\Parameters\SetConfigXMLParameters;
17
use JoisarJignesh\Bigbluebutton\Bigbluebutton as BigBlueButtonServer;
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
     * Bbb constructor.
43
     *
44
     * @param BigBlueButton $bbb
45
     */
46
    public function __construct(BigBlueButton $bbb)
47
    {
48
        $this->bbb = $bbb;
49
    }
50
51
    /**
52
     * for specific server instance.
53
     *
54
     * @param $serverName
55
     *
56
     * @return Bbb
57
     * @throws \Exception
58
     */
59
    public function server($serverName)
60
    {
61
        if (is_null(config("bigbluebutton.servers.{$serverName}", null))) {
62
            throw new \Exception("Could not found {$serverName} server configuration in config file");
63
        }
64
65
        return new self(
66
            new BigBlueButtonServer(
67
                config("bigbluebutton.servers.{$serverName}.BBB_SERVER_BASE_URL"),
68
                config("bigbluebutton.servers.{$serverName}.BBB_SECURITY_SALT")
69
            )
70
        );
71
    }
72
73
    /**
74
     * @return self
75
     */
76
    public function make()
77
    {
78
        return $this;
79
    }
80
81
    /**
82
     * @return BigBlueButton
83
     */
84
    public function source()
85
    {
86
        return $this->bbb;
87
    }
88
89
    /**
90
     * check url and secret is working.
91
     * @return bool
92
     */
93
    public function isConnect()
94
    {
95
        $response = $this->initIsConnect();
96
        if ($response['flag'] === true) {
97
            return true;
98
        }
99
100
        return false;
101
    }
102
103
    /**
104
     *  Return a list of all meetings.
105
     *
106
     * @return \Illuminate\Support\Collection
107
     */
108
    public function all()
109
    {
110
        $this->response = $this->bbb->getMeetings();
111 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...
112
            if (! is_null($this->response->getRawXml()->meetings->meeting) && count($this->response->getRawXml()->meetings->meeting) > 0) {
113
                $meetings = [];
114
                foreach ($this->response->getRawXml()->meetings->meeting as $meeting) {
115
                    $meetings[] = XmlToArray($meeting);
116
                }
117
118
                return collect(XmlToArray($meetings));
119
            }
120
        }
121
122
        return collect([]);
123
    }
124
125
    /**
126
     * $meeting.
127
     *
128
     * @param $meeting
129
     *
130
     * required fields
131
     * meetingID
132
     * meetingName
133
     *
134
     * @return mixed
135
     */
136 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...
137
    {
138
        if (! $meeting instanceof CreateMeetingParameters) {
139
            $meeting = $this->initCreateMeeting($meeting);
140
        }
141
142
        $this->response = $this->bbb->createMeeting($meeting);
143
        if ($this->response->failed()) {
144
            return $this->response->getMessage();
145
        } else {
146
            return collect(XmlToArray($this->response->getRawXml()));
147
        }
148
    }
149
150
    /**
151
     * @param $meeting
152
     *
153
     * required fields:
154
     * meetingID
155
     *
156
     * @return bool
157
     */
158 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...
159
    {
160
        if (! $meeting instanceof IsMeetingRunningParameters) {
161
            $meeting = $this->initIsMeetingRunning($meeting);
162
        }
163
164
        $this->response = $this->bbb->isMeetingRunning($meeting);
165
        if ($this->response->success()) {
166
            $response = XmlToArray($this->response->getRawXml());
167
            if (isset($response['running']) && $response['running'] == 'true') {
168
                return true;
169
            }
170
        }
171
172
        return false;
173
    }
174
175
    /**
176
     *  Join meeting.
177
     *
178
     * @param $meeting
179
     * required fields
180
     *
181
     *  meetingID
182
     *  userName join by name
183
     *  password which role want to join
184
     *
185
     * @return string
186
     */
187
    public function join($meeting)
188
    {
189
        if (! $meeting instanceof JoinMeetingParameters) {
190
            $meeting = $this->initJoinMeeting($meeting);
191
        }
192
193
        if ($meeting->isRedirect()) {
194
            return $this->bbb->getJoinMeetingURL($meeting);
195
        }
196
197
        return $this->bbb->joinMeeting($meeting)->getUrl();
198
    }
199
200
    /**
201
     *  Returns information about the meeting.
202
     *
203
     * @param $meeting
204
     * required fields
205
     * meetingID
206
     * moderatorPW must be there moderator password
207
     *
208
     * @return \Illuminate\Support\Collection
209
     */
210 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...
211
    {
212
        if (! $meeting instanceof GetMeetingInfoParameters) {
213
            $meeting = $this->initGetMeetingInfo($meeting);
214
        }
215
216
        $this->response = $this->bbb->getMeetingInfo($meeting);
217
        if ($this->response->success()) {
218
            return collect(XmlToArray($this->response->getRawXml()));
219
        }
220
221
        return collect([]);
222
    }
223
224
    /**
225
     * @param $parameters
226
     *
227
     *  required fields
228
     * meetingID
229
     * meetingName
230
     * userName
231
     * attendeePW
232
     * moderatorPW
233
     *
234
     * @return mixed
235
     */
236
    public function start($parameters)
237
    {
238
        return $this->initStart($parameters);
239
    }
240
241
    /**
242
     *  Close meeting.
243
     *
244
     * @param  $meeting
245
     * required fields:
246
     * meetingID
247
     * moderatorPW close meeting must be there moderator password
248
     *
249
     * @return bool
250
     */
251
    public function close($meeting)
252
    {
253
        if (! $meeting instanceof EndMeetingParameters) {
254
            $meeting = $this->initCloseMeeting($meeting);
255
        }
256
257
        $this->response = $this->bbb->endMeeting($meeting);
258
        if ($this->response->success()) {
259
            return true;
260
        }
261
262
        return false;
263
    }
264
265
    /**
266
     * @param $recording
267
     * required fields
268
     * meetingID
269
     *
270
     * optional fields
271
     * recordID
272
     * state
273
     *
274
     * @return \Illuminate\Support\Collection
275
     */
276
    public function getRecordings($recording)
277
    {
278
        if (! $recording instanceof GetRecordingsParameters) {
279
            $recording = $this->initGetRecordings($recording);
280
        }
281
282
        $this->response = $this->bbb->getRecordings($recording);
283 View Code Duplication
        if ($this->response->success() && ! is_null($this->response->getRawXml()->recordings->recording) && 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...
284
            $recordings = [];
285
            foreach ($this->response->getRawXml()->recordings->recording as $r) {
286
                $recordings[] = XmlToArray($r);
287
            }
288
289
            return collect($recordings);
290
        }
291
292
        return collect([]);
293
    }
294
295
    /**
296
     * @param $recording
297
     * recordID as string(separated by comma)
298
     * publish as bool
299
     *
300
     * @return bool
301
     */
302 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...
303
    {
304
        if (! $recording instanceof PublishRecordingsParameters) {
305
            $recording = $this->initPublishRecordings($recording);
306
        }
307
308
        $this->response = $this->bbb->publishRecordings($recording);
309
        if ($this->response->success()) {
310
            $response = XmlToArray($this->response->getRawXml());
311
            if (isset($response['published']) && $response['published'] == 'true') {
312
                return true;
313
            }
314
        }
315
316
        return false;
317
    }
318
319
    /**
320
     * @param $recording
321
     *
322
     * required fields
323
     * recordingID
324
     *
325
     * @return \Illuminate\Support\Collection
326
     */
327
    public function deleteRecordings($recording)
328
    {
329
        if (! $recording instanceof DeleteRecordingsParameters) {
330
            $recording = $this->initDeleteRecordings($recording);
331
        }
332
333
        $this->response = $this->bbb->deleteRecordings($recording);
334
335
        return collect(XmlToArray($this->response->getRawXml()));
336
    }
337
338
    /**
339
     * @param $configXml
340
     *
341
     * @return \Illuminate\Support\Collection
342
     * @throws \Exception
343
     */
344
    public function setConfigXml($configXml)
345
    {
346
        if (! $configXml instanceof SetConfigXMLParameters) {
347
            $configXml = $this->initSetConfigXml($configXml);
348
        }
349
350
        $this->response = $this->bbb->setConfigXML($configXml);
351
352
        return collect(XmlToArray($this->response->getRawXml()));
353
    }
354
355
    /**
356
     * @return \BigBlueButton\Responses\GetDefaultConfigXMLResponse
357
     */
358
    public function getDefaultConfigXml()
359
    {
360
        $this->response = $this->bbb->getDefaultConfigXML();
361
362
        return $this->response;
363
    }
364
365
    /**
366
     * @return \Illuminate\Support\Collection
367
     */
368
    public function getApiVersion()
369
    {
370
        $this->response = $this->bbb->getApiVersion();
371
372
        return collect(XmlToArray($this->response->getRawXml()));
373
    }
374
375
    /**
376
     * @param $hooks
377
     *
378
     * @return \Illuminate\Support\Collection
379
     */
380
    public function hooksCreate($hooks)
381
    {
382
        if (! $hooks instanceof HooksCreateParameters) {
383
            $hooks = $this->initHooksCreate($hooks);
384
        }
385
386
        $this->response = $this->bbb->hooksCreate($hooks);
387
388
        return collect(XmlToArray($this->response->getRawXml()));
389
    }
390
391
    /**
392
     * @param $hooks
393
     *
394
     * @return  \Illuminate\Support\Collection
395
     */
396
    public function hooksDestroy($hooks)
397
    {
398
        if (! $hooks instanceof HooksDestroyParameters) {
399
            $hooks = $this->initHooksDestroy($hooks);
400
        }
401
402
        $this->response = $this->bbb->hooksDestroy($hooks);
403
404
        return collect(XmlToArray($this->response->getRawXml()));
405
    }
406
}
407