Completed
Push — master ( 9d9aa3...aeab87 )
by Ghazi
04:57
created

BigBlueButton::getMeetingInfoUrl()   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\GetMeetingInfoResponse;
35
use BigBlueButton\Responses\GetMeetingsResponse;
36
use BigBlueButton\Responses\GetRecordingsResponse;
37
use BigBlueButton\Responses\IsMeetingRunningResponse;
38
use BigBlueButton\Responses\PublishRecordingsResponse;
39
use BigBlueButton\Util\UrlBuilder;
40
use SimpleXMLElement;
41
42
/**
43
 * Class BigBlueButton
44
 * @package BigBlueButton
45
 */
46
class BigBlueButton
47
{
48
    private $securitySalt;
49
    private $bbbServerBaseUrl;
50
    private $urlBuilder;
51
52
    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...
53
    {
54
        $this->securitySalt     = $_SERVER['BBB_SECURITY_SALT'];
55
        $this->bbbServerBaseUrl = $_SERVER['BBB_SERVER_BASE_URL'];
56
        $this->urlBuilder       = new UrlBuilder($this->securitySalt, $this->bbbServerBaseUrl);
57
    }
58
59
    /**
60
     * @return ApiVersionResponse
61
     *
62
     * @throws \Exception
63
     */
64
    public function getApiVersion()
65
    {
66
        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...
67
    }
68
69
    /* __________________ BBB ADMINISTRATION METHODS _________________ */
70
    /* The methods in the following section support the following categories of the BBB API:
71
    -- create
72
    -- join
73
    -- end
74
    */
75
76
    /**
77
     * @param $createMeetingParams CreateMeetingParameters
78
     *
79
     * @return string
80
     */
81
    public function getCreateMeetingUrl($createMeetingParams)
82
    {
83
        return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
84
    }
85
86
    /**
87
     * @param  CreateMeetingParameters $createMeetingParams
88
     * @return CreateMeetingResponse
89
     * @throws \Exception
90
     */
91
    public function createMeeting($createMeetingParams)
92
    {
93
        $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...
94
95
        return new CreateMeetingResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...etPresentationsAsXML()) on line 93 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...
96
    }
97
98
    /**
99
     * @param $joinMeetingParams JoinMeetingParameters
100
     *
101
     * @return string
102
     */
103
    public function getJoinMeetingURL($joinMeetingParams)
104
    {
105
        return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
106
    }
107
108
    /**
109
     * @param $endParams EndMeetingParameters
110
     *
111
     * @return string
112
     */
113
    public function getEndMeetingURL($endParams)
114
    {
115
        return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
116
    }
117
118
    /**
119
     * @param $endParams EndMeetingParameters
120
     *
121
     * @return EndMeetingResponse
122
     */
123
    public function endMeeting($endParams)
124
    {
125
        $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
126
127
        return new EndMeetingResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...MeetingURL($endParams)) on line 125 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...
128
    }
129
130
    /* __________________ BBB MONITORING METHODS _________________ */
131
    /* The methods in the following section support the following categories of the BBB API:
132
    -- isMeetingRunning
133
    -- getMeetings
134
    -- getMeetingInfo
135
    */
136
137
    /**
138
     * @param $meetingParams IsMeetingRunningParameters
139
     * @return string
140
     */
141
    public function getIsMeetingRunningUrl($meetingParams)
142
    {
143
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
144
    }
145
146
    /**
147
     * @param $meetingParams
148
     * @return IsMeetingRunningResponse
149
     * @throws \Exception
150
     */
151
    public function isMeetingRunning($meetingParams)
152
    {
153
        $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
154
155
        return new IsMeetingRunningResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...ingUrl($meetingParams)) on line 153 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...
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getMeetingsUrl()
162
    {
163
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
164
    }
165
166
    /**
167
     * @return GetMeetingsResponse
168
     */
169
    public function getMeetings()
170
    {
171
        $xml = $this->processXmlResponse($this->getMeetingsUrl());
172
173
        return new GetMeetingsResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...this->getMeetingsUrl()) on line 171 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...
