Cleanup some incorrect return annotations
[lhc/web/wiklou.git] / tests / phan / config.php
1 <?php
2
3 use \Phan\Config;
4
5 // If xdebug is enabled, we need to increase the nesting level for phan
6 ini_set( 'xdebug.max_nesting_level', 1000 );
7
8 /**
9 * This configuration will be read and overlayed on top of the
10 * default configuration. Command line arguments will be applied
11 * after this file is read.
12 *
13 * @see src/Phan/Config.php
14 * See Config for all configurable options.
15 *
16 * A Note About Paths
17 * ==================
18 *
19 * Files referenced from this file should be defined as
20 *
21 * ```
22 * Config::projectPath('relative_path/to/file')
23 * ```
24 *
25 * where the relative path is relative to the root of the
26 * project which is defined as either the working directory
27 * of the phan executable or a path passed in via the CLI
28 * '-d' flag.
29 */
30 return [
31 /**
32 * A list of individual files to include in analysis
33 * with a path relative to the root directory of the
34 * project. directory_list won't find .inc files so
35 * we augment it here.
36 */
37 'file_list' => [
38 'maintenance/7zip.inc',
39 'maintenance/backupPrefetch.inc',
40 'maintenance/commandLine.inc',
41 'maintenance/sqlite.inc',
42 'maintenance/userOptions.inc',
43 'maintenance/backup.inc',
44 'maintenance/cleanupTable.inc',
45 'maintenance/importImages.inc',
46 'maintenance/userDupes.inc',
47 'maintenance/language/checkLanguage.inc',
48 'maintenance/language/languages.inc',
49 ],
50
51 /**
52 * A list of directories that should be parsed for class and
53 * method information. After excluding the directories
54 * defined in exclude_analysis_directory_list, the remaining
55 * files will be statically analyzed for errors.
56 *
57 * Thus, both first-party and third-party code being used by
58 * your application should be included in this list.
59 */
60 'directory_list' => [
61 'includes/',
62 'languages/',
63 'maintenance/',
64 'mw-config/',
65 'resources/',
66 'skins/',
67 'vendor/',
68 'tests/phan/stubs/',
69 ],
70
71 /**
72 * A file list that defines files that will be excluded
73 * from parsing and analysis and will not be read at all.
74 *
75 * This is useful for excluding hopelessly unanalyzable
76 * files that can't be removed for whatever reason.
77 */
78 'exclude_file_list' => function_exists( 'xcache_get' ) ? [] : [
79 // References xcache which probably isn't installed
80 'includes/libs/objectcache/XCacheBagOStuff.php'
81 ],
82
83 /**
84 * A list of directories holding code that we want
85 * to parse, but not analyze. Also works for individual
86 * files.
87 */
88 "exclude_analysis_directory_list" => [
89 'vendor/',
90 'tests/phan/stubs/',
91 // The referenced classes are not available in vendor, only when
92 // included from composer.
93 'includes/composer/',
94 // Directly references classes that only exist in Translate extension
95 'maintenance/language/',
96 // External class
97 'includes/libs/jsminplus.php',
98 ],
99
100 /**
101 * Backwards Compatibility Checking. This is slow
102 * and expensive, but you should consider running
103 * it before upgrading your version of PHP to a
104 * new version that has backward compatibility
105 * breaks.
106 */
107 'backward_compatibility_checks' => false,
108
109 /**
110 * A set of fully qualified class-names for which
111 * a call to parent::__construct() is required
112 */
113 'parent_constructor_required' => [
114 ],
115
116 /**
117 * Run a quick version of checks that takes less
118 * time at the cost of not running as thorough
119 * an analysis. You should consider setting this
120 * to true only when you wish you had more issues
121 * to fix in your code base.
122 *
123 * In quick-mode the scanner doesn't rescan a function
124 * or a method's code block every time a call is seen.
125 * This means that the problem here won't be detected:
126 *
127 * ```php
128 * <?php
129 * function test($arg):int {
130 * return $arg;
131 * }
132 * test("abc");
133 * ```
134 *
135 * This would normally generate:
136 *
137 * ```sh
138 * test.php:3 TypeError return string but `test()` is declared to return int
139 * ```
140 *
141 * The initial scan of the function's code block has no
142 * type information for `$arg`. It isn't until we see
143 * the call and rescan test()'s code block that we can
144 * detect that it is actually returning the passed in
145 * `string` instead of an `int` as declared.
146 */
147 'quick_mode' => false,
148
149 /**
150 * By default, Phan will not analyze all node types
151 * in order to save time. If this config is set to true,
152 * Phan will dig deeper into the AST tree and do an
153 * analysis on all nodes, possibly finding more issues.
154 *
155 * See \Phan\Analysis::shouldVisit for the set of skipped
156 * nodes.
157 */
158 'should_visit_all_nodes' => true,
159
160 /**
161 * If enabled, check all methods that override a
162 * parent method to make sure its signature is
163 * compatible with the parent's. This check
164 * can add quite a bit of time to the analysis.
165 */
166 'analyze_signature_compatibility' => true,
167
168 // Only emit critical issues
169 "minimum_severity" => 10,
170
171 /**
172 * If true, missing properties will be created when
173 * they are first seen. If false, we'll report an
174 * error message if there is an attempt to write
175 * to a class property that wasn't explicitly
176 * defined.
177 */
178 'allow_missing_properties' => false,
179
180 /**
181 * Allow null to be cast as any type and for any
182 * type to be cast to null. Setting this to false
183 * will cut down on false positives.
184 */
185 'null_casts_as_any_type' => true,
186
187 /**
188 * If enabled, scalars (int, float, bool, string, null)
189 * are treated as if they can cast to each other.
190 *
191 * MediaWiki is pretty lax and uses many scalar
192 * types interchangably.
193 */
194 'scalar_implicit_cast' => true,
195
196 /**
197 * If true, seemingly undeclared variables in the global
198 * scope will be ignored. This is useful for projects
199 * with complicated cross-file globals that you have no
200 * hope of fixing.
201 */
202 'ignore_undeclared_variables_in_global_scope' => false,
203
204 /**
205 * Set to true in order to attempt to detect dead
206 * (unreferenced) code. Keep in mind that the
207 * results will only be a guess given that classes,
208 * properties, constants and methods can be referenced
209 * as variables (like `$class->$property` or
210 * `$class->$method()`) in ways that we're unable
211 * to make sense of.
212 */
213 'dead_code_detection' => false,
214
215 /**
216 * If true, the dead code detection rig will
217 * prefer false negatives (not report dead code) to
218 * false positives (report dead code that is not
219 * actually dead) which is to say that the graph of
220 * references will create too many edges rather than
221 * too few edges when guesses have to be made about
222 * what references what.
223 */
224 'dead_code_detection_prefer_false_negative' => true,
225
226 /**
227 * If disabled, Phan will not read docblock type
228 * annotation comments (such as for @return, @param,
229 * @var, @suppress, @deprecated) and only rely on
230 * types expressed in code.
231 */
232 'read_type_annotations' => true,
233
234 /**
235 * If a file path is given, the code base will be
236 * read from and written to the given location in
237 * order to attempt to save some work from being
238 * done. Only changed files will get analyzed if
239 * the file is read
240 */
241 'stored_state_file_path' => null,
242
243 /**
244 * Set to true in order to ignore issue suppression.
245 * This is useful for testing the state of your code, but
246 * unlikely to be useful outside of that.
247 */
248 'disable_suppression' => false,
249
250 /**
251 * If set to true, we'll dump the AST instead of
252 * analyzing files
253 */
254 'dump_ast' => false,
255
256 /**
257 * If set to a string, we'll dump the fully qualified lowercase
258 * function and method signatures instead of analyzing files.
259 */
260 'dump_signatures_file' => null,
261
262 /**
263 * If true (and if stored_state_file_path is set) we'll
264 * look at the list of files passed in and expand the list
265 * to include files that depend on the given files
266 */
267 'expand_file_list' => false,
268
269 // Include a progress bar in the output
270 'progress_bar' => false,
271
272 /**
273 * The probability of actually emitting any progress
274 * bar update. Setting this to something very low
275 * is good for reducing network IO and filling up
276 * your terminal's buffer when running phan on a
277 * remote host.
278 */
279 'progress_bar_sample_rate' => 0.005,
280
281 /**
282 * The number of processes to fork off during the analysis
283 * phase.
284 */
285 'processes' => 1,
286
287 /**
288 * Add any issue types (such as 'PhanUndeclaredMethod')
289 * to this black-list to inhibit them from being reported.
290 */
291 'suppress_issue_types' => [
292 // MediaWiki has so much deprecated class usage it's a bit hopeless to
293 // fix this immediately
294 'PhanDeprecatedClass',
295 'PhanDeprecatedFunction',
296 'PhanDeprecatedProperty',
297 // There are arround 1400 usages of undeclared properties.
298 // php is ok with that but it's a code smell.
299 'PhanUndeclaredProperty',
300 ],
301
302 /**
303 * If empty, no filter against issues types will be applied.
304 * If this white-list is non-empty, only issues within the list
305 * will be emitted by Phan.
306 */
307 'whitelist_issue_types' => [
308 // 'PhanAccessMethodPrivate',
309 // 'PhanAccessMethodProtected',
310 // 'PhanAccessNonStaticToStatic',
311 // 'PhanAccessPropertyPrivate',
312 // 'PhanAccessPropertyProtected',
313 // 'PhanAccessSignatureMismatch',
314 // 'PhanAccessSignatureMismatchInternal',
315 // 'PhanAccessStaticToNonStatic',
316 // 'PhanCompatibleExpressionPHP7',
317 // 'PhanCompatiblePHP7',
318 // 'PhanContextNotObject',
319 // 'PhanDeprecatedClass',
320 // 'PhanDeprecatedFunction',
321 // 'PhanDeprecatedProperty',
322 // 'PhanEmptyFile',
323 // 'PhanNonClassMethodCall',
324 // 'PhanNoopArray',
325 // 'PhanNoopClosure',
326 // 'PhanNoopConstant',
327 // 'PhanNoopProperty',
328 // 'PhanNoopVariable',
329 // 'PhanParamRedefined',
330 // 'PhanParamReqAfterOpt',
331 // 'PhanParamSignatureMismatch',
332 // 'PhanParamSignatureMismatchInternal',
333 // 'PhanParamSpecial1',
334 // 'PhanParamSpecial2',
335 // 'PhanParamSpecial3',
336 // 'PhanParamSpecial4',
337 // 'PhanParamTooFew',
338 // 'PhanParamTooFewInternal',
339 // 'PhanParamTooMany',
340 // 'PhanParamTooManyInternal',
341 // 'PhanParamTypeMismatch',
342 // 'PhanParentlessClass',
343 // 'PhanRedefineClass',
344 // 'PhanRedefineClassInternal',
345 // 'PhanRedefineFunction',
346 // 'PhanRedefineFunctionInternal',
347 // 'PhanStaticCallToNonStatic',
348 // 'PhanSyntaxError',
349 // 'PhanTraitParentReference',
350 // 'PhanTypeArrayOperator',
351 // 'PhanTypeArraySuspicious',
352 // 'PhanTypeComparisonFromArray',
353 // 'PhanTypeComparisonToArray',
354 // 'PhanTypeConversionFromArray',
355 // 'PhanTypeInstantiateAbstract',
356 // 'PhanTypeInstantiateInterface',
357 // 'PhanTypeInvalidLeftOperand',
358 // 'PhanTypeInvalidRightOperand',
359 // 'PhanTypeMismatchArgument',
360 // 'PhanTypeMismatchArgumentInternal',
361 // 'PhanTypeMismatchDefault',
362 // 'PhanTypeMismatchForeach',
363 // 'PhanTypeMismatchProperty',
364 // 'PhanTypeMismatchReturn',
365 // 'PhanTypeMissingReturn',
366 // 'PhanTypeNonVarPassByRef',
367 // 'PhanTypeParentConstructorCalled',
368 // 'PhanTypeVoidAssignment',
369 // 'PhanUnanalyzable',
370 // 'PhanUndeclaredClass',
371 // 'PhanUndeclaredClassCatch',
372 // 'PhanUndeclaredClassConstant',
373 // 'PhanUndeclaredClassInstanceof',
374 // 'PhanUndeclaredClassMethod',
375 // 'PhanUndeclaredClassReference',
376 // 'PhanUndeclaredConstant',
377 // 'PhanUndeclaredExtendedClass',
378 // 'PhanUndeclaredFunction',
379 // 'PhanUndeclaredInterface',
380 // 'PhanUndeclaredMethod',
381 // 'PhanUndeclaredProperty',
382 // 'PhanUndeclaredStaticMethod',
383 // 'PhanUndeclaredStaticProperty',
384 // 'PhanUndeclaredTrait',
385 // 'PhanUndeclaredTypeParameter',
386 // 'PhanUndeclaredTypeProperty',
387 // 'PhanUndeclaredVariable',
388 // 'PhanUnreferencedClass',
389 // 'PhanUnreferencedConstant',
390 // 'PhanUnreferencedMethod',
391 // 'PhanUnreferencedProperty',
392 // 'PhanVariableUseClause',
393 ],
394
395 /**
396 * Override to hardcode existence and types of (non-builtin) globals in the global scope.
397 * Class names must be prefixed with '\\'.
398 * (E.g. ['_FOO' => '\\FooClass', 'page' => '\\PageClass', 'userId' => 'int'])
399 */
400 'globals_type_map' => [
401 'IP' => 'string',
402 ],
403
404 // Emit issue messages with markdown formatting
405 'markdown_issue_messages' => false,
406
407 /**
408 * Enable or disable support for generic templated
409 * class types.
410 */
411 'generic_types_enabled' => true,
412
413 // A list of plugin files to execute
414 'plugins' => [
415 ],
416 ];