From 02b18ba4cd0a4f0c23d453a7a3fd491bf0854582 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 7 Apr 2019 00:11:39 -0700 Subject: [PATCH] Fix/suppress phan errors related to arrays (#11) Change-Id: Ie5c05fbc88c51d493bc1462005d2f8dde5f72101 --- .phan/config.php | 4 ---- includes/debug/DeprecationHelper.php | 2 +- includes/libs/objectcache/WinCacheBagOStuff.php | 6 ++++++ includes/specials/SpecialEmailuser.php | 3 ++- includes/user/User.php | 6 ++++++ languages/Language.php | 1 + 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index c754480e87..12e723d469 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -97,12 +97,8 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanTypeArraySuspiciousNullable", // approximate error count: 26 "PhanTypeComparisonFromArray", - // approximate error count: 2 - "PhanTypeComparisonToArray", // approximate error count: 63 "PhanTypeInvalidDimOffset", - // approximate error count: 6 - "PhanTypeInvalidExpressionArrayDestructuring", // approximate error count: 7 "PhanTypeInvalidLeftOperandOfIntegerOp", // approximate error count: 2 diff --git a/includes/debug/DeprecationHelper.php b/includes/debug/DeprecationHelper.php index cd78005a65..46809e3837 100644 --- a/includes/debug/DeprecationHelper.php +++ b/includes/debug/DeprecationHelper.php @@ -50,7 +50,7 @@ trait DeprecationHelper { * the name of the class defining the property, is the MediaWiki component * (extension, skin etc.) for use in the deprecation warning) or null if it is MediaWiki. * E.g. [ 'mNewRev' => [ '1.32', 'DifferenceEngine', null ] - * @var string[] + * @var string[][] */ protected $deprecatedPublicProperties = []; diff --git a/includes/libs/objectcache/WinCacheBagOStuff.php b/includes/libs/objectcache/WinCacheBagOStuff.php index 818f6f1dc2..8c419b22cd 100644 --- a/includes/libs/objectcache/WinCacheBagOStuff.php +++ b/includes/libs/objectcache/WinCacheBagOStuff.php @@ -70,12 +70,18 @@ class WinCacheBagOStuff extends BagOStuff { public function set( $key, $value, $expire = 0, $flags = 0 ) { $result = wincache_ucache_set( $key, serialize( $value ), $expire ); + // false positive, wincache_ucache_set returns an empty array + // in some circumstances. + // @phan-suppress-next-line PhanTypeComparisonToArray return ( $result === [] || $result === true ); } public function add( $key, $value, $exptime = 0, $flags = 0 ) { $result = wincache_ucache_add( $key, serialize( $value ), $exptime ); + // false positive, wincache_ucache_add returns an empty array + // in some circumstances. + // @phan-suppress-next-line PhanTypeComparisonToArray return ( $result === [] || $result === true ); } diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index ded0891d30..5f80215632 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -248,7 +248,8 @@ class SpecialEmailUser extends UnlistedSpecialPage { * @param User $user * @param string $editToken Edit token * @param Config|null $config optional for backwards compatibility - * @return string|null Null on success or string on error + * @return null|string|array Null on success, string on error, or array on + * hook error */ public static function getPermissionsError( $user, $editToken, Config $config = null ) { if ( $config === null ) { diff --git a/includes/user/User.php b/includes/user/User.php index 311cac225c..5f403dd834 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -2205,6 +2205,9 @@ class User implements IDBAccessObject, UserIdentity { // Set the user limit key if ( $userLimit !== false ) { + // phan is confused because &can-bypass's value is a bool, so it assumes + // that $userLimit is also a bool here. + // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring list( $max, $period ) = $userLimit; wfDebug( __METHOD__ . ": effective user limit: $max in {$period}s\n" ); $keys[$cache->makeKey( 'limiter', $action, 'user', $id )] = $userLimit; @@ -2236,6 +2239,9 @@ class User implements IDBAccessObject, UserIdentity { $triggered = false; foreach ( $keys as $key => $limit ) { + // phan is confused because &can-bypass's value is a bool, so it assumes + // that $userLimit is also a bool here. + // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring list( $max, $period ) = $limit; $summary = "(limit $max in {$period}s)"; $count = $cache->get( $key ); diff --git a/languages/Language.php b/languages/Language.php index f72ac1a25a..52cb231561 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3697,6 +3697,7 @@ class Language { } } elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) { # String in fact does need truncation, the truncation point was OK. + // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring list( $ret, $openTags ) = $maybeState; // reload state $ret = $this->removeBadCharLast( $ret ); // multi-byte char fix $ret .= $ellipsis; // add ellipsis -- 2.20.1