174
    }
175
176
    /**
177
     * @param $meetingParams GetMeetingInfoParameters
178
     * @return string
179
     */
180
    public function getMeetingInfoUrl($meetingParams)
181
    {
182
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
183
    }
184
185
    /**
186
     * @param $meetingParams GetMeetingInfoParameters
187
     * @return GetMeetingInfoResponse
188
     */
189
    public function getMeetingInfo($meetingParams)
190
    {
191
        $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
192
193
        return new GetMeetingInfoResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...nfoUrl($meetingParams)) on line 191 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...
194
    }
195
196
    /* __________________ BBB RECORDING METHODS _________________ */
197
    /* The methods in the following section support the following categories of the BBB API:
198
    -- getRecordings
199
    -- publishRecordings
200
    -- deleteRecordings
201
    */
202
203
    /**
204
     * @param $recordingsParams GetRecordingsParameters
205
     * @return string
206
     */
207
    public function getRecordingsUrl($recordingsParams)
208
    {
209
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
210
    }
211
212
    /**
213
     * @param $recordingParams
214
     * @return GetRecordingsResponse
215
     * @throws \Exception
216
     */
217
    public function getRecordings($recordingParams)
218
    {
219
        $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
220
221
        return new GetRecordingsResponse($xml);
0 ignored issues
show
Security Bug introduced by
It seems like $xml defined by $this->processXmlRespons...sUrl($recordingParams)) on line 219 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...
222
    }
223
224
    /**
225
     * @param $recordingParams PublishRecordingsParameters
226
     * @return string
227
     */
228
    public function getPublishRecordingsUrl($recordingParams)
229
    {
230
        return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
231
    }
232
233
    /**
234
     * @param $recordingParams PublishRecordingsParameters
235
     * @return PublishRecordingsResponse
236
     * @throws \Exception
237
     */
238
    public function publishRecordings($recordingParams)
239
    {
240
        $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
241
242
        return new PublishRecordingsResponse($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 DeleteRecordingsParameters
247
     * @return string
248
     */
249
    public function deleteRecordingsUrl($recordingParams)
250
    {
251
        return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
252
    }
253
254
    /**
255
     * @param $recordingParams
256
     * @return DeleteRecordingsResponse
257
     * @throws \Exception
258
     */
259
    public function deleteRecordings($recordingParams)
260
    {
261
        $xml = $this->processXmlResponse($this->deleteRecordingsUrl($recordingParams));
262
263
        return new DeleteRecordingsResponse($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
    /* ____________________ INTERNAL CLASS METHODS ___________________ */
267
268
    /**
269
     * A private utility method used by other public methods to process XML responses.
270
     *
271
     * @param $url
272
     * @param  string                $xml
273
     * @return bool|SimpleXMLElement
274
     * @throws \Exception
275
     */
276
    private function processXmlResponse($url, $xml = '')
277
    {
278
        /*
279
        
280
        */
281
        if (extension_loaded('curl')) {
282
            $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...
283
            $timeout = 10;
284
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
285
            curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
286
            curl_setopt($ch, CURLOPT_URL, $url);
287
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
288
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
289
            if (!empty($xml)) {
290
                curl_setopt($ch, CURLOPT_HEADER, 0);
291
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
292
                curl_setopt($ch, CURLOPT_POST, 1);
293
                curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
294
                curl_setopt($ch, CURLOPT_HTTPHEADER, [
295
                    'Content-type: application/xml',
296
                    'Content-length: ' . strlen($xml),
297
                ]);
298
            }
299
            $data = curl_exec($ch);
300
            curl_close($ch);
301
302
            if ($data) {
303
                return new SimpleXMLElement($data);
304
            } else {
305
                return false;
306
            }
307
        }
308
        if (!empty($xml)) {
309
            throw new \Exception('Set xml, but curl does not installed.');
310
        }
311
312
        return simplexml_load_file($url);
313
    }
314
}
315