|
| 1 | +<?php |
| 2 | + |
| 3 | +use MediaWikiPhanConfig\ConfigBuilder; |
| 4 | + |
| 5 | +function setBaseOptions( string $curDir, ConfigBuilder $configBuilder ): void { |
| 6 | + // TODO: Do we need to explicitly set these? If so, move to ConfigBuilder. Remove otherwise. |
| 7 | + $baseOptions = [ |
| 8 | + 'backward_compatibility_checks' => false, |
| 9 | + |
| 10 | + 'parent_constructor_required' => [ |
| 11 | + ], |
| 12 | + |
| 13 | + 'quick_mode' => false, |
| 14 | + 'analyze_signature_compatibility' => true, |
| 15 | + 'ignore_undeclared_variables_in_global_scope' => false, |
| 16 | + 'read_type_annotations' => true, |
| 17 | + 'disable_suppression' => false, |
| 18 | + 'dump_ast' => false, |
| 19 | + 'dump_signatures_file' => null, |
| 20 | + 'processes' => 1, |
| 21 | + 'whitelist_issue_types' => [], |
| 22 | + 'markdown_issue_messages' => false, |
| 23 | + 'generic_types_enabled' => true, |
| 24 | + 'plugins' => [ |
| 25 | + 'PregRegexCheckerPlugin', |
| 26 | + 'UnusedSuppressionPlugin', |
| 27 | + 'DuplicateExpressionPlugin', |
| 28 | + 'LoopVariableReusePlugin', |
| 29 | + 'RedundantAssignmentPlugin', |
| 30 | + 'UnreachableCodePlugin', |
| 31 | + 'SimplifyExpressionPlugin', |
| 32 | + 'DuplicateArrayKeyPlugin', |
| 33 | + 'UseReturnValuePlugin', |
| 34 | + 'AddNeverReturnTypePlugin', |
| 35 | + ], |
| 36 | + 'plugin_config' => [], |
| 37 | + // BC for repos not checking whether these are set |
| 38 | + 'file_list' => [], |
| 39 | + 'exclude_file_list' => [], |
| 40 | + ]; |
| 41 | + $configBuilder->setRawOptions( $baseOptions ); |
| 42 | + |
| 43 | + $configBuilder |
| 44 | + ->excludeDirectories( $curDir . '/stubs' ) |
| 45 | + ->setExcludeFileRegex( |
| 46 | + '@vendor/(' . |
| 47 | + '(' . implode( '|', array_merge( [ |
| 48 | + // Exclude known dev dependencies |
| 49 | + 'composer/installers', |
| 50 | + 'php-parallel-lint/php-console-color', |
| 51 | + 'php-parallel-lint/php-console-highlighter', |
| 52 | + 'php-parallel-lint/php-parallel-lint', |
| 53 | + 'mediawiki/mediawiki-codesniffer', |
| 54 | + 'microsoft/tolerant-php-parser', |
| 55 | + 'phan/phan', |
| 56 | + 'phpunit/php-code-coverage', |
| 57 | + 'squizlabs/php_codesniffer', |
| 58 | + // Exclude stubs used in libraries |
| 59 | + '[^/]+/[^/]+/\.phan', |
| 60 | + ], PHP_MAJOR_VERSION < 8 ? [] : [ |
| 61 | + 'symfony/polyfill-php80', |
| 62 | + ] ) ) . ')' . |
| 63 | + '|' . |
| 64 | + // Also exclude tests folder from dependencies |
| 65 | + '.*/[Tt]ests?' . |
| 66 | + ')/@' |
| 67 | + ) |
| 68 | + ->setMinimumSeverity( 0 ) |
| 69 | + ->allowMissingProperties( false ) |
| 70 | + ->allowNullCastsAsAnyType( false ) |
| 71 | + ->allowScalarImplicitCasts( false ) |
| 72 | + ->enableDeadCodeDetection( false ) |
| 73 | + ->shouldDeadCodeDetectionPreferFalseNegatives( true ) |
| 74 | + // TODO Enable by default |
| 75 | + ->setProgressBarMode( ConfigBuilder::PROGRESS_BAR_DISABLED ) |
| 76 | + ->readClassAliases( true ) |
| 77 | + ->enableRedundantConditionDetection( true ) |
| 78 | + ->setMinimumPHPVersion( '7.4' ) |
| 79 | + ->setTargetPHPVersion( '8.1' ); |
| 80 | + |
| 81 | + if ( !defined( 'MSG_EOR' ) ) { |
| 82 | + $configBuilder->addFiles( $curDir . '/stubs/sockets.windows.php' ); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * Internal helper used to filter dirs. This is used so that we can include commonly-used dir |
| 88 | + * names without phan complaining about "directory not found". It should NOT be used in |
| 89 | + * repo-specific config files. |
| 90 | + */ |
| 91 | +function filterDirs( array $dirs ): array { |
| 92 | + return array_filter( $dirs, 'file_exists' ); |
| 93 | +} |
0 commit comments