Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 127
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
setBaseOptions
0.00% covered (danger)
0.00%
0 / 127
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types = 1 );
3
4use MediaWikiPhanConfig\ConfigBuilder;
5
6function setBaseOptions( ConfigBuilder $configBuilder ): void {
7    // TODO: Do we need to explicitly set these? If so, move to ConfigBuilder. Remove otherwise.
8    $baseOptions = [
9        'backward_compatibility_checks' => false,
10
11        'parent_constructor_required' => [
12        ],
13
14        'quick_mode' => false,
15        'analyze_signature_compatibility' => true,
16        'ignore_undeclared_variables_in_global_scope' => false,
17        'read_type_annotations' => true,
18        'disable_suppression' => false,
19        'dump_ast' => false,
20        'dump_signatures_file' => null,
21        'processes' => 1,
22        'whitelist_issue_types' => [],
23        'markdown_issue_messages' => false,
24        'generic_types_enabled' => true,
25        'plugin_config' => [],
26        'warn_about_undocumented_throw_statements' => true,
27        'exception_classes_with_optional_throws_phpdoc' => [
28            \LogicException::class,
29            \RuntimeException::class,
30            \Error::class,
31            \DOMException::class,
32            \Wikimedia\NormalizedException\NormalizedException::class,
33        ],
34        // BC for repos not checking whether these are set
35        'file_list' => [],
36        'exclude_file_list' => [],
37    ];
38    $configBuilder->setRawOptions( $baseOptions );
39
40    $configBuilder
41        ->excludeDirectories( __DIR__ . '/stubs' )
42        ->setExcludeFileRegex(
43            '@vendor/(' .
44            '(' . implode( '|', [
45                // Exclude known dev dependencies
46                'composer/installers',
47                'php-parallel-lint/php-console-color',
48                'php-parallel-lint/php-console-highlighter',
49                'php-parallel-lint/php-parallel-lint',
50                'mediawiki/mediawiki-codesniffer',
51                'phan/tolerant-php-parser',
52                'phan/phan',
53                'phan/var_representation_polyfill',
54                'phpunit/php-code-coverage',
55                'squizlabs/php_codesniffer',
56                'phpcsstandards/phpcsextra',
57                'phpcsstandards/phpcsutils',
58                // Exclude stubs used in libraries
59                '[^/]+/[^/]+/\.phan',
60            ] ) . ')' .
61            '|' .
62            // Also exclude tests folder from dependencies
63            '.*/[Tt]ests?' .
64            ')/@'
65        )
66        ->setMinimumSeverity( 0 )
67        ->allowMissingProperties( false )
68        ->allowNullCastsAsAnyType( false )
69        ->allowScalarImplicitCasts( false )
70        // Note, this implies unused_variable_detection
71        ->enableDeadCodeDetection( true )
72        ->shouldDeadCodeDetectionPreferFalseNegatives( true )
73        // TODO Enable by default
74        ->setProgressBarMode( ConfigBuilder::PROGRESS_BAR_DISABLED )
75        ->readClassAliases( true )
76        ->enableRedundantConditionDetection( true )
77        ->setTargetPHPVersion( '8.5' )
78        ->setSuppressedIssuesList( [
79            // Covered by codesniffer
80            'PhanUnreferencedUseNormal',
81            'PhanUnreferencedUseFunction',
82            'PhanUnreferencedUseConstant',
83            'PhanDuplicateUseNormal',
84            'PhanDuplicateUseFunction',
85            'PhanDuplicateUseConstant',
86            'PhanUseNormalNoEffect',
87            'PhanUseNormalNamespacedNoEffect',
88            'PhanUseFunctionNoEffect',
89            'PhanUseConstantNoEffect',
90            'PhanDeprecatedCaseInsensitiveDefine',
91            'PhanDeprecatedImplicitNullableParam',
92
93            // We have several parameters named "unused" in public interfaces
94            'PhanParamNameIndicatingUnused',
95            'PhanParamNameIndicatingUnusedInClosure',
96
97            // Consider unsuppressing when we formalize named parameter adoption
98            'PhanProvidingUnusedParameter',
99
100            // Would probably have many false positives
101            'PhanPluginMixedKeyNoKey',
102
103            // Using the `strlen( ... )` syntax for built-in functions feels quite verbose,
104            // we probably shouldn't try to make everyone use that, but it's there if you want
105            'MediaWikiUseFirstClassCallableInternalFunc',
106
107            // Issues from unused variable detection with too many false positives. For variables in particular, we
108            // would need a way to annotate RAII classes, see e.g. plugin attempt in
109            // Id87c4a437c0f9144fb53a576af16fc9cb23baed1.
110            // Intentionally enabled, as of phan 6.0.5: PhanUnusedPrivateMethodParameter, PhanUnusedVariableStatic,
111            // PhanUnusedClosureUseVariable, PhanUnusedVariableCaughtException
112            'PhanUnusedPublicMethodParameter',
113            'PhanUnusedPublicNoOverrideMethodParameter',
114            'PhanUnusedPublicFinalMethodParameter',
115            'PhanUnusedProtectedMethodParameter',
116            'PhanUnusedProtectedNoOverrideMethodParameter',
117            'PhanUnusedProtectedFinalMethodParameter',
118            'PhanUnusedGlobalFunctionParameter',
119            'PhanUnusedClosureParameter',
120            'PhanUnusedVariable',
121            'PhanUnusedVariableGlobal',
122            'PhanUnusedVariableValueOfForeachWithKey',
123
124            // Issues from dead code detection with too many false positives. For classes, constants, functions,
125            // and public/protected members, it'll be hard to lower the rate.
126            // Intentionally enabled, as of phan 6.0.5: PhanReadOnlyPrivateProperty, PhanWriteOnlyPrivateProperty,
127            // PhanUnreferencedPrivateProperty, PhanReadOnlyPHPDocProperty, PhanUnreferencedPrivateClassConstant,
128            // PhanUnreferencedPrivateMethod
129            'PhanUnreferencedClass',
130            'PhanReadOnlyPublicProperty',
131            'PhanWriteOnlyPublicProperty',
132            'PhanReadOnlyProtectedProperty',
133            'PhanWriteOnlyProtectedProperty',
134            'PhanUnreferencedPublicClassConstant',
135            'PhanUnreferencedProtectedClassConstant',
136            'PhanUnreferencedPublicMethod',
137            'PhanUnreferencedPublicProperty',
138            'PhanUnreferencedProtectedMethod',
139            'PhanUnreferencedProtectedProperty',
140            'PhanUnreferencedConstant',
141            'PhanUnreferencedFunction',
142            // TODO: re-enable when upstream https://github.com/phan/phan/issues/4572 is fixed
143            'PhanUnreferencedClosure',
144        ] )
145        ->addPlugins( [
146            'PregRegexCheckerPlugin',
147            'UnusedSuppressionPlugin',
148            'DuplicateExpressionPlugin',
149            'LoopVariableReusePlugin',
150            'RedundantAssignmentPlugin',
151            'UnreachableCodePlugin',
152            'SimplifyExpressionPlugin',
153            'DuplicateArrayKeyPlugin',
154            'UseReturnValuePlugin',
155            'AddNeverReturnTypePlugin',
156            'CaseMismatchPlugin',
157        ] )
158        ->addCustomPlugins( [
159            'FirstClassCallableRecommendPlugin',
160            'RedundantExistenceChecksPlugin',
161            'NoBaseExceptionPlugin',
162        ] );
163
164    if ( !defined( 'MSG_EOR' ) ) {
165        $configBuilder->addFiles( __DIR__ . '/stubs/sockets.windows.php' );
166    }
167}