GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 0f62f3...5bd5ca )
by Leonardo
12:37
created

convertRelativeToFullPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
use Isolated\Symfony\Component\Finder\Finder;
0 ignored issues
show
Bug introduced by
The type Isolated\Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * Must only scope the packages in vendor/, because:
9
 *
10
 * - config/ references only local configuration
11
 * - src/ references only local classes (with one exception), which need not be scoped
12
 * - vendor/ references external classes (excluding local -wp packages), which need be scoped
13
 *
14
 * In addition, we must exclude all the local WordPress packages,
15
 * because scoping WordPress functions does NOT work.
16
 * @see https://github.com/humbug/php-scoper/issues/303
17
 *
18
 * Excluding the WordPress packages is feasible, because they do
19
 * not reference any external library.
20
 *
21
 * The only exception is getpop/routing-wp, which uses Brain\Cortex:
22
 *
23
 * in getpop/routing-wp/src/Component.php:
24
 *   use Brain\Cortex;
25
 *
26
 * in getpop/routing-wp/src/Hooks/SetupCortexHookSet.php:
27
 *   use Brain\Cortex\Route\RouteCollectionInterface;
28
 *   use Brain\Cortex\Route\RouteInterface;
29
 *   use Brain\Cortex\Route\QueryRoute;
30
 *
31
 * Then, manually add these 2 files to scope Brain\Cortex.
32
 * This works without side effects, because there are no WordPress stubs in them.
33
 */
