config.php 14 KB

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