HHVM removal: Deprecate and simplify wfIsHHVM()
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 4ae9237..6396290 100644 (file)
@@ -518,7 +518,7 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
                }
        }
 
-       $defaultProtoWithoutSlashes = substr( $defaultProto, 0, -2 );
+       $defaultProtoWithoutSlashes = $defaultProto !== null ? substr( $defaultProto, 0, -2 ) : '';
 
        if ( substr( $url, 0, 2 ) == '//' ) {
                $url = $defaultProtoWithoutSlashes . $url;
@@ -1816,10 +1816,11 @@ function mimeTypeMatch( $type, $avail ) {
  *
  * @param array $cprefs Client's acceptable type list
  * @param array $sprefs Server's offered types
- * @return string
+ * @return string|null
  *
  * @todo FIXME: Doesn't handle params like 'text/plain; charset=UTF-8'
  * XXX: generalize to negotiate other stuff
+ * @todo The function appears unused. Is it worth to keep?
  */
 function wfNegotiateType( $cprefs, $sprefs ) {
        $combine = [];
@@ -1914,10 +1915,12 @@ function wfIsWindows() {
 /**
  * Check if we are running under HHVM
  *
+ * @deprecated since 1.34, HHVM is no longer supported
  * @return bool
  */
 function wfIsHHVM() {
-       return defined( 'HHVM_VERSION' );
+       // wfDeprecated( __FUNCTION__, '1.34' );
+       return false;
 }
 
 /**
@@ -2030,7 +2033,7 @@ function wfRecursiveRemoveDir( $dir ) {
  */
 function wfPercent( $nr, $acc = 2, $round = true ) {
        $ret = sprintf( "%.${acc}f", $nr );
-       return $round ? round( $ret, $acc ) . '%' : "$ret%";
+       return $round ? round( (float)$ret, $acc ) . '%' : "$ret%";
 }
 
 /**
@@ -2116,6 +2119,7 @@ function wfEscapeShellArg( ...$args ) {
  *     including errors from limit.sh
  *   - profileMethod: By default this function will profile based on the calling
  *     method. Set this to a string for an alternative method to profile from
+ * @phan-param array{duplicateStderr?:bool,profileMethod?:string} $options
  *
  * @return string Collected stdout as a string
  * @deprecated since 1.30 use class MediaWiki\Shell\Shell
@@ -2190,6 +2194,7 @@ function wfShellExecWithStderr( $cmd, &$retval = null, $environ = [], $limits =
  * @param array $options Associative array of options:
  *     'php': The path to the php executable
  *     'wrapper': Path to a PHP wrapper to handle the maintenance script
+ * @phan-param array{php?:string,wrapper?:string} $options
  * @return string
  */
 function wfShellWikiCmd( $script, array $parameters = [], array $options = [] ) {
@@ -2791,7 +2796,7 @@ function wfMemoryLimit( $newLimit ) {
 function wfTransactionalTimeLimit() {
        global $wgTransactionalTimeLimit;
 
-       $timeLimit = ini_get( 'max_execution_time' );
+       $timeLimit = (int)ini_get( 'max_execution_time' );
        // Note that CLI scripts use 0
        if ( $timeLimit > 0 && $wgTransactionalTimeLimit > $timeLimit ) {
                set_time_limit( $wgTransactionalTimeLimit );
@@ -2893,7 +2898,6 @@ function wfUnpack( $format, $data, $length = false ) {
        $result = unpack( $format, $data );
        Wikimedia\restoreWarnings();
 
-       // @phan-suppress-next-line PhanTypeComparisonFromArray Phan issue #3160
        if ( $result === false ) {
                // If it cannot extract the packed data.
                throw new MWException( "unpack could not unpack binary data" );