34
function convertRelativeToFullPath(string $relativePath): string {
35
    return __DIR__ . '/vendor/' . $relativePath;
36
}
37
return [
38
    'prefix' => 'PrefixedByPoP',
39
    'finders' => [
40
        // Scope packages under vendor/, excluding local WordPress packages
41
        Finder::create()
42
            ->files()
43
            ->ignoreVCS(true)
44
            ->notName('/.*\\.md|.*\\.dist|composer\\.lock/')
45
            ->exclude([
46
                'tests',
47
            ])
48
            ->notPath([
49
                // Exclude libraries ending in "-wp"
50
                '#getpop/[a-zA-Z0-9_-]*-wp/#',
51
                '#pop-schema/[a-zA-Z0-9_-]*-wp/#',
52
                '#graphql-by-pop/[a-zA-Z0-9_-]*-wp/#',
53
                // Exclude all composer.json from own libraries (they get broken!)
54
                '#[getpop|pop\-schema|graphql\-by\-pop|graphql\-api]/*/composer.json#',
55
                // Exclude libraries
56
                '#symfony/deprecation-contracts/#',
57
                '#ralouphie/getallheaders/#',
58
                // Exclude tests from libraries
59
                '#nikic/fast-route/test/#',
60
                '#psr/log/Psr/Log/Test/#',
61
                '#symfony/service-contracts/Test/#',
62
            ])
63
            ->in('vendor'),
64
        Finder::create()->append([
65
            'vendor/getpop/routing-wp/src/Component.php',
66
            'vendor/getpop/routing-wp/src/Hooks/SetupCortexHookSet.php',
67
        ])
68
    ],
69
    'whitelist' => [
70
        // Own namespaces
71
        // Watch out! Do NOT alter the order of PoPSchema and PoP!
72
        // If PoP comes first, then PoPSchema is still scoped!
73
        'PoPSchema\*',
74
        'PoP\*',
75
        'GraphQLByPoP\*',
76
        'GraphQLAPI\*',
77
        // Own container cache
78
        'PoPContainer\*',
79
    ],
80
    'files-whitelist' => [
81
        // Class Composer\InstalledVersions will be regenerated without scope when
82
        // doing `composer dumpautoload`, so skip it
83
        'vendor/composer/InstalledVersions.php',
84
    ],
85
    'patchers' => [
86
        function (string $filePath, string $prefix, string $content): string {
87
            /**
88
             * File vendor/nikic/fast-route/src/bootstrap.php has this code:
89
             *
90
             * if (\strpos($class, 'FastRoute\\') === 0) {
91
             *   $name = \substr($class, \strlen('FastRoute'));
92
             *
93
             * Fix it
94
             */
95
            if ($filePath === __DIR__ . DIRECTORY_SEPARATOR . 'vendor/nikic/fast-route/src/bootstrap.php') {
96
                return str_replace(
97
                    ["'FastRoute\\\\'", "'FastRoute'"],
98
                    ["'${prefix}\\\\FastRoute\\\\'", "'${prefix}\\\\FastRoute'"],
99
                    $content
100
                );
101
            }
102
            /**
103
             * Brain/Cortex is prefixing classes \WP and \WP_Rewrite
104
             * Avoid it!
105
             */
106
            if (str_starts_with($filePath, __DIR__ . DIRECTORY_SEPARATOR . 'vendor/brain/cortex/')) {
107
                return str_replace(
108
                    "\\${prefix}\\WP",
109
                    "\\WP",
110
                    $content
111
                );
112
            }
113
            /**
114
             * Symfony Polyfill packages.
115
             * The bootstrap*.php files must register functions under the global namespace,
116
             * and the other ones must register constants on the global namespace,
117
             * so remove the namespaced after it's added.
118
             * These files can't be whitelisted, because they may reference a prefixed class
119
             */
120
            // Pattern to identify Symfony Polyfill bootstrap files
121
            // - vendor/symfony/polyfill-mbstring/bootstrap80.php
122
            // - vendor/symfony/polyfill-php72/bootstrap.php
123
            // - etc
124
            $pattern = '#' . __DIR__ . '/vendor/symfony/polyfill-[a-zA-Z0-9_-]*/bootstrap.*\.php#';
125
            $symfonyPolyfillFilesWithGlobalClass = array_map(
126
                'convertRelativeToFullPath',
127
                [
128
                    'symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
129
                    'symfony/polyfill-php73/Resources/stubs/JsonException.php',
130
                    'symfony/polyfill-php80/Resources/stubs/Attribute.php',
131
                    'symfony/polyfill-php80/Resources/stubs/Stringable.php',
132
                    'symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
133
                    'symfony/polyfill-php80/Resources/stubs/ValueError.php',
134
                ]
135
            );
136
            $isSymfonyPolyfillFileWithGlobalClass = in_array($filePath, $symfonyPolyfillFilesWithGlobalClass);
137
            if (
138
                $isSymfonyPolyfillFileWithGlobalClass
139
                || preg_match($pattern, $filePath)
140
            ) {
141
                // Remove the namespace
142
                $content = str_replace(
143
                    "namespace ${prefix};",
144
                    '',
145
                    $content
146
                );
147
148
                // Comment out the class_alias too
149
                if ($isSymfonyPolyfillFileWithGlobalClass) {
150
                    $content = str_replace(
151
                        "\class_alias('${prefix}\\\\",
152
                        "//\class_alias('${prefix}\\\\",
153
                        $content
154
                    );
155
                }
156
157
                return $content;
158
            }
159
            /**
160
             * In these files, it prefixes the return type `parent`.
161
             * Undo it!
162
             */
163
            $symfonyPolyfillFilesWithParentReturnType = array_map(
164
                'convertRelativeToFullPath',
165
                [
166
                    'symfony/string/AbstractUnicodeString.php',
167
                    'symfony/string/ByteString.php',
168
                    'symfony/string/UnicodeString.php',
169
                ]
170
            );
171
            if (in_array($filePath, $symfonyPolyfillFilesWithParentReturnType)) {
172
                return str_replace(
173
                    "\\${prefix}\\parent",
174
                    'parent',
175
                    $content
176
                );
177
            }
178
179
            /**
180
             * It changes the path to Parsedown source files in its composer.json
181
             * Undo it!
182
             */
183
            if ($filePath == convertRelativeToFullPath('erusev/parsedown/composer.json')) {
184
                return str_replace(
185
                    ['"\\/Parsedown\\/"', '"psr-4"'],
186
                    ['""', '"psr-0"'],
187
                    $content
188
                );
189
            }
190
191
            return $content;
192
        },
193
    ],
194
];
195