Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PHP-Scoper to v0.16.2 #10511

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"roave/security-advisories": "dev-latest",
"sirbrillig/phpcs-variable-analysis": "^2.8",
"slevomat/coding-standard": "^7.0.18",
"sniccowp/php-scoper-wordpress-excludes": "^5.9",
"szepeviktor/phpstan-wordpress": "^1.0",
"wp-coding-standards/wpcs": "^2.3",
"yoast/wp-test-utils": "^1.0.0"
Expand Down Expand Up @@ -87,7 +88,7 @@
"php-scoper": {
"path": "vendor/bin/php-scoper",
"type": "phar",
"url": "https://github.com/humbug/php-scoper/releases/download/0.15.0/php-scoper.phar"
"url": "https://github.com/humbug/php-scoper/releases/download/0.16.2/php-scoper.phar"
}
},
"enable-patching": true,
Expand Down
88 changes: 67 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 36 additions & 93 deletions scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

use Isolated\Symfony\Component\Finder\Finder;

$wp_classes = json_decode( file_get_contents( 'vendor/sniccowp/php-scoper-wordpress-excludes/generated/exclude-wordpress-classes.json' ) );
$wp_functions = json_decode( file_get_contents( 'vendor/sniccowp/php-scoper-wordpress-excludes/generated/exclude-wordpress-functions.json' ) );
$wp_constants = json_decode( file_get_contents( 'vendor/sniccowp/php-scoper-wordpress-excludes/generated/exclude-wordpress-constants.json' ) );
swissspidy marked this conversation as resolved.
Show resolved Hide resolved

