-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoper.custom.php
More file actions
48 lines (42 loc) · 1.5 KB
/
scoper.custom.php
File metadata and controls
48 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
/*
* This file is part of the Wonolog WordPress plugin.
*
* (ɔ) Frugan <dev@frugan.it>
*
* This source file is subject to the GNU GPLv3 or later license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Customize PHP Scoper configuration to fix Rector namespace conflicts.
*
* @param array $config Pre-configured configuration array from wpify/scoper
*
* @return array Valid PHP Scoper configuration array
*/
function customize_php_scoper_config(array $config): array
{
// Remove namespace prefix from constants in defined() calls
$config['patchers'][] = static fn (string $filePath, string $prefix, string $content): string => str_replace(
sprintf("defined('%s\\", $prefix),
"defined('",
$content
);
// Add a patcher to restore original Rector namespaces in rector-migrate.php files
// These files are configuration files for Rector and must use non-scoped Rector classes
$config['patchers'][] = static function (string $filePath, string $prefix, string $content): string {
// Check if this is a rector-migrate.php file
if (str_contains($filePath, 'thecodingmachine/safe')
&& str_contains($filePath, 'rector-migrate.php')) {
// Restore original Rector namespaces
return str_replace(
'WpSpaghetti\Deps\Rector\\',
'Rector\\',
$content
);
}
return $content;
};
return $config;
}