| Total Complexity | 47 |
| Total Lines | 503 |
| Duplicated Lines | 0 % |
| Changes | 17 | ||
| Bugs | 2 | Features | 0 |
Complex classes like BigBlueButton 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.
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 BigBlueButton, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 57 | class BigBlueButton |
||
| 58 | { |
||
| 59 | protected $securitySecret; |
||
| 60 | protected $bbbServerBaseUrl; |
||
| 61 | protected $urlBuilder; |
||
| 62 | protected $jSessionId; |
||
| 63 | protected $timeOut = 10; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * BigBlueButton constructor. |
||
| 67 | * |
||
| 68 | * @param null $baseUrl |
||
|
|
|||
| 69 | * @param null $secret |
||
| 70 | * @param null|mixed $opts |
||
| 71 | */ |
||
| 72 | public function __construct($baseUrl = null, $secret = null, $opts = null) |
||
| 73 | { |
||
| 74 | // Keeping backward compatibility with older deployed versions |
||
| 75 | // BBB_SECRET is the new variable name and have higher priority against the old named BBB_SECURITY_SALT |
||
| 76 | $this->securitySecret = $secret ?: getenv('BBB_SECRET') ?: getenv('BBB_SECURITY_SALT'); |
||
| 77 | $this->bbbServerBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL'); |
||
| 78 | $this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl); |
||
| 79 | $this->curlopts = $opts['curl'] ?? []; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @throws \RuntimeException |
||
| 84 | * |
||
| 85 | * @return ApiVersionResponse |
||
| 86 | */ |
||
| 87 | public function getApiVersion() |
||
| 88 | { |
||
| 89 | $xml = $this->processXmlResponse($this->urlBuilder->buildUrl()); |
||
| 90 | |||
| 91 | return new ApiVersionResponse($xml); |
||
| 92 | } |
||
| 93 | |||
| 94 | // __________________ BBB ADMINISTRATION METHODS _________________ |
||
| 95 | /* The methods in the following section support the following categories of the BBB API: |
||
| 96 | -- create |
||
| 97 | -- join |
||
| 98 | -- end |
||
| 99 | -- insertDocument |
||
| 100 | */ |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param CreateMeetingParameters $createMeetingParams |
||
| 104 | * |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public function getCreateMeetingUrl($createMeetingParams) |
||
| 108 | { |
||
| 109 | return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery()); |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param CreateMeetingParameters $createMeetingParams |
||
| 114 | * |
||
| 115 | * @throws \RuntimeException |
||
| 116 | * |
||
| 117 | * @return CreateMeetingResponse |
||
| 118 | */ |
||
| 119 | public function createMeeting($createMeetingParams) |
||
| 120 | { |
||
| 121 | $xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML()); |
||
| 122 | |||
| 123 | return new CreateMeetingResponse($xml); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param $joinMeetingParams JoinMeetingParameters |
||
| 128 | * |
||
| 129 | * @return string |
||
| 130 | */ |
||
| 131 | public function getJoinMeetingURL($joinMeetingParams) |
||
| 132 | { |
||
| 133 | return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery()); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param $joinMeetingParams JoinMeetingParameters |
||
| 138 | * |
||
| 139 | * @throws \RuntimeException |
||
| 140 | * |
||
| 141 | * @return JoinMeetingResponse |
||
| 142 | */ |
||
| 143 | public function joinMeeting($joinMeetingParams) |
||
| 144 | { |
||
| 145 | $xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams)); |
||
| 146 | |||
| 147 | return new JoinMeetingResponse($xml); |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param $endParams EndMeetingParameters |
||
| 152 | * |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | public function getEndMeetingURL($endParams) |
||
| 156 | { |
||
| 157 | return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery()); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param $endParams EndMeetingParameters |
||
| 162 | * |
||
| 163 | * @throws \RuntimeException |
||
| 164 | * |
||
| 165 | * @return EndMeetingResponse |
||
| 166 | * */ |
||
| 167 | public function endMeeting($endParams) |
||
| 168 | { |
||
| 169 | $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams)); |
||
| 170 | |||
| 171 | return new EndMeetingResponse($xml); |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param CreateMeetingParameters $createMeetingParams |
||
| 176 | * |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | public function getInsertDocumentUrl($createMeetingParams) |
||
| 180 | { |
||
| 181 | return $this->urlBuilder->buildUrl(ApiMethod::INSERT_DOCUMENT, $createMeetingParams->getHTTPQuery()); |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param InsertDocumentParameters $insertDocumentParams |
||
| 186 | * |
||
| 187 | * @throws \RuntimeException |
||
| 188 | * |
||
| 189 | * @return InsertDocumentResponse |
||
| 190 | */ |
||
| 191 | public function insertDocument($insertDocumentParams) |
||
| 192 | { |
||
| 193 | $xml = $this->processXmlResponse($this->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML()); |
||
| 194 | |||
| 195 | return new CreateMeetingResponse($xml); |
||
| 196 | } |
||
| 197 | |||
| 198 | // __________________ BBB MONITORING METHODS _________________ |
||
| 199 | /* The methods in the following section support the following categories of the BBB API: |
||
| 200 | -- isMeetingRunning |
||
| 201 | -- getMeetings |
||
| 202 | -- getMeetingInfo |
||
| 203 | */ |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param $meetingParams IsMeetingRunningParameters |
||
| 207 | * |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | public function getIsMeetingRunningUrl($meetingParams) |
||
| 211 | { |
||
| 212 | return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery()); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param $meetingParams |
||
| 217 | * |
||
| 218 | * @throws \RuntimeException |
||
| 219 | * |
||
| 220 | * @return IsMeetingRunningResponse |
||
| 221 | */ |
||
| 222 | public function isMeetingRunning($meetingParams) |
||
| 223 | { |
||
| 224 | $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams)); |
||
| 225 | |||
| 226 | return new IsMeetingRunningResponse($xml); |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | public function getMeetingsUrl() |
||
| 233 | { |
||
| 234 | return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS); |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @throws \RuntimeException |
||
| 239 | * |
||
| 240 | * @return GetMeetingsResponse |
||
| 241 | */ |
||
| 242 | public function getMeetings() |
||
| 243 | { |
||
| 244 | $xml = $this->processXmlResponse($this->getMeetingsUrl()); |
||
| 245 | |||
| 246 | return new GetMeetingsResponse($xml); |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param $meetingParams GetMeetingInfoParameters |
||
| 251 | * |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | public function getMeetingInfoUrl($meetingParams) |
||
| 255 | { |
||
| 256 | return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery()); |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param $meetingParams GetMeetingInfoParameters |
||
| 261 | * |
||
| 262 | * @throws \RuntimeException |
||
| 263 | * |
||
| 264 | * @return GetMeetingInfoResponse |
||
| 265 | */ |
||
| 266 | public function getMeetingInfo($meetingParams) |
||
| 267 | { |
||
| 268 | $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams)); |
||
| 269 | |||
| 270 | return new GetMeetingInfoResponse($xml); |
||
| 271 | } |
||
| 272 | |||
| 273 | // __________________ BBB RECORDING METHODS _________________ |
||
| 274 | /* The methods in the following section support the following categories of the BBB API: |
||
| 275 | -- getRecordings |
||
| 276 | -- publishRecordings |
||
| 277 | -- deleteRecordings |
||
| 278 | */ |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @param $recordingsParams GetRecordingsParameters |
||
| 282 | * |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | public function getRecordingsUrl($recordingsParams) |
||
| 286 | { |
||
| 287 | return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery()); |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @param $recordingParams |
||
| 292 | * |
||
| 293 | * @throws \RuntimeException |
||
| 294 | * |
||
| 295 | * @return GetRecordingsResponse |
||
| 296 | */ |
||
| 297 | public function getRecordings($recordingParams) |
||
| 298 | { |
||
| 299 | $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams)); |
||
| 300 | |||
| 301 | return new GetRecordingsResponse($xml); |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @param $recordingParams PublishRecordingsParameters |
||
| 306 | * |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | public function getPublishRecordingsUrl($recordingParams) |
||
| 310 | { |
||
| 311 | return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery()); |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param $recordingParams PublishRecordingsParameters |
||
| 316 | * |
||
| 317 | * @throws \RuntimeException |
||
| 318 | * |
||
| 319 | * @return PublishRecordingsResponse |
||
| 320 | */ |
||
| 321 | public function publishRecordings($recordingParams) |
||
| 322 | { |
||
| 323 | $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams)); |
||
| 324 | |||
| 325 | return new PublishRecordingsResponse($xml); |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @param $recordingParams DeleteRecordingsParameters |
||
| 330 | * |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getDeleteRecordingsUrl($recordingParams) |
||
| 334 | { |
||
| 335 | return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery()); |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param $recordingParams DeleteRecordingsParameters |
||
| 340 | * |
||
| 341 | * @throws \RuntimeException |
||
| 342 | * |
||
| 343 | * @return DeleteRecordingsResponse |
||
| 344 | */ |
||
| 345 | public function deleteRecordings($recordingParams) |
||
| 346 | { |
||
| 347 | $xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams)); |
||
| 348 | |||
| 349 | return new DeleteRecordingsResponse($xml); |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @param $recordingParams UpdateRecordingsParameters |
||
| 354 | * |
||
| 355 | * @return string |
||
| 356 | */ |
||
| 357 | public function getUpdateRecordingsUrl($recordingParams) |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param $recordingParams UpdateRecordingsParameters |
||
| 364 | * |
||
| 365 | * @throws \RuntimeException |
||
| 366 | * |
||
| 367 | * @return UpdateRecordingsResponse |
||
| 368 | */ |
||
| 369 | public function updateRecordings($recordingParams) |
||
| 370 | { |
||
| 371 | $xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams)); |
||
| 372 | |||
| 373 | return new UpdateRecordingsResponse($xml); |
||
| 374 | } |
||
| 375 | |||
| 376 | // ____________________ WEB HOOKS METHODS ___________________ |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param $hookCreateParams HooksCreateParameters |
||
| 380 | * |
||
| 381 | * @return string |
||
| 382 | */ |
||
| 383 | public function getHooksCreateUrl($hookCreateParams) |
||
| 384 | { |
||
| 385 | return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery()); |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @param $hookCreateParams |
||
| 390 | * |
||
| 391 | * @return HooksCreateResponse |
||
| 392 | */ |
||
| 393 | public function hooksCreate($hookCreateParams) |
||
| 394 | { |
||
| 395 | $xml = $this->processXmlResponse($this->getHooksCreateUrl($hookCreateParams)); |
||
| 396 | |||
| 397 | return new HooksCreateResponse($xml); |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return string |
||
| 402 | */ |
||
| 403 | public function getHooksListUrl() |
||
| 404 | { |
||
| 405 | return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_LIST); |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @return HooksListResponse |
||
| 410 | */ |
||
| 411 | public function hooksList() |
||
| 412 | { |
||
| 413 | $xml = $this->processXmlResponse($this->getHooksListUrl()); |
||
| 414 | |||
| 415 | return new HooksListResponse($xml); |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param $hooksDestroyParams HooksDestroyParameters |
||
| 420 | * |
||
| 421 | * @return string |
||
| 422 | */ |
||
| 423 | public function getHooksDestroyUrl($hooksDestroyParams) |
||
| 424 | { |
||
| 425 | return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery()); |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @param $hooksDestroyParams |
||
| 430 | * |
||
| 431 | * @return HooksDestroyResponse |
||
| 432 | */ |
||
| 433 | public function hooksDestroy($hooksDestroyParams) |
||
| 434 | { |
||
| 435 | $xml = $this->processXmlResponse($this->getHooksDestroyUrl($hooksDestroyParams)); |
||
| 436 | |||
| 437 | return new HooksDestroyResponse($xml); |
||
| 438 | } |
||
| 439 | |||
| 440 | // ____________________ SPECIAL METHODS ___________________ |
||
| 441 | /** |
||
| 442 | * @return string |
||
| 443 | */ |
||
| 444 | public function getJSessionId() |
||
| 445 | { |
||
| 446 | return $this->jSessionId; |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @param string $jSessionId |
||
| 451 | */ |
||
| 452 | public function setJSessionId($jSessionId) |
||
| 453 | { |
||
| 454 | $this->jSessionId = $jSessionId; |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @param array $curlopts |
||
| 459 | */ |
||
| 460 | public function setCurlOpts($curlopts) |
||
| 461 | { |
||
| 462 | $this->curlopts = $curlopts; |
||
| 463 | } |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Set Curl Timeout (Optional), Default 10 Seconds. |
||
| 467 | * |
||
| 468 | * @param int $TimeOutInSeconds |
||
| 469 | * |
||
| 470 | * @return static |
||
| 471 | */ |
||
| 472 | public function setTimeOut($TimeOutInSeconds) |
||
| 473 | { |
||
| 474 | $this->timeOut = $TimeOutInSeconds; |
||
| 475 | |||
| 476 | return $this; |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Public accessor for buildUrl. |
||
| 481 | * |
||
| 482 | * @param string $method |
||
| 483 | * @param string $params |
||
| 484 | * @param bool $append |
||
| 485 | * |
||
| 486 | * @return string |
||
| 487 | */ |
||
| 488 | public function buildUrl($method = '', $params = '', $append = true) |
||
| 491 | } |
||
| 492 | |||
| 493 | // ____________________ INTERNAL CLASS METHODS ___________________ |
||
| 494 | |||
| 495 | /** |
||
| 496 | * A private utility method used by other public methods to process XML responses. |
||
| 497 | * |
||
| 498 | * @param string $url |
||
| 499 | * @param string $payload |
||
| 500 | * @param string $contentType |
||
| 501 | * |
||
| 502 | * @throws \RuntimeException |
||
| 503 | * |
||
| 504 | * @return SimpleXMLElement |
||
| 505 | */ |
||
| 506 | private function processXmlResponse($url, $payload = '', $contentType = 'application/xml') |
||
| 507 | { |
||
| 508 | if (extension_loaded('curl')) { |
||
| 509 | $ch = curl_init(); |
||
| 510 | if (!$ch) { |
||
| 511 | throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch)); |
||
| 560 | } |
||
| 561 | } |
||
| 562 |