From e5444ea55a8000f0040044626e1efc0e99e4b6ac Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 15 Sep 2019 16:40:42 +0200 Subject: [PATCH] docs: Avoid some scalar juggling Phan can treat scalar types as non-interchangeable with `scalar_implicit_cast` set to false. This patch fixes some of those issues (which are in total >1000), namely the ones with alphabetic order < includes/actions. Change-Id: Ib1c6573ab899088bc319b9da9ceaffc850da3dbe --- includes/AjaxResponse.php | 4 ++-- includes/Autopromote.php | 4 ++-- includes/EditPage.php | 2 +- includes/GlobalFunctions.php | 4 ++-- includes/Linker.php | 4 ++-- includes/OutputPage.php | 14 +++++++------- includes/PHPVersionCheck.php | 4 ++-- includes/Permissions/PermissionManager.php | 2 +- includes/Revision/RevisionRecord.php | 2 +- includes/Revision/RevisionStoreRecord.php | 2 +- includes/Revision/SlotRoleHandler.php | 2 +- includes/Setup.php | 2 +- includes/Storage/PageEditStash.php | 4 ++-- includes/Xml.php | 6 +++--- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index 0664652a7e..faff021859 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -55,7 +55,7 @@ class AjaxResponse { /** * HTTP response code - * @var string $mResponseCode + * @var int|string $mResponseCode */ private $mResponseCode; @@ -114,7 +114,7 @@ class AjaxResponse { /** * Set the HTTP response code - * @param string $code + * @param int|string $code */ function setResponseCode( $code ) { $this->mResponseCode = $code; diff --git a/includes/Autopromote.php b/includes/Autopromote.php index 2156787886..f8f3c24a6a 100644 --- a/includes/Autopromote.php +++ b/includes/Autopromote.php @@ -187,10 +187,10 @@ class Autopromote { } return $user->getEditCount() >= $reqEditCount; case APCOND_AGE: - $age = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); + $age = time() - (int)wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); return $age >= $cond[1]; case APCOND_AGE_FROM_EDIT: - $age = time() - wfTimestampOrNull( TS_UNIX, $user->getFirstEditTimestamp() ); + $age = time() - (int)wfTimestampOrNull( TS_UNIX, $user->getFirstEditTimestamp() ); return $age >= $cond[1]; case APCOND_INGROUPS: $groups = array_slice( $cond, 1 ); diff --git a/includes/EditPage.php b/includes/EditPage.php index d047f6e2f8..10eea89001 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1188,7 +1188,7 @@ class EditPage { /** * @param Content|null $def_content The default value to return * - * @return Content|null Content on success, $def_content for invalid sections + * @return Content|false|null Content on success, $def_content for invalid sections * * @since 1.21 */ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 2ed385e225..125b917caa 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2031,7 +2031,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%"; } /** @@ -2794,7 +2794,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 ); diff --git a/includes/Linker.php b/includes/Linker.php index 324b1f5f4b..864019dcc7 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -891,7 +891,7 @@ class Linker { * Make user link (or user contributions for unregistered users) * @param int $userId User id in database. * @param string $userName User name in database. - * @param string $altUserName Text to display instead of the user name (optional) + * @param string|false $altUserName Text to display instead of the user name (optional) * @return string HTML fragment * @since 1.16.3. $altUserName was added in 1.19. */ @@ -1912,7 +1912,7 @@ class Linker { * @since 1.16.3. $context added in 1.20. $editCount added in 1.21 * @param Revision $rev * @param IContextSource|null $context Context to use or null for the main context. - * @param int $editCount Number of edits that would be reverted + * @param int|false $editCount Number of edits that would be reverted * @return string HTML fragment */ public static function buildRollbackLink( $rev, IContextSource $context = null, diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c9b4193f1a..acf2d25532 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -50,7 +50,7 @@ class OutputPage extends ContextSource { /** @var array */ protected $mLinktags = []; - /** @var bool */ + /** @var string|bool */ protected $mCanonicalUrl = false; /** @@ -2147,7 +2147,7 @@ class OutputPage extends ContextSource { } /** - * Get TTL in [$minTTL,$maxTTL] in pass it to lowerCdnMaxage() + * Get TTL in [$minTTL,$maxTTL] and pass it to lowerCdnMaxage() * * This sets and returns $minTTL if $mtime is false or null. Otherwise, * the TTL is higher the older the $mtime timestamp is. Essentially, the @@ -2163,10 +2163,10 @@ class OutputPage extends ContextSource { $maxTTL = $maxTTL ?: $this->getConfig()->get( 'CdnMaxAge' ); if ( $mtime === null || $mtime === false ) { - return $minTTL; // entity does not exist + return; // entity does not exist } - $age = MWTimestamp::time() - wfTimestamp( TS_UNIX, $mtime ); + $age = MWTimestamp::time() - (int)wfTimestamp( TS_UNIX, $mtime ); $adaptiveTTL = max( 0.9 * $age, $minTTL ); $adaptiveTTL = min( $adaptiveTTL, $maxTTL ); @@ -2270,7 +2270,7 @@ class OutputPage extends ContextSource { /** * Return a Link: header. Based on the values of $mLinkHeader. * - * @return string + * @return string|false */ public function getLinkHeader() { if ( !$this->mLinkHeader ) { @@ -2602,7 +2602,7 @@ class OutputPage extends ContextSource { * and optionally an custom HTML title (content of the "" tag). * * @param string|Message $pageTitle Will be passed directly to setPageTitle() - * @param string|Message $htmlTitle Will be passed directly to setHTMLTitle(); + * @param string|Message|false $htmlTitle Will be passed directly to setHTMLTitle(); * optional, if not passed the "<title>" attribute will be * based on $pageTitle */ @@ -3283,7 +3283,7 @@ class OutputPage extends ContextSource { $vars['wgUserId'] = $user->getId(); $vars['wgUserEditCount'] = $user->getEditCount(); $userReg = $user->getRegistration(); - $vars['wgUserRegistration'] = $userReg ? wfTimestamp( TS_UNIX, $userReg ) * 1000 : null; + $vars['wgUserRegistration'] = $userReg ? (int)wfTimestamp( TS_UNIX, $userReg ) * 1000 : null; // Get the revision ID of the oldest new message on the user's talk // page. This can be used for constructing new message alerts on // the client side. diff --git a/includes/PHPVersionCheck.php b/includes/PHPVersionCheck.php index e726729481..55b45984f6 100644 --- a/includes/PHPVersionCheck.php +++ b/includes/PHPVersionCheck.php @@ -77,8 +77,8 @@ class PHPVersionCheck { /** * Return the version of the installed PHP implementation. * - * @param string $impl By default, the function returns the info of the currently installed PHP - * implementation. Using this parameter the caller can decide, what version info will be + * @param string|false $impl By default, the function returns the info of the currently installed + * PHP implementation. Using this parameter the caller can decide, what version info will be * returned. Valid values: HHVM, PHP * @return array An array of information about the PHP implementation, containing: * - 'version': The version of the PHP implementation (specific to the implementation, not diff --git a/includes/Permissions/PermissionManager.php b/includes/Permissions/PermissionManager.php index 0a8e515a32..ef6b8ac5a9 100644 --- a/includes/Permissions/PermissionManager.php +++ b/includes/Permissions/PermissionManager.php @@ -97,7 +97,7 @@ class PermissionManager { */ private $temporaryUserRights = []; - /** @var string[] Cached rights for isEveryoneAllowed */ + /** @var bool[] Cached rights for isEveryoneAllowed, [ right => allowed ] */ private $cachedRights = []; /** diff --git a/includes/Revision/RevisionRecord.php b/includes/Revision/RevisionRecord.php index 759180a984..cf353718f8 100644 --- a/includes/Revision/RevisionRecord.php +++ b/includes/Revision/RevisionRecord.php @@ -59,7 +59,7 @@ abstract class RevisionRecord { const FOR_THIS_USER = 2; const RAW = 3; - /** @var string Wiki ID; false means the current wiki */ + /** @var string|false Wiki ID; false means the current wiki */ protected $mWiki = false; /** @var int|null */ protected $mId; diff --git a/includes/Revision/RevisionStoreRecord.php b/includes/Revision/RevisionStoreRecord.php index 469e494a3d..dabf62bb0b 100644 --- a/includes/Revision/RevisionStoreRecord.php +++ b/includes/Revision/RevisionStoreRecord.php @@ -151,7 +151,7 @@ class RevisionStoreRecord extends RevisionRecord { /** * @throws RevisionAccessException if the size was unknown and could not be calculated. - * @return string The nominal revision size, never null. May be computed on the fly. + * @return int The nominal revision size, never null. May be computed on the fly. */ public function getSize() { // If length is null, calculate and remember it (potentially SLOW!). diff --git a/includes/Revision/SlotRoleHandler.php b/includes/Revision/SlotRoleHandler.php index 85b4c5ab34..7c2623bebd 100644 --- a/includes/Revision/SlotRoleHandler.php +++ b/includes/Revision/SlotRoleHandler.php @@ -150,7 +150,7 @@ class SlotRoleHandler { * * The default implementation always returns false. * - * @return string + * @return bool */ public function supportsArticleCount() { return false; diff --git a/includes/Setup.php b/includes/Setup.php index 6838c37260..d450bdd33c 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -728,7 +728,7 @@ if ( is_null( $wgLocaltimezone ) ) { date_default_timezone_set( $wgLocaltimezone ); if ( is_null( $wgLocalTZoffset ) ) { - $wgLocalTZoffset = date( 'Z' ) / 60; + $wgLocalTZoffset = (int)date( 'Z' ) / 60; } // The part after the System| is ignored, but rest of MW fills it // out as the local offset. diff --git a/includes/Storage/PageEditStash.php b/includes/Storage/PageEditStash.php index a0ef07d651..826d52675b 100644 --- a/includes/Storage/PageEditStash.php +++ b/includes/Storage/PageEditStash.php @@ -231,7 +231,7 @@ class PageEditStash { return false; } - $age = time() - wfTimestamp( TS_UNIX, $editInfo->output->getCacheTime() ); + $age = time() - (int)wfTimestamp( TS_UNIX, $editInfo->output->getCacheTime() ); $context['age'] = $age; $isCacheUsable = true; @@ -450,7 +450,7 @@ class PageEditStash { ) { // If an item is renewed, mind the cache TTL determined by config and parser functions. // Put an upper limit on the TTL for sanity to avoid extreme template/file staleness. - $age = time() - wfTimestamp( TS_UNIX, $parserOutput->getCacheTime() ); + $age = time() - (int)wfTimestamp( TS_UNIX, $parserOutput->getCacheTime() ); $ttl = min( $parserOutput->getCacheExpiry() - $age, self::MAX_CACHE_TTL ); // Avoid extremely stale user signature timestamps (T84843) if ( $parserOutput->getFlag( 'user-signature' ) ) { diff --git a/includes/Xml.php b/includes/Xml.php index febf03e7a2..b368a131ca 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -266,7 +266,7 @@ class Xml { /** * Convenience function to build an HTML text input field * @param string $name Value of the name attribute - * @param int $size Value of the size attribute + * @param int|false $size Value of the size attribute * @param mixed $value Value of the value attribute * @param array $attribs Other attributes * @return string HTML @@ -289,7 +289,7 @@ class Xml { /** * Convenience function to build an HTML password input field * @param string $name Value of the name attribute - * @param int $size Value of the size attribute + * @param int|false $size Value of the size attribute * @param mixed $value Value of the value attribute * @param array $attribs Other attributes * @return string HTML @@ -600,7 +600,7 @@ class Xml { * * @param string|bool $legend Legend of the fieldset. If evaluates to false, * legend is not added. - * @param string $content Pre-escaped content for the fieldset. If false, + * @param string|false $content Pre-escaped content for the fieldset. If false, * only open fieldset is returned. * @param array $attribs Any attributes to fieldset-element. * -- 2.20.1