Completed
Push — master ( 2fe86e...abe09c )
by Jignesh
01:12
created

initMeeting   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 171
rs 10
c 0
b 0
f 0
wmc 21
lcom 0
cbo 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A initCreateMeeting() 0 28 5
A initCloseMeeting() 0 6 1
A initJoinMeeting() 0 14 2
A initIsMeetingRunning() 0 6 1
A initGetMeetingInfo() 0 6 1
A initGetRecordings() 0 15 3
A initDeleteRecordings() 0 6 1
A makeJoinMeetingArray() 0 14 3
A initStart() 0 14 4
1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton\Services;
5
6
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 Illuminate\Support\Str;
15
16
trait initMeeting
17
{
18
19
    /*
20
     * required fields
21
     * meetingID
22
     * meetingName
23
     *
24
     */
25
    public function initCreateMeeting(array $parameters)
26
    {
27
        $request = Fluent($parameters);
28
        $meetingParams = new CreateMeetingParameters($request->meetingID, $request->meetingName);
29
        if ($request->duration) {
30
            $meetingParams->setDuration($request->duration);
31
        }
32
33
        $meetingParams->setModeratorPassword($request->get('moderatorPW', Str::random(10)));
34
        $meetingParams->setAttendeePassword($request->get('attendeePW', Str::random(10)));
35
36
        if ($request->record) {
37
            $meetingParams->setRecord(true);
38
            $meetingParams->setAllowStartStopRecording(true);
39
            $meetingParams->setAutoStartRecording(true);
40
        }
41
42
        if ($request->maxParticipants) {
43
            $meetingParams->setMaxParticipants($request->maxParticipants);
44
        }
45
46
        if ($request->logoutUrl) {
47
            $meetingParams->setLogoutUrl($request->logoutUrl);
48
        }
49
50
51
        return $meetingParams;
52
    }
53
54
    /*
55
     * required fields:
56
     * meetingID
57
     * moderatorPW close meeting must be there moderator password
58
     */
59
    public function initCloseMeeting(array $parameters)
60
    {
61
        $request = Fluent($parameters);
62
63
        return (new EndMeetingParameters($request->meetingID, $request->moderatorPW));
64
    }
65
66
    /*
67
     *  required fields
68
     *
69
     *  meetingID
70
     *  userName join by name
71
     *  password which role want to join
72
     */
73
    public function initJoinMeeting(array $parameters)
74
    {
75
        $request = Fluent($parameters);
76
        $meetingParams = new JoinMeetingParameters($request->meetingID, $request->userName, $request->password);
77
        $meetingParams->setRedirect($request->get('redirect', true));
78
        $meetingParams->setJoinViaHtml5($request->get('joinViaHtml5', true));
79
80
81
        if ($request->userId) {
82
            $meetingParams->setUserId($request->userId);
83
        }
84
85
        return $meetingParams;
86
    }
87
88
    /*
89
     * required fields
90
     * meetingID
91
     */
92
    public function initIsMeetingRunning(array $parameters)
93
    {
94
        $request = Fluent($parameters);
95
96
        return (new IsMeetingRunningParameters($request->meetingID));
97
    }
98
99
    /*
100
     * required fields
101
     * meetingID
102
     * moderatorPW must be there moderator password
103
     */
104
    public function initGetMeetingInfo($parameters)
105
    {
106
        $request = Fluent($parameters);
107
108
        return (new GetMeetingInfoParameters($request->meetingID, $request->moderatorPW));
109
    }
110
111
    /*
112
     * required fields
113
     * meetingID
114
     *
115
     * optional fields
116
     * recordID
117
     * state
118
     */
119
    public function initGetRecordings(array $parameters)
120
    {
121
        $request = Fluent($parameters);
122
123
        $recordings = new GetRecordingsParameters();
124
        $recordings->setMeetingId($request->meetingID);
125
        if ($request->recordID) {
126
            $recordings->setRecordId($request->recordID);
127
        }
128
        if ($request->state) {
129
            $recordings->setState($request->state);
130
        }
131
132
        return $recordings;
133
    }
134
135
    /*
136
     * required fields
137
     * recordingID
138
     */
139
    public function initDeleteRecordings($recording)
140
    {
141
        $request = Fluent($recording);
142
143
        return (new DeleteRecordingsParameters($request->recordingID));
144
    }
145
146
    private function makeJoinMeetingArray($object, $parameters)
147
    {
148
        $pass['meetingID'] = $object->get('meetingID');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$pass was never initialized. Although not strictly required by PHP, it is generally a good practice to add $pass = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
149
        $pass['password'] = $object->get('moderatorPW');
150
        if (isset($parameters['userName'])) {
151
            $pass['userName'] = $parameters['userName'];
152
        }
153
        $pass['meetingName'] = $object->get('meetingName');
154
        if (isset($parameters['redirect'])) {
155
            $pass['redirect'] = $parameters['redirect'];
156
        }
157
158
        return $pass;
159
    }
160
161
    /*
162
     * required fields
163
     * meetingID
164
     * meetingName
165
     * userName
166
     * attendeePW
167
     * moderatorPW
168
     * redirect
169
     */
170
    public function initStart(array $parameters)
171
    {
172
        if ($this->getMeetingInfo($parameters)->isEmpty()) {
0 ignored issues
show
Bug introduced by
The method getMeetingInfo() does not exist on JoisarJignesh\Bigbluebutton\Services\initMeeting. Did you maybe mean initGetMeetingInfo()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
173
            $object = $this->create($parameters);
0 ignored issues
show
Bug introduced by
The method create() does not exist on JoisarJignesh\Bigbluebutton\Services\initMeeting. Did you maybe mean initCreateMeeting()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
174
            if (!$object->isEmpty()) {
175
                return $this->join($this->makeJoinMeetingArray($object, $parameters));
0 ignored issues
show
Bug introduced by
It seems like join() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
176
            }
177
        } else {
178
            if (isset($parameters['moderatorPW'])) {
179
                $parameters['password'] = trim($parameters['moderatorPW']);
180
            }
181
            return $this->join($parameters);
0 ignored issues
show
Bug introduced by
It seems like join() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
182
        }
183
    }
184
185
186
}
187