Completed
Push — master ( 98ce91...54c84c )
by Ghazi
02:25
created

BigBlueButton::getIsMeetingRunningUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under the
8
 * terms of the GNU Lesser General Public License as published by the Free Software
9
 * Foundation; either version 3.0 of the License, or (at your option) any later
10
 * version.
11
 *
12
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License along
17
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
 */
19
namespace BigBlueButton;
20
21
use BigBlueButton\Core\ApiMethod;
22
use BigBlueButton\Parameters\CreateMeetingParameters;
23
use BigBlueButton\Parameters\DeleteRecordingsParameters;
24
use BigBlueButton\Parameters\EndMeetingParameters;
25
use BigBlueButton\Parameters\GetMeetingInfoParameters;
26
use BigBlueButton\Parameters\GetRecordingsParameters;
27
use BigBlueButton\Parameters\IsMeetingRunningParameters;
28
use BigBlueButton\Parameters\JoinMeetingParameters;
29
use BigBlueButton\Parameters\PublishRecordingsParameters;
30
use BigBlueButton\Responses\ApiVersionResponse;
31
use BigBlueButton\Responses\CreateMeetingResponse;
32
use BigBlueButton\Responses\DeleteRecordingsResponse;
33
use BigBlueButton\Responses\EndMeetingResponse;
34
use BigBlueButton\Responses\GetDefaultConfigXMLResponse;
35
use BigBlueButton\Responses\GetMeetingInfoResponse;
36
use BigBlueButton\Responses\GetMeetingsResponse;
37
use BigBlueButton\Responses\GetRecordingsResponse;
38
use BigBlueButton\Responses\IsMeetingRunningResponse;
39
use BigBlueButton\Responses\PublishRecordingsResponse;
40
use BigBlueButton\Util\UrlBuilder;
41
use SimpleXMLElement;
42
43
/**
44
 * Class BigBlueButton
45
 * @package BigBlueButton
46
 */
47
class BigBlueButton
48
{
49
    private $securitySalt;
50
    private $bbbServerBaseUrl;
51
    private $urlBuilder;
52
53
    public function __construct()
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
54
    {
55
        $this->securitySalt     = $_SERVER['BBB_SECURITY_SALT'];
56
        $this->bbbServerBaseUrl = $_SERVER['BBB_SERVER_BASE_URL'];
57
        $this->urlBuilder       = new UrlBuilder($this->securitySalt, $this->bbbServerBaseUrl);
58
    }
59
60
    /**
61
     * @return ApiVersionResponse
62
     *
63
     * @throws \Exception
64
     */
65
    public function getApiVersion()
66
    {
67
        return new ApiVersionResponse($this->processXmlResponse($this->urlBuilder->buildUrl()));
0 ignored issues
show
Security Bug introduced by
It seems like $this->processXmlRespons...urlBuilder->buildUrl()) targeting BigBlueButton\BigBlueButton::processXmlResponse() can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?
Loading history...
68
    }
69
70
    /* __________________ BBB ADMINISTRATION METHODS _________________ */
71
    /* The methods in the following section support the following categories of the BBB API:
72
    -- create
73
    -- getDefaultConfigXML
74
    -- join
75
    -- end
76
    */
77
78
    /**
79
     * @param $createMeetingParams CreateMeetingParameters
80
     *
81
     * @return string
82
     */
83
    public function getCreateMeetingUrl($createMeetingParams)
84
    {
85
        return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
86
    }
87
88
    /**
89
     * @param  CreateMeetingParameters $createMeetingParams
90
     * @return CreateMeetingResponse
91
     * @throws \Exception
92
     */
93
    public function createMeeting($createMeetingParams)
94
    {
95
        $xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
0 ignored issues
show
Security Bug introduced by
It seems like $createMeetingParams->getPresentationsAsXML() targeting BigBlueButton\Parameters...getPresentationsAsXML() can also be of type false; however, BigBlueButton\BigBlueButton::processXmlResponse() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
96
97
        return new CreateMeetingResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...etPresentationsAsXML()) on line 95 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getDefaultConfigXMLUrl()
104
    {
105
        return $this->urlBuilder->buildUrl(ApiMethod::GET_DEFAULT_CONFIG_XML);
106
    }
107
108
    /**
109
     *
110
     * @return GetDefaultConfigXMLResponse
111
     */
112
    public function getDefaultConfigXML()
113
    {
114
        $xml = $this->processXmlResponse($this->getDefaultConfigXMLUrl());
115
116
        return new GetDefaultConfigXMLResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...tDefaultConfigXMLUrl()) on line 114 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
117
    }
118
119
    /**
120
     * @param $joinMeetingParams JoinMeetingParameters
121
     *
122
     * @return string
123
     */
124
    public function getJoinMeetingURL($joinMeetingParams)
125
    {
126
        return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
127
    }
128
129
    /**
130
     * @param $endParams EndMeetingParameters
131
     *
132
     * @return string
133
     */
134
    public function getEndMeetingURL($endParams)
135
    {
136
        return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
137
    }
138
139
    /**
140
     * @param $endParams EndMeetingParameters
141
     *
142
     * @return EndMeetingResponse
143
     */
144
    public function endMeeting($endParams)
145
    {
146
        $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
147
148
        return new EndMeetingResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...MeetingURL($endParams)) on line 146 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
