Completed
Push — master ( e09922...78d11c )
by Jignesh
01:13
created

Bbb   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 252
Duplicated Lines 30.16 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
dl 76
loc 252
rs 9.6
c 0
b 0
f 0
wmc 35
lcom 1
cbo 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 4 1
A all() 10 16 4
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 getRecordings() 8 18 4
A publishRecordings() 16 16 5
A deleteRecordings() 0 9 2

How to fix   Duplicated Code   

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:

1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton;
5
6
use BigBlueButton\BigBlueButton;
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\IsMeetingRunningParameters;
13
use BigBlueButton\Parameters\JoinMeetingParameters;
14
use BigBlueButton\Parameters\PublishRecordingsParameters;
15
use JoisarJignesh\Bigbluebutton\Services\initMeeting;
16
17
class Bbb
18
{
19
    use initMeeting;
20
21
    private $response;
22
    /**
23
     * @var BigBlueButton
24
     */
25
    protected $bbb;
26
27
28
    public function __construct(BigBlueButton $bbb)
29
    {
30
        $this->bbb = $bbb;
31
    }
32
33
    /*
34
     * return BigBlueButton\BigBlueButton
35
     * return BigBlueButton Class of Api class
36
     */
37
    public function make()
38
    {
39
        return $this->bbb;
40
    }
41
    /**
42
     *  Return a list of all meetings
43
     *
44
     * @return \Illuminate\Support\Collection
45
     */
46
    public function all()
47
    {
48
        $this->response = $this->bbb->getMeetings();
49 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...
50
            if (count($this->response->getRawXml()->meetings->meeting) > 0) {
51
                $meetings = [];
52
                foreach ($this->response->getRawXml()->meetings->meeting as $meeting) {
53
                    $meetings[] = XmlToArray($meeting);
54
                }
55
56
                return collect(XmlToArray($meetings));
57
            }
58
        }
59
60
        return collect([]);
61
    }
62
63
64
    /**
65
     * $meeting
66
     *
67
     * @param $meeting
68
     *
69
     * required fields
70
     * meetingID
71
     * meetingName
72
     *
73
     * @return mixed
74
     */
75 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...
76
    {
77
        if (!$meeting instanceof CreateMeetingParameters) {
78
            $meeting = $this->initCreateMeeting($meeting);
79
        }
80
81
        $this->response = $this->bbb->createMeeting($meeting);
82
        if ($this->response->failed()) {
83
            return $this->response->getMessage();
84
        } else {
85
            return collect(XmlToArray($this->response->getRawXml()));
86
        }
87
    }
88
89
    /**
90
     * @param $meeting
91
     *
92
     * required fields:
93
     * meetingID
94
     *
95
     * @return bool
96
     */
97 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...
98
    {
99
        if (!$meeting instanceof IsMeetingRunningParameters) {
100
            $meeting = $this->initIsMeetingRunning($meeting);
101
        }
102
103
        $this->response = $this->bbb->isMeetingRunning($meeting);
104
        if ($this->response->success()) {
105
            $response = XmlToArray($this->response->getRawXml());
106
            if (isset($response['running']) && $response['running'] == "true") {
107
                return true;
108
            }
109
        }
110
111
        return false;
112
    }
113
114
    /**
115
     *  Join meeting
116
     *
117
     * @param $meeting
118
     * required fields
119
     *
120
     *  meetingID
121
     *  userName join by name
122
     *  password which role want to join
123
     *
124
     * @return string
125
     */
126
    public function join($meeting)
127
    {
128
        if (!$meeting instanceof JoinMeetingParameters) {
129
            $meeting = $this->initJoinMeeting($meeting);
130
        }
131
132
        if ($meeting->isRedirect()) {
133
            return $this->bbb->getJoinMeetingURL($meeting);
134
        }
135
136
        return $this->bbb->joinMeeting($meeting)->getUrl();
137
    }
138
139
    /**
140
     *  Returns information about the meeting
141
     *
142
     * @param $meeting
143
     * required fields
144
     * meetingID
145
     * moderatorPW must be there moderator password
146
     *
147
     * @return \Illuminate\Support\Collection
148
     */
149 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...
150
    {
151
        if (!$meeting instanceof GetMeetingInfoParameters) {
152
            $meeting = $this->initGetMeetingInfo($meeting);
153
        }
154
155
        $this->response = $this->bbb->getMeetingInfo($meeting);
156
        if ($this->response->success()) {
157
            return collect(XmlToArray($this->response->getRawXml()));
158
        }
159
160
        return collect([]);
161
    }
162
163
    /*
164
         * required fields
165
         * meetingID
166
         * meetingName
167
         * userName
168
         * attendeePW
169
         * moderatorPW
170
         */
171
    public function start($parameters)
172
    {
173
        return $this->initStart($parameters);
174
    }
175
176
    /**
177
     *  Close meeting
178
     *
179
     * @param  $meeting
180
     * required fields:
181
     * meetingID
182
     * moderatorPW close meeting must be there moderator password
183
     *
184
     * @return bool
185
     */
186
    public function close($meeting)
187
    {
188
        if (!$meeting instanceof EndMeetingParameters) {
189
            $meeting = $this->initCloseMeeting($meeting);
190
        }
191
192
        $this->response = $this->bbb->endMeeting($meeting);
193
        if ($this->response->success()) {
194
            return true;
195
        }
196
197
        return false;
198
    }
199
200
    /**
201
     *
202
     * @param $recording
203
     * required fields
204
     * meetingID
205
     *
206
     * optional fields
207
     * recordID
208
     * state
209
     * @return \Illuminate\Support\Collection
210
     */
211
    public function getRecordings($recording)
212
    {
213
        if (!$recording instanceof GetRecordingsParameters) {
214
            $recording = $this->initGetRecordings($recording);
215
        }
216
217
        $this->response = $this->bbb->getRecordings($recording);
218 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...
219
            $recordings = [];
220
            foreach ($this->response->getRawXml()->recordings->recording as $r) {
221
                $recordings[] = XmlToArray($r);
222
            }
223
224
            return collect($recordings);
225
        }
226
227
        return collect([]);
228
    }
229
230
    /**
231
     * @param $recording
232
     * recordID as string(sepeate by commma)
233
     * publish as bool
234
     *
235
     * @return bool
236
     */
237 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...
238
    {
239
        if (!$recording instanceof PublishRecordingsParameters) {
240
            $recording = $this->initPublishRecordings($recording);
241
        }
242
243
        $this->response = $this->bbb->publishRecordings($recording);
244
        if ($this->response->success()) {
245
            $response = XmlToArray($this->response->getRawXml());
246
            if (isset($response['published']) && $response['published'] == "true") {
247
                return true;
248
            }
249
        }
250
251
        return false;
252
    }
253
254
    /*
255
     * required fields
256
     * recordingID
257
     */
258
    public function deleteRecordings($recording)
259
    {
260
        if (!$recording instanceof DeleteRecordingsParameters) {
261
            $recording = $this->initDeleteRecordings($recording);
262
        }
263
264
        $this->response = $this->bbb->deleteRecordings($recording);
265
        return collect(XmlToArray($this->response->getRawXml()));
266
    }
267
268
}
269