@@ -270,7 +270,7 @@ protected function connect()
270270 $ options ['ssl ' ]['peer_name ' ] = $ reqHost ;
271271
272272 } else {
273- $ options ['ssl ' ][substr ($ name , 4 )] = $ value ;
273+ $ options ['ssl ' ][( string ) substr ($ name , 4 )] = $ value ;
274274 }
275275 }
276276 }
@@ -504,18 +504,18 @@ protected function shouldUseServerDigestAuth(HTTP_Request2_Response $response)
504504
505505 $ url = $ this ->request ->getUrl ();
506506 $ scheme = (string )$ url ->getScheme ();
507- $ host = $ scheme . ':// ' . $ url ->getHost ();
507+ $ host = $ scheme . ':// ' . ( string ) $ url ->getHost ();
508508 if ($ port = $ url ->getPort ()) {
509509 if ((0 === strcasecmp ($ scheme , 'http ' ) && 80 != $ port )
510510 || (0 === strcasecmp ($ scheme , 'https ' ) && 443 != $ port )
511511 ) {
512- $ host .= ': ' . $ port ;
512+ $ host .= ': ' . ( string ) $ port ;
513513 }
514514 }
515515
516516 if (!empty ($ challenge ['domain ' ])) {
517517 $ prefixes = [];
518- foreach (preg_split ('/ \\s+/ ' , $ challenge ['domain ' ]) as $ prefix ) {
518+ foreach (preg_split ('/ \\s+/ ' , $ challenge ['domain ' ]) ?: [] as $ prefix ) {
519519 // don't bother with different servers
520520 if ('/ ' == substr ($ prefix , 0 , 1 )) {
521521 $ prefixes [] = $ host . $ prefix ;
@@ -699,7 +699,7 @@ protected function createDigestResponse($user, $password, $url, &$challenge)
699699 if (false !== ($ q = strpos ($ url , '? ' ))
700700 && $ this ->request ->getConfig ('digest_compat_ie ' )
701701 ) {
702- $ url = substr ($ url , 0 , $ q );
702+ $ url = ( string ) substr ($ url , 0 , $ q );
703703 }
704704
705705 $ a1 = md5 ($ user . ': ' . $ challenge ['realm ' ] . ': ' . $ password );
@@ -713,7 +713,7 @@ protected function createDigestResponse($user, $password, $url, &$challenge)
713713 if (empty ($ challenge ['nc ' ])) {
714714 $ challenge ['nc ' ] = 1 ;
715715 }
716- $ nc = sprintf ('%08x ' , $ challenge ['nc ' ]++);
716+ $ nc = ( string ) sprintf ('%08x ' , $ challenge ['nc ' ]++);
717717 $ digest = md5 (
718718 $ a1 . ': ' . $ challenge ['nonce ' ] . ': ' . $ nc . ': ' .
719719 $ challenge ['cnonce ' ] . ':auth: ' . $ a2
@@ -756,10 +756,9 @@ protected function addAuthorizationHeader(&$headers, $requestHost, $requestUrl)
756756
757757 case HTTP_Request2::AUTH_DIGEST :
758758 unset($ this ->serverChallenge );
759- $ fullUrl = ('/ ' == $ requestUrl [0 ])?
760- $ this ->request ->getUrl ()->getScheme () . ':// ' .
761- $ requestHost . $ requestUrl :
762- $ requestUrl ;
759+ $ fullUrl = '/ ' == $ requestUrl [0 ]
760+ ? (string )$ this ->request ->getUrl ()->getScheme () . ':// ' . $ requestHost . $ requestUrl
761+ : $ requestUrl ;
763762 foreach (array_keys (self ::$ challenges ) as $ key ) {
764763 if ($ key == substr ($ fullUrl , 0 , strlen ($ key ))) {
765764 $ headers ['authorization ' ] = $ this ->createDigestResponse (
@@ -841,9 +840,10 @@ protected function prepareHeaders()
841840 $ connect = HTTP_Request2::METHOD_CONNECT == $ this ->request ->getMethod ();
842841 $ host = (string )$ url ->getHost ();
843842
844- $ defaultPort = 0 === strcasecmp ((string )$ url ->getScheme (), 'https ' )? 443 : 80 ;
845- if (($ port = $ url ->getPort ()) && $ port != $ defaultPort || $ connect ) {
846- $ host .= ': ' . (empty ($ port )? $ defaultPort : $ port );
843+ $ customPort = (string )$ url ->getPort ();
844+ $ defaultPort = 0 === strcasecmp ((string )$ url ->getScheme (), 'https ' ) ? '443 ' : '80 ' ;
845+ if ('' !== $ customPort && $ defaultPort !== $ customPort || $ connect ) {
846+ $ host .= ': ' . ($ customPort ?: $ defaultPort );
847847 }
848848 // Do not overwrite explicitly set 'Host' header, see bug #16146
849849 if (!isset ($ headers ['host ' ])) {
@@ -860,11 +860,11 @@ protected function prepareHeaders()
860860 ) {
861861 $ requestUrl = '' ;
862862 } else {
863- $ requestUrl = $ url ->getScheme () . ':// ' . $ host ;
863+ $ requestUrl = ( string ) $ url ->getScheme () . ':// ' . $ host ;
864864 }
865- $ path = $ url ->getPath ();
866- $ query = $ url ->getQuery ();
867- $ requestUrl .= (empty ( $ path) ? '/ ' : $ path ) . (empty ( $ query) ? '' : '? ' . $ query );
865+ $ path = ( string ) $ url ->getPath ();
866+ $ query = ( string ) $ url ->getQuery ();
867+ $ requestUrl .= ('' === $ path ? '/ ' : $ path ) . ('' === $ query ? '' : '? ' . $ query );
868868 }
869869
870870 if ('1.1 ' == $ this ->request ->getConfig ('protocol_version ' )
@@ -990,9 +990,9 @@ protected function writeBody()
990990 $ chunked = isset ($ headers ['transfer-encoding ' ]);
991991 while ($ position < $ this ->contentLength ) {
992992 if (is_string ($ this ->requestBody )) {
993- $ str = substr ($ this ->requestBody , $ position , $ bufferSize );
993+ $ str = ( string ) substr ($ this ->requestBody , $ position , $ bufferSize );
994994 } elseif (is_resource ($ this ->requestBody )) {
995- $ str = fread ($ this ->requestBody , $ bufferSize );
995+ $ str = ( string ) fread ($ this ->requestBody , $ bufferSize );
996996 } else {
997997 $ str = $ this ->requestBody ->read ($ bufferSize );
998998 }
0 commit comments