return [
'prefix' => 'Google\\Web_Stories_Dependencies',
'prefix' => 'Google\\Web_Stories_Dependencies',

// See: https://github.com/humbug/php-scoper#finders-and-paths.
'finders' => [
'finders' => [
// Main AMP PHP Library.
Finder::create()
->files()
Expand Down Expand Up @@ -173,99 +177,38 @@
],

// See: https://github.com/humbug/php-scoper#patchers.
'patchers' => [
function ( $file_path, $prefix, $contents ) {
/*
* There is currently no easy way to simply whitelist all global WordPress functions.
*
* This list here is a manual attempt after scanning through the AMP plugin, which means
* it needs to be maintained and kept in sync with any changes to the dependency.
*
* As long as there's no built-in solution in PHP-Scoper for this, an alternative could be
* to generate a list based on php-stubs/wordpress-stubs. devowlio/wp-react-starter/ seems
* to be doing just this successfully.
*
* @see https://github.com/humbug/php-scoper/issues/303
* @see https://github.com/php-stubs/wordpress-stubs
* @see https://github.com/devowlio/wp-react-starter/
*/
$contents = str_replace( "\\$prefix\\_doing_it_wrong", '\\_doing_it_wrong', $contents );
$contents = str_replace( "\\$prefix\\__", '\\__', $contents );
$contents = str_replace( "\\$prefix\\esc_html_e", '\\esc_html_e', $contents );
$contents = str_replace( "\\$prefix\\esc_html", '\\esc_html', $contents );
$contents = str_replace( "\\$prefix\\esc_attr", '\\esc_attr', $contents );
$contents = str_replace( "\\$prefix\\esc_url", '\\esc_url', $contents );
$contents = str_replace( "\\$prefix\\site_url", '\\site_url', $contents );
$contents = str_replace( "\\$prefix\\wp_guess_url", '\\wp_guess_url', $contents );
$contents = str_replace( "\\$prefix\\untrailingslashit", '\\untrailingslashit', $contents );
$contents = str_replace( "\\$prefix\\WP_CONTENT_URL", '\\WP_CONTENT_URL', $contents );
$contents = str_replace( "\\$prefix\\wp_list_pluck", '\\wp_list_pluck', $contents );
$contents = str_replace( "\\$prefix\\is_customize_preview", '\\is_customize_preview', $contents );
$contents = str_replace( "\\$prefix\\do_action", '\\do_action', $contents );
$contents = str_replace( "\\$prefix\\trailingslashit", '\\trailingslashit', $contents );
$contents = str_replace( "\\$prefix\\get_template_directory_uri", '\\get_template_directory_uri', $contents );
$contents = str_replace( "\\$prefix\\get_stylesheet_directory_uri", '\\get_stylesheet_directory_uri', $contents );
$contents = str_replace( "\\$prefix\\includes_url", '\\includes_url', $contents );
$contents = str_replace( "\\$prefix\\wp_styles", '\\wp_styles', $contents );
$contents = str_replace( "\\$prefix\\get_stylesheet", '\\get_stylesheet', $contents );
$contents = str_replace( "\\$prefix\\get_template", '\\get_template', $contents );
$contents = str_replace( "\\$prefix\\wp_parse_url", '\\wp_parse_url', $contents );
$contents = str_replace( "\\$prefix\\is_wp_error", '\\is_wp_error', $contents );
$contents = str_replace( "\\$prefix\\content_url", '\\content_url', $contents );
$contents = str_replace( "\\$prefix\\get_admin_url", '\\get_admin_url', $contents );
$contents = str_replace( "\\$prefix\\WP_CONTENT_DIR", '\\WP_CONTENT_DIR', $contents );
$contents = str_replace( "\\$prefix\\AMP__FILE__", '\\AMP__FILE__', $contents );
$contents = str_replace( "\\$prefix\\AMP__DIR__", '\\AMP__DIR__', $contents );
$contents = str_replace( "\\$prefix\\AMP__VERSION", '\\AMP__VERSION', $contents );
$contents = str_replace( "\\$prefix\\ABSPATH", '\\ABSPATH', $contents );
$contents = str_replace( "\\$prefix\\WPINC", '\\WPINC', $contents );
$contents = str_replace( "\\$prefix\\MINUTE_IN_SECONDS", '\\MINUTE_IN_SECONDS', $contents );
$contents = str_replace( "\\$prefix\\HOUR_IN_SECONDS", '\\HOUR_IN_SECONDS', $contents );
$contents = str_replace( "\\$prefix\\DAY_IN_SECONDS", '\\DAY_IN_SECONDS', $contents );
$contents = str_replace( "\\$prefix\\MONTH_IN_SECONDS", '\\MONTH_IN_SECONDS', $contents );
$contents = str_replace( "\\$prefix\\WP_DEBUG_DISPLAY", '\\WP_DEBUG_DISPLAY', $contents );
$contents = str_replace( "\\$prefix\\home_url", '\\home_url', $contents );
$contents = str_replace( "\\$prefix\\wp_array_slice_assoc", '\\wp_array_slice_assoc', $contents );
$contents = str_replace( "\\$prefix\\wp_json_encode", '\\wp_json_encode', $contents );
$contents = str_replace( "\\$prefix\\get_transient", '\\get_transient', $contents );
$contents = str_replace( "\\$prefix\\wp_cache_get", '\\wp_cache_get', $contents );
$contents = str_replace( "\\$prefix\\set_transient", '\\set_transient', $contents );
$contents = str_replace( "\\$prefix\\wp_cache_set", '\\wp_cache_set', $contents );
$contents = str_replace( "\\$prefix\\wp_using_ext_object_cache", '\\wp_using_ext_object_cache', $contents );
$contents = str_replace( "\\$prefix\\_doing_it_wrong", '\\_doing_it_wrong', $contents );
$contents = str_replace( "\\$prefix\\plugin_dir_url", '\\plugin_dir_url', $contents );
$contents = str_replace( "\\$prefix\\is_admin_bar_showing", '\\is_admin_bar_showing', $contents );
$contents = str_replace( "\\$prefix\\get_bloginfo", '\\get_bloginfo', $contents );
$contents = str_replace( "\\$prefix\\add_filter", '\\add_filter', $contents );
$contents = str_replace( "\\$prefix\\remove_filter", '\\remove_filter', $contents );
$contents = str_replace( "\\$prefix\\apply_filters", '\\apply_filters', $contents );
$contents = str_replace( "\\$prefix\\add_query_arg", '\\add_query_arg', $contents );
$contents = str_replace( "\\$prefix\\remove_query_arg", '\\remove_query_arg', $contents );
$contents = str_replace( "\\$prefix\\get_post", '\\get_post', $contents );
$contents = str_replace( "\\$prefix\\wp_scripts", '\\wp_scripts', $contents );
$contents = str_replace( "\\$prefix\\wp_style_is", '\\wp_style_is', $contents );
$contents = str_replace( "\\$prefix\\WPMU_PLUGIN_DIR", '\\WPMU_PLUGIN_DIR', $contents );
$contents = str_replace( "\\$prefix\\WP_PLUGIN_DIR", '\\WP_PLUGIN_DIR', $contents );
$contents = str_replace( "\\$prefix\\WP_PLUGIN_URL", '\\WP_PLUGIN_URL', $contents );
$contents = str_replace( "\\$prefix\\WPMU_PLUGIN_URL", '\\WPMU_PLUGIN_URL', $contents );
$contents = str_replace( "\\$prefix\\wp_array_slice_assoc", '\\wp_array_slice_assoc', $contents );
$contents = str_replace( "\\$prefix\\wp_json_encode", '\\wp_json_encode', $contents );
$contents = str_replace( "$prefix\\WP_Http", 'WP_Http', $contents );
$contents = str_replace( "$prefix\\WP_Error", 'WP_Error', $contents );

return $contents;
},
],
'patchers' => [],

// See https://github.com/humbug/php-scoper#whitelist.
'whitelist' => [],

// See https://github.com/humbug/php-scoper#constants--classes--functions-from-the-global-namespace.
'whitelist-global-constants' => false,
'whitelist' => [],

// See https://github.com/humbug/php-scoper#constants--classes--functions-from-the-global-namespace.
'whitelist-global-classes' => false,
'exclude-classes' => $wp_classes,

// See https://github.com/humbug/php-scoper#constants--classes--functions-from-the-global-namespace.
'whitelist-global-functions' => false,
'exclude-functions' => $wp_functions,

// Currently exclude-wordpress-constants.json is empty [].
// Issue https://github.com/sniccowp/php-scoper-wordpress-excludes/issues/2 .
// If fixed we can remove the hardcoded WP constants.

'exclude-constants' => array_merge(
$wp_constants,
[
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
'WP_CONTENT_DIR',
'WP_CONTENT_URL',
'ABSPATH',
'WPINC',
'WP_DEBUG_DISPLAY',
'WPMU_PLUGIN_DIR',
'WP_PLUGIN_DIR',
'WP_PLUGIN_URL',
'WPMU_PLUGIN_URL',
'AMP__FILE__',
'AMP__DIR__',
'AMP__VERSION',
'MINUTE_IN_SECONDS',
'HOUR_IN_SECONDS',
'DAY_IN_SECONDS',
'MONTH_IN_SECONDS',
]
),
];