149
    }
150
151
    /* __________________ BBB MONITORING METHODS _________________ */
152
    /* The methods in the following section support the following categories of the BBB API:
153
    -- isMeetingRunning
154
    -- getMeetings
155
    -- getMeetingInfo
156
    */
157
158
    /**
159
     * @param $meetingParams IsMeetingRunningParameters
160
     * @return string
161
     */
162
    public function getIsMeetingRunningUrl($meetingParams)
163
    {
164
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
165
    }
166
167
    /**
168
     * @param $meetingParams
169
     * @return IsMeetingRunningResponse
170
     * @throws \Exception
171
     */
172
    public function isMeetingRunning($meetingParams)
173
    {
174
        $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
175
176
        return new IsMeetingRunningResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...ingUrl($meetingParams)) on line 174 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
177
    }
178
179
    /**
180
     * @return string
181
     */
182
    public function getMeetingsUrl()
183
    {
184
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
185
    }
186
187
    /**
188
     * @return GetMeetingsResponse
189
     */
190
    public function getMeetings()
191
    {
192
        $xml = $this->processXmlResponse($this->getMeetingsUrl());
193
194
        return new GetMeetingsResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...this->getMeetingsUrl()) on line 192 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
195
    }
196
197
    /**
198
     * @param $meetingParams GetMeetingInfoParameters
199
     * @return string
200
     */
201
    public function getMeetingInfoUrl($meetingParams)
202
    {
203
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
204
    }
205
206
    /**
207
     * @param $meetingParams GetMeetingInfoParameters
208
     * @return GetMeetingInfoResponse
209
     */
210
    public function getMeetingInfo($meetingParams)
211
    {
212
        $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
213
214
        return new GetMeetingInfoResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...nfoUrl($meetingParams)) on line 212 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
215
    }
216
217
    /* __________________ BBB RECORDING METHODS _________________ */
218
    /* The methods in the following section support the following categories of the BBB API:
219
    -- getRecordings
220
    -- publishRecordings
221
    -- deleteRecordings
222
    */
223
224
    /**
225
     * @param $recordingsParams GetRecordingsParameters
226
     * @return string
227
     */
228
    public function getRecordingsUrl($recordingsParams)
229
    {
230
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
231
    }
232
233
    /**
234
     * @param $recordingParams
235
     * @return GetRecordingsResponse
236
     * @throws \Exception
237
     */
238
    public function getRecordings($recordingParams)
239
    {
240
        $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
241
242
        return new GetRecordingsResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 240 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
243
    }
244
245
    /**
246
     * @param $recordingParams PublishRecordingsParameters
247
     * @return string
248
     */
249
    public function getPublishRecordingsUrl($recordingParams)
250
    {
251
        return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
252
    }
253
254
    /**
255
     * @param $recordingParams PublishRecordingsParameters
256
     * @return PublishRecordingsResponse
257
     * @throws \Exception
258
     */
259
    public function publishRecordings($recordingParams)
260
    {
261
        $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
262
263
        return new PublishRecordingsResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 261 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
264
    }
265
266
    /**
267
     * @param $recordingParams DeleteRecordingsParameters
268
     * @return string
269
     */
270
    public function deleteRecordingsUrl($recordingParams)
271
    {
272
        return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
273
    }
274
275
    /**
276
     * @param $recordingParams
277
     * @return DeleteRecordingsResponse
278
     * @throws \Exception
279
     */
280
    public function deleteRecordings($recordingParams)
281
    {
282
        $xml = $this->processXmlResponse($this->deleteRecordingsUrl($recordingParams));
283
284
        return new DeleteRecordingsResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 282 can also be of type false; however, BigBlueButton\Responses\...Response::__construct() does only seem to accept object<SimpleXMLElement>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
285
    }
286
287
    /* ____________________ INTERNAL CLASS METHODS ___________________ */
288
289
    /**
290
     * A private utility method used by other public methods to process XML responses.
291
     *
292
     * @param $url
293
     * @param  string                $xml
294
     * @return bool|SimpleXMLElement
295
     * @throws \Exception
296
     */
297
    private function processXmlResponse($url, $xml = '')
298
    {
299
        /*
300
        
301
        */
302
        if (extension_loaded('curl')) {
303
            $ch      = curl_init() or die(curl_error());
0 ignored issues
show
Coding Style Compatibility introduced by
The method processXmlResponse() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
304
            $timeout = 10;
305
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
306
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
307
            curl_setopt($ch, CURLOPT_URL, $url);
308
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
309
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
310
            if (!empty($xml)) {
311
                curl_setopt($ch, CURLOPT_HEADER, 0);
312
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
313
                curl_setopt($ch, CURLOPT_POST, 1);
314
                curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
315
                curl_setopt($ch, CURLOPT_HTTPHEADER, [
316
                    'Content-type: application/xml',
317
                    'Content-length: ' . strlen($xml),
318
                ]);
319
            }
320
            $data = curl_exec($ch);
321
            curl_close($ch);
322
323
            if ($data) {
324
                return new SimpleXMLElement($data);
325
            } else {
326
                return false;
327
            }
328
        }
329
        if (!empty($xml)) {
330
            throw new \Exception('Set xml, but curl does not installed.');
331
        }
332
333
        return simplexml_load_file($url);
334
    }
335
}
336