From 43cc14657dae8594eebbf2e7e33a5a3c50b2e9e4 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 1 Sep 2019 14:45:11 +0200 Subject: [PATCH] Unsuppress phan issues, part 8 And also clean up the config. Bug: T231636 Depends-On: Ie6233561de78457cae5e4e44e220feec2d1272d8 Change-Id: I82a279e1f7b0fdefd3bb712e46c7d0665429d065 --- .phan/config.php | 41 ++-- .phan/internal_stubs/pgsql.phan_php | 189 ++++++++++++++++++ includes/Rest/EntryPoint.php | 1 + includes/Rest/Router.php | 1 + includes/Revision.php | 1 + includes/Revision/RevisionStoreFactory.php | 1 + includes/ServiceWiring.php | 2 + includes/Setup.php | 1 + .../lockmanager/PostgreSqlLockManager.php | 2 + includes/media/ExifBitmapHandler.php | 2 + includes/page/WikiPage.php | 2 + includes/parser/Preprocessor.php | 2 + includes/session/SessionManager.php | 3 + includes/user/User.php | 1 + maintenance/Maintenance.php | 1 + 15 files changed, 237 insertions(+), 13 deletions(-) create mode 100644 .phan/internal_stubs/pgsql.phan_php diff --git a/.phan/config.php b/.phan/config.php index fe63e474b9..47f4512246 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -32,21 +32,36 @@ $cfg['file_list'] = array_merge( class_exists( PHPUnit_TextUI_Command::class ) ? [] : [ '.phan/stubs/phpunit4.php' ], class_exists( ProfilerExcimer::class ) ? [] : [ '.phan/stubs/excimer.php' ], [ - 'maintenance/cleanupTable.inc', - 'maintenance/CodeCleanerGlobalsPass.inc', - 'maintenance/commandLine.inc', - 'maintenance/sqlite.inc', - 'maintenance/userDupes.inc', - 'maintenance/language/checkLanguage.inc', - 'maintenance/language/languages.inc', + // This makes constants and globals known to Phan before processing all other files. + // You can check the parser order with --dump-parsed-file-list + 'includes/Defines.php', + // @todo This isn't working yet, see globals_type_map below + // 'includes/DefaultSettings.php', + // 'includes/Setup.php', ] ); +$cfg['exclude_file_list'] = array_merge( + $cfg['exclude_file_list'], + [ + // This file has invalid PHP syntax + 'vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc', + ] +); + +$cfg['analyzed_file_extensions'] = array_merge( + $cfg['analyzed_file_extensions'] ?? [ 'php' ], + [ 'inc' ] +); + $cfg['autoload_internal_extension_signatures'] = [ + 'dom' => '.phan/internal_stubs/dom.phan_php', 'imagick' => '.phan/internal_stubs/imagick.phan_php', + 'intl' => '.phan/internal_stubs/intl.phan_php', 'memcached' => '.phan/internal_stubs/memcached.phan_php', 'oci8' => '.phan/internal_stubs/oci8.phan_php', 'pcntl' => '.phan/internal_stubs/pcntl.phan_php', + 'pgsql' => '.phan/internal_stubs/pgsql.phan_php', 'redis' => '.phan/internal_stubs/redis.phan_php', 'sockets' => '.phan/internal_stubs/sockets.phan_php', 'sqlsrv' => '.phan/internal_stubs/sqlsrv.phan_php', @@ -65,7 +80,7 @@ $cfg['directory_list'] = [ $cfg['exclude_analysis_directory_list'] = [ 'vendor/', - '.phan/stubs/', + '.phan/', // The referenced classes are not available in vendor, only when // included from composer. 'includes/composer/', @@ -77,14 +92,11 @@ $cfg['exclude_analysis_directory_list'] = [ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ // approximate error count: 19 - "PhanParamReqAfterOpt", // False positives with nullables, ref phan issue #3159 + "PhanParamReqAfterOpt", // False positives with nullables (phan issue #3159). Use real nullables + //after dropping HHVM // approximate error count: 110 "PhanParamTooMany", // False positives with variargs. Unsuppress after dropping HHVM - // approximate error count: 22 - "PhanAccessMethodInternal", - // approximate error count: 36 - "PhanUndeclaredConstant", // approximate error count: 60 "PhanTypeMismatchArgument", // approximate error count: 752 @@ -92,6 +104,8 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ ] ); $cfg['ignore_undeclared_variables_in_global_scope'] = true; +// @todo It'd be great if we could just make phan read these from DefaultSettings, to avoid +// duplicating the types. $cfg['globals_type_map'] = array_merge( $cfg['globals_type_map'], [ 'IP' => 'string', 'wgGalleryOptions' => 'array', @@ -110,6 +124,7 @@ $cfg['globals_type_map'] = array_merge( $cfg['globals_type_map'], [ 'wgVirtualRestConfig' => 'array', 'wgWANObjectCaches' => 'array[]', 'wgLocalInterwikis' => 'string[]', + 'wgDebugLogGroups' => 'string|false|array{destination:string,sample?:int,level:int}', ] ); return $cfg; diff --git a/.phan/internal_stubs/pgsql.phan_php b/.phan/internal_stubs/pgsql.phan_php new file mode 100644 index 0000000000..c8a2b25e70 --- /dev/null +++ b/.phan/internal_stubs/pgsql.phan_php @@ -0,0 +1,189 @@ + $conf->get( 'CookiePrefix' ) ] ); + // @phan-suppress-next-line PhanAccessMethodInternal $authorizer = new MWBasicAuthorizer( $context->getUser(), $services->getPermissionManager() ); diff --git a/includes/Rest/Router.php b/includes/Rest/Router.php index 14b4c9cb89..961da01471 100644 --- a/includes/Rest/Router.php +++ b/includes/Rest/Router.php @@ -263,6 +263,7 @@ class Router { * @return ResponseInterface */ private function executeHandler( $handler ): ResponseInterface { + // @phan-suppress-next-line PhanAccessMethodInternal $authResult = $this->basicAuth->authorize( $handler->getRequest(), $handler ); if ( $authResult ) { return $this->responseFactory->createHttpError( 403, [ 'error' => $authResult ] ); diff --git a/includes/Revision.php b/includes/Revision.php index de3c2998b5..c6e727e69b 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -89,6 +89,7 @@ class Revision implements IDBAccessObject { * @return SqlBlobStore */ protected static function getBlobStore( $wiki = false ) { + // @phan-suppress-next-line PhanAccessMethodInternal $store = MediaWikiServices::getInstance() ->getBlobStoreFactory() ->newSqlBlobStore( $wiki ); diff --git a/includes/Revision/RevisionStoreFactory.php b/includes/Revision/RevisionStoreFactory.php index 0475557387..acecee1294 100644 --- a/includes/Revision/RevisionStoreFactory.php +++ b/includes/Revision/RevisionStoreFactory.php @@ -125,6 +125,7 @@ class RevisionStoreFactory { $store = new RevisionStore( $this->dbLoadBalancerFactory->getMainLB( $dbDomain ), + // @phan-suppress-next-line PhanAccessMethodInternal $this->blobStoreFactory->newSqlBlobStore( $dbDomain ), $this->cache, // Pass local cache instance; Leave cache sharing to RevisionStore. $this->commentStore, diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index b53011ff96..740377c027 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -362,6 +362,7 @@ return [ 'MessageFormatterFactory' => function ( MediaWikiServices $services ) : IMessageFormatterFactory { + // @phan-suppress-next-line PhanAccessMethodInternal return new MessageFormatterFactory(); }, @@ -829,6 +830,7 @@ return [ }, '_SqlBlobStore' => function ( MediaWikiServices $services ) : SqlBlobStore { + // @phan-suppress-next-line PhanAccessMethodInternal return $services->getBlobStoreFactory()->newSqlBlobStore(); }, diff --git a/includes/Setup.php b/includes/Setup.php index 1e65f52a95..cc9a3f9b0b 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -618,6 +618,7 @@ if ( $wgPHPSessionHandling !== 'enable' && if ( defined( 'MW_NO_SESSION' ) ) { // If the entry point wants no session, force 'disable' here unless they // specifically set it to the (undocumented) 'warn'. + // @phan-suppress-next-line PhanUndeclaredConstant $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable'; } diff --git a/includes/libs/lockmanager/PostgreSqlLockManager.php b/includes/libs/lockmanager/PostgreSqlLockManager.php index fd3ffa5cbc..5530eedba9 100644 --- a/includes/libs/lockmanager/PostgreSqlLockManager.php +++ b/includes/libs/lockmanager/PostgreSqlLockManager.php @@ -7,6 +7,8 @@ use Wikimedia\Rdbms\DBError; * All locks are non-blocking, which avoids deadlocks. * * @ingroup LockManager + * @phan-file-suppress PhanUndeclaredConstant Phan doesn't read constants in LockManager + * when accessed via self:: */ class PostgreSqlLockManager extends DBLockManager { /** @var array Mapping of lock types to the type actually used */ diff --git a/includes/media/ExifBitmapHandler.php b/includes/media/ExifBitmapHandler.php index 9058340fb6..874e87264b 100644 --- a/includes/media/ExifBitmapHandler.php +++ b/includes/media/ExifBitmapHandler.php @@ -26,6 +26,8 @@ * All metadata related, since both JPEG and TIFF support Exif. * * @ingroup Media + * @phan-file-suppress PhanUndeclaredConstant Phan doesn't read constants in MediaHandler + * when accessed via self:: */ class ExifBitmapHandler extends BitmapHandler { const BROKEN_FILE = '-1'; // error extracting metadata diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 4f0f2e2949..9c5c4e055e 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -41,6 +41,8 @@ use Wikimedia\Rdbms\LoadBalancer; * * Some fields are public only for backwards-compatibility. Use accessors. * In the past, this class was part of Article.php and everything was public. + * + * @phan-file-suppress PhanAccessMethodInternal Due to the use of DerivedPageDataUpdater */ class WikiPage implements Page, IDBAccessObject { // Constants for $mDataLoadedFrom and related diff --git a/includes/parser/Preprocessor.php b/includes/parser/Preprocessor.php index b321078dcd..99ca1be489 100644 --- a/includes/parser/Preprocessor.php +++ b/includes/parser/Preprocessor.php @@ -76,6 +76,7 @@ abstract class Preprocessor { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $key = $cache->makeKey( + // @phan-suppress-next-line PhanUndeclaredConstant defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class, md5( $text ), $flags @@ -108,6 +109,7 @@ abstract class Preprocessor { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $key = $cache->makeKey( + // @phan-suppress-next-line PhanUndeclaredConstant defined( 'static::CACHE_PREFIX' ) ? static::CACHE_PREFIX : static::class, md5( $text ), $flags diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php index fcc428da6e..1da0cebc93 100644 --- a/includes/session/SessionManager.php +++ b/includes/session/SessionManager.php @@ -321,6 +321,7 @@ final class SessionManager implements SessionManagerInterface { public function getVaryHeaders() { // @codeCoverageIgnoreStart + // @phan-suppress-next-line PhanUndeclaredConstant if ( defined( 'MW_NO_SESSION' ) && MW_NO_SESSION !== 'warn' ) { return []; } @@ -341,6 +342,7 @@ final class SessionManager implements SessionManagerInterface { public function getVaryCookies() { // @codeCoverageIgnoreStart + // @phan-suppress-next-line PhanUndeclaredConstant if ( defined( 'MW_NO_SESSION' ) && MW_NO_SESSION !== 'warn' ) { return []; } @@ -815,6 +817,7 @@ final class SessionManager implements SessionManagerInterface { public function getSessionFromInfo( SessionInfo $info, WebRequest $request ) { // @codeCoverageIgnoreStart if ( defined( 'MW_NO_SESSION' ) ) { + // @phan-suppress-next-line PhanUndeclaredConstant if ( MW_NO_SESSION === 'warn' ) { // Undocumented safety case for converting existing entry points $this->logger->error( 'Sessions are supposed to be disabled for this entry point', [ diff --git a/includes/user/User.php b/includes/user/User.php index 82f2ddc7f5..ad6b5b81d9 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -1752,6 +1752,7 @@ class User implements IDBAccessObject, UserIdentity { // overwriting mBlockedby, surely? $this->load(); + // @phan-suppress-next-line PhanAccessMethodInternal It's the only allowed use $block = MediaWikiServices::getInstance()->getBlockManager()->getUserBlock( $this, $fromReplica diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 81bee4c621..d89959043d 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1235,6 +1235,7 @@ abstract class Maintenance { */ protected function afterFinalSetup() { if ( defined( 'MW_CMDLINE_CALLBACK' ) ) { + // @phan-suppress-next-line PhanUndeclaredConstant call_user_func( MW_CMDLINE_CALLBACK ); } } -- 2.20.1