Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 73
0.00% covered (danger)
0.00%
0 / 2
CRAP
n/a
0 / 0
setBaseOptions
0.00% covered (danger)
0.00%
0 / 72
0.00% covered (danger)
0.00%
0 / 1
12
filterDirs
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3use MediaWikiPhanConfig\ConfigBuilder;
4
5function 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        'plugin_config' => [],
25        // BC for repos not checking whether these are set
26        'file_list' => [],
27        'exclude_file_list' => [],
28    ];
29    $configBuilder->setRawOptions( $baseOptions );
30
31    $configBuilder
32        ->excludeDirectories( $curDir . '/stubs' )
33        ->setExcludeFileRegex(
34            '@vendor/(' .
35            '(' . implode( '|', array_merge( [
36                // Exclude known dev dependencies
37                'composer/installers',
38                'php-parallel-lint/php-console-color',
39                'php-parallel-lint/php-console-highlighter',
40                'php-parallel-lint/php-parallel-lint',
41                'mediawiki/mediawiki-codesniffer',
42                'microsoft/tolerant-php-parser',
43                'phan/phan',
44                'phpunit/php-code-coverage',
45                'squizlabs/php_codesniffer',
46                // Exclude stubs used in libraries
47                '[^/]+/[^/]+/\.phan',
48            ], PHP_MAJOR_VERSION < 8 ? [] : [
49                'symfony/polyfill-php80',
50            ] ) ) . ')' .
51            '|' .
52            // Also exclude tests folder from dependencies
53            '.*/[Tt]ests?' .
54            ')/@'
55        )
56        ->setMinimumSeverity( 0 )
57        ->allowMissingProperties( false )
58        ->allowNullCastsAsAnyType( false )
59        ->allowScalarImplicitCasts( false )
60        ->enableDeadCodeDetection( false )
61        ->shouldDeadCodeDetectionPreferFalseNegatives( true )
62        // TODO Enable by default
63        ->setProgressBarMode( ConfigBuilder::PROGRESS_BAR_DISABLED )
64        ->readClassAliases( true )
65        ->enableRedundantConditionDetection( true )
66        ->setMinimumPHPVersion( '7.4' )
67        ->setTargetPHPVersion( '8.1' )
68        ->addPlugins( [
69            'PregRegexCheckerPlugin',
70            'UnusedSuppressionPlugin',
71            'DuplicateExpressionPlugin',
72            'LoopVariableReusePlugin',
73            'RedundantAssignmentPlugin',
74            'UnreachableCodePlugin',
75            'SimplifyExpressionPlugin',
76            'DuplicateArrayKeyPlugin',
77            'UseReturnValuePlugin',
78            'AddNeverReturnTypePlugin',
79        ] )
80        ->addCustomPlugins( [
81            'RedundantExistenceChecksPlugin',
82            'NoBaseExceptionPlugin',
83        ] );
84
85    if ( !defined( 'MSG_EOR' ) ) {
86        $configBuilder->addFiles( $curDir . '/stubs/sockets.windows.php' );
87    }
88}
89
90/**
91 * Internal helper used to filter dirs. This is used so that we can include commonly-used dir
92 * names without phan complaining about "directory not found". It should NOT be used in
93 * repo-specific config files.
94 */
95function filterDirs( array $dirs ): array {
96    return array_filter( $dirs, 'file_exists' );
97}