@@ -94,13 +94,13 @@ public function __construct(?string $baseUrl = null, ?string $secret = null, ?ar
9494 {
9595 // Provide an early error message if configuration is wrong
9696 if (is_null ($ baseUrl ) && false === getenv ('BBB_SERVER_BASE_URL ' )) {
97- throw new \RuntimeException ('No BBB-Server-Url found! Please provide it either in constructor ' .
98- "(1st argument) or by environment variable 'BBB_SERVER_BASE_URL'! " );
97+ throw new \RuntimeException ('No BBB-Server-Url found! Please provide it either in constructor '
98+ . "(1st argument) or by environment variable 'BBB_SERVER_BASE_URL'! " );
9999 }
100100
101101 if (is_null ($ secret ) && false === getenv ('BBB_SECRET ' ) && false === getenv ('BBB_SECURITY_SALT ' )) {
102- throw new \RuntimeException ('No BBB-Secret (or BBB-Salt) found! Please provide it either in constructor ' .
103- "(2nd argument) or by environment variable 'BBB_SECRET' (or 'BBB_SECURITY_SALT')! " );
102+ throw new \RuntimeException ('No BBB-Secret (or BBB-Salt) found! Please provide it either in constructor '
103+ . "(2nd argument) or by environment variable 'BBB_SECRET' (or 'BBB_SECURITY_SALT')! " );
104104 }
105105
106106 // Keeping backward compatibility with older deployed versions
@@ -302,11 +302,9 @@ public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): str
302302 }
303303
304304 /**
305- * @param mixed $recordingParams
306- *
307305 * @throws BadResponseException|\RuntimeException
308306 */
309- public function getRecordings ($ recordingParams ): GetRecordingsResponse
307+ public function getRecordings (GetRecordingsParameters $ recordingParams ): GetRecordingsResponse
310308 {
311309 $ xml = $ this ->processXmlResponse ($ this ->getUrlBuilder ()->getRecordingsUrl ($ recordingParams ));
312310
@@ -414,11 +412,9 @@ public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): stri
414412 }
415413
416414 /**
417- * @param mixed $hookCreateParams
418- *
419415 * @throws BadResponseException
420416 */
421- public function hooksCreate ($ hookCreateParams ): HooksCreateResponse
417+ public function hooksCreate (HooksCreateParameters $ hookCreateParams ): HooksCreateResponse
422418 {
423419 $ xml = $ this ->processXmlResponse ($ this ->getUrlBuilder ()->getHooksCreateUrl ($ hookCreateParams ));
424420
@@ -452,11 +448,9 @@ public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams):
452448 }
453449
454450 /**
455- * @param mixed $hooksDestroyParams
456- *
457451 * @throws BadResponseException
458452 */
459- public function hooksDestroy ($ hooksDestroyParams ): HooksDestroyResponse
453+ public function hooksDestroy (HooksDestroyParameters $ hooksDestroyParams ): HooksDestroyResponse
460454 {
461455 $ xml = $ this ->processXmlResponse ($ this ->getUrlBuilder ()->getHooksDestroyUrl ($ hooksDestroyParams ));
462456
@@ -538,10 +532,9 @@ private function sendRequest(string $url, string $payload = '', string $contentT
538532 $ ch = curl_init ();
539533 $ cookieFile = tmpfile ();
540534
541- if (! $ ch ) { // @phpstan-ignore-line
542- throw new \RuntimeException ('Unhandled curl error: ' . curl_error ( $ ch ) );
535+ if (false === $ ch ) {
536+ throw new \RuntimeException ('Failed to initialize cURL ' );
543537 }
544-
545538 // JSESSIONID
546539 if ($ cookieFile ) {
547540 $ cookieFilePath = stream_get_meta_data ($ cookieFile )['uri ' ];
@@ -550,26 +543,34 @@ private function sendRequest(string $url, string $payload = '', string $contentT
550543 curl_setopt ($ ch , CURLOPT_COOKIEFILE , $ cookieFilePath );
551544 curl_setopt ($ ch , CURLOPT_COOKIEJAR , $ cookieFilePath );
552545
553- if ($ cookies ) {
554- if (false !== mb_strpos ($ cookies , 'JSESSIONID ' )) {
555- preg_match ('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/ ' , $ cookies , $ output_array );
556- $ this ->setJSessionId ($ output_array ['JSESSIONID ' ]);
546+ if ($ cookies && false !== mb_strpos ($ cookies , 'JSESSIONID ' )) {
547+ if (preg_match ('/JSESSIONID\s*(?<JSESSIONID>[^;\s]*)/ ' , $ cookies , $ output_array )) {
548+ // No need for isset() - we know JSESSIONID exists if preg_match returns true
549+ $ this ->setJSessionId (mb_trim ($ output_array ['JSESSIONID ' ]));
550+ } else {
551+ throw new \RuntimeException ('JSESSIONID found but could not be extracted ' );
557552 }
558553 }
559554 }
560555
556+ // Initialise headers array with mandatory Content-type
557+ $ headers = [
558+ 'Content-type: ' . $ contentType ,
559+ ];
560+
561561 // PAYLOAD
562562 if (!empty ($ payload )) {
563563 curl_setopt ($ ch , CURLOPT_HEADER , 0 );
564564 curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'POST ' );
565565 curl_setopt ($ ch , CURLOPT_POST , 1 );
566566 curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ payload );
567- curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
568- 'Content-type: ' . $ contentType ,
569- 'Content-length: ' . strlen ($ payload ),
570- ]);
567+ // Add Content-length header if payload is present
568+ $ headers [] = 'Content-length: ' . strlen ($ payload );
571569 }
572570
571+ // Set HTTP headers
572+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
573+
573574 // OTHERS
574575 foreach ($ this ->curlOpts as $ opt => $ value ) {
575576 curl_setopt ($ ch , $ opt , $ value );
0 commit comments