Merge "Make ContributionsSpecialPage::shouldShowBlockLogExtract public"
[mediawiki.git] / .phan / config.php
blob1e76040852d37b8408a1d048c851fdaecdac8d12
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 $cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
23 // Whilst MediaWiki is still supporting PHP 7.4+, this lets us run phan on higher versions of PHP
24 // like 8.0 without phan trying to get us to make PHP 7.4-incompatible changes. This value should
25 // match the PHP version specified in composer.json and PHPVersionCheck.php.
26 $cfg['minimum_target_php_version'] = '7.4.3';
28 $cfg['file_list'] = array_merge(
29 $cfg['file_list'],
30 class_exists( Socket::class ) ? [] : [ '.phan/stubs/Socket.php' ],
31 class_exists( AllowDynamicProperties::class ) ? [] : [ '.phan/stubs/AllowDynamicProperties.php' ],
32 class_exists( WeakMap::class ) ? [] : [ '.phan/stubs/WeakMap.php' ],
34 // This makes constants and globals known to Phan before processing all other files.
35 // You can check the parser order with --dump-parsed-file-list
36 'includes/Defines.php',
37 // @todo This isn't working yet, see globals_type_map below
38 // 'includes/Setup.php',
39 'tests/phpunit/MediaWikiIntegrationTestCase.php',
40 'tests/phpunit/includes/TestUser.php',
44 $cfg['exclude_file_list'] = array_merge(
45 $cfg['exclude_file_list'],
47 // Avoid microsoft/tolerant-php-parser dependency
48 'maintenance/findDeprecated.php',
49 'maintenance/CodeCleanerGlobalsPass.php',
50 // Avoid nikic/php-parser dependency
51 'maintenance/shell.php',
55 if ( PHP_VERSION_ID >= 80000 ) {
56 // Exclude PHP 8.0 polyfills if PHP 8.0+ is running
57 $cfg['exclude_file_list'] = array_merge(
58 $cfg['exclude_file_list'],
60 'vendor/symfony/polyfill-php80/Resources/stubs/Attribute.php',
61 'vendor/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
62 'vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php',
63 'vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
64 'vendor/symfony/polyfill-php80/Resources/stubs/ValueError.php',
69 $cfg['autoload_internal_extension_signatures'] = [
70 'excimer' => '.phan/internal_stubs/excimer.phan_php',
71 'imagick' => '.phan/internal_stubs/imagick.phan_php',
72 'memcached' => '.phan/internal_stubs/memcached.phan_php',
73 'pcntl' => '.phan/internal_stubs/pcntl.phan_php',
74 'pgsql' => '.phan/internal_stubs/pgsql.phan_php',
75 'redis' => '.phan/internal_stubs/redis.phan_php',
76 'sockets' => '.phan/internal_stubs/sockets.phan_php',
77 'tideways_xhprof' => '.phan/internal_stubs/tideways_xhprof.phan_php',
78 'wikidiff2' => '.phan/internal_stubs/wikidiff.php'
81 $cfg['directory_list'] = [
82 'includes/',
83 'languages/',
84 'maintenance/',
85 'mw-config/',
86 'resources/',
87 'tests/common/',
88 'tests/parser/',
89 'tests/phan',
90 'tests/phpunit/mocks/',
91 // Do NOT add .phan/stubs/ here: stubs are conditionally loaded in file_list
94 // Include only direct production dependencies in vendor/
95 // Omit dev dependencies and most indirect dependencies
97 $composerJson = json_decode(
98 file_get_contents( __DIR__ . '/../composer.json' ),
99 true
102 $directDeps = [];
103 foreach ( $composerJson['require'] as $dep => $version ) {
104 $parts = explode( '/', $dep );
105 if ( count( $parts ) === 2 ) {
106 $directDeps[] = $dep;
110 // This is a list of all composer packages that are referenced by core but
111 // are not listed as requirements in composer.json.
112 $indirectDeps = [
113 'composer/spdx-licenses',
114 'doctrine/dbal',
115 'doctrine/sql-formatter',
116 'guzzlehttp/psr7',
117 'pear/net_url2',
118 'pear/pear-core-minimal',
119 'phpunit/phpunit',
120 'psr/http-message',
121 'seld/jsonlint',
122 'wikimedia/testing-access-wrapper',
123 'wikimedia/zest-css',
126 foreach ( [ ...$directDeps, ...$indirectDeps ] as $dep ) {
127 $cfg['directory_list'][] = "vendor/$dep";
130 $cfg['exclude_analysis_directory_list'] = [
131 'vendor/',
132 '.phan/',
133 'tests/phpunit/',
134 // The referenced classes are not available in vendor, only when
135 // included from composer.
136 'includes/composer/',
137 // Directly references classes that only exist in Translate extension
138 'maintenance/language/',
139 // External class
140 'includes/libs/objectcache/utils/MemcachedClient.php',
141 // File may be valid, but may contain numerous "errors" such as iterating over an
142 // empty array due to the version checking in T246594 not being currently used.
143 'includes/PHPVersionCheck.php',
146 // TODO: Ideally we'd disable this in core, given we don't need backwards compatibility here and aliases
147 // should not be used. However, that would have unwanted side effects such as being unable to test
148 // taint-check (T321806).
149 $cfg['enable_class_alias_support'] = true;
150 // Exclude Parsoid's src/DOM in favor of .phan/stubs/DomImpl.php
151 $cfg['exclude_file_list'] = array_merge(
152 $cfg['exclude_file_list'],
153 array_map( fn ( $f ) => "vendor/wikimedia/parsoid/src/DOM/{$f}.php", [
154 'Attr', 'CharacterData', 'Comment', 'Document', 'DocumentFragment',
155 'DocumentType', 'Element', 'Node', 'ProcessingInstruction', 'Text',
158 $cfg['file_list'][] = '.phan/stubs/DomImpl.php';
160 $cfg['ignore_undeclared_variables_in_global_scope'] = true;
161 // @todo It'd be great if we could just make phan read these from config-schema.php, to avoid
162 // duplicating the types. config-schema.php has JSON types though, not PHP types.
163 // @todo As we are removing access to global variables from the code base,
164 // remove them from here as well, so phan complains when something tries to use them.
165 $cfg['globals_type_map'] = array_merge( $cfg['globals_type_map'], [
166 'IP' => 'string',
167 'wgTitle' => \MediaWiki\Title\Title::class,
168 'wgGalleryOptions' => 'array',
169 'wgDirectoryMode' => 'int',
170 'wgDummyLanguageCodes' => 'string[]',
171 'wgNamespaceProtection' => 'array<int,string|string[]>',
172 'wgNamespaceAliases' => 'array<string,int>',
173 'wgLockManagers' => 'array[]',
174 'wgForeignFileRepos' => 'array[]',
175 'wgDefaultUserOptions' => 'array',
176 'wgSkipSkins' => 'string[]',
177 'wgLogTypes' => 'string[]',
178 'wgLogNames' => 'array<string,string>',
179 'wgLogHeaders' => 'array<string,string>',
180 'wgLogActionsHandlers' => 'array<string,class-string>',
181 'wgPasswordPolicy' => 'array<string,array<string,string|array>>',
182 'wgVirtualRestConfig' => 'array<string,array>',
183 'wgLocalInterwikis' => 'string[]',
184 'wgDebugLogGroups' => 'string|false|array{destination:string,sample?:int,level:int}',
185 'wgCookiePrefix' => 'string|false',
186 'wgOut' => \MediaWiki\Output\OutputPage::class,
187 'wgExtraNamespaces' => 'string[]',
188 'wgRequest' => \MediaWiki\Request\WebRequest::class,
189 ] );
191 // Include a local config file if it exists
192 if ( file_exists( __DIR__ . '/local-config.php' ) ) {
193 require __DIR__ . '/local-config.php';
196 return $cfg;