Skip to content

Commit

Permalink
Upgrade PHPCS standards and fix issues, excluding ExceptionNotEscaped.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbowler committed Jul 1, 2024
1 parent 8240ccf commit 9c3d558
Show file tree
Hide file tree
Showing 294 changed files with 835 additions and 763 deletions.
4 changes: 2 additions & 2 deletions bin/check-commit-msg.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ function echo_error_if( $condition, $message ) {
if ( $condition ) {
$has_color_support = has_color_support();

// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite,WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fwrite,WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite
$has_color_support && fwrite( STDERR, "\033[31m" );
fwrite( STDERR, '- ' . $message );
$has_color_support && fwrite( STDERR, "\033[0m" );
fwrite( STDERR, PHP_EOL );
// phpcs:enable WordPress.WP.AlternativeFunctions.file_system_read_fwrite,WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite
// phpcs:enable WordPress.WP.AlternativeFunctions.file_system_operations_fwrite,WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite

return $current_code;
}
Expand Down
2 changes: 1 addition & 1 deletion bin/prepare-commit-msg.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

$message[0] = implode( ' ', $tokens );

// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents,WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents,WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
file_put_contents( $argv[1], implode( PHP_EOL, $message ) );
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"type": "wordpress-plugin",
"homepage": "https://sitekit.withgoogle.com",
"require-dev": {
"automattic/vipwpcs": "^2",
"automattic/vipwpcs": "^3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"phpunit/phpunit": "^9.0",
"roave/security-advisories": "dev-latest",
"roots/wordpress": ">=5.2",
"squizlabs/php_codesniffer": "^3.7",
"wp-coding-standards/wpcs": "^2",
"wp-coding-standards/wpcs": "^3",
"wp-phpunit/wp-phpunit": ">=5.2",
"yoast/phpunit-polyfills": "^2.0"
},
Expand Down
572 changes: 422 additions & 150 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions includes/Core/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Notices {
* @since 1.0.0
*/
public function register() {
$callback = function() {
$callback = function () {
global $hook_suffix;

if ( empty( $hook_suffix ) ) {
Expand Down Expand Up @@ -85,7 +85,7 @@ private function get_notices() {

return array_filter(
$notices,
function( $notice ) {
function ( $notice ) {
return $notice instanceof Notice;
}
);
Expand Down
3 changes: 1 addition & 2 deletions includes/Core/Admin/Plugin_Action_Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ function ( $links ) {
);

array_unshift( $links, $settings_link );
};
}

return $links;
}
);
}

}
1 change: 0 additions & 1 deletion includes/Core/Admin/Plugin_Row_Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ private function get_plugin_row_meta() {
'<a href="https://wordpress.org/support/plugin/google-site-kit/#new-post">' . __( 'Support', 'google-site-kit' ) . '</a>',
);
}

}
6 changes: 3 additions & 3 deletions includes/Core/Admin/Pointers.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function enqueue_pointers( $hook_suffix ) {

$active_pointers = array_filter(
$pointers,
function( Pointer $pointer ) use ( $hook_suffix ) {
function ( Pointer $pointer ) use ( $hook_suffix ) {
return $pointer->is_active( $hook_suffix );
}
);
Expand All @@ -66,7 +66,7 @@ function( Pointer $pointer ) use ( $hook_suffix ) {

add_action(
'admin_print_footer_scripts',
function() use ( $active_pointers ) {
function () use ( $active_pointers ) {
foreach ( $active_pointers as $pointer ) {
$this->print_pointer_script( $pointer );
}
Expand All @@ -93,7 +93,7 @@ private function get_pointers() {

return array_filter(
$pointers,
function( $pointer ) {
function ( $pointer ) {
return $pointer instanceof Pointer;
}
);
Expand Down
9 changes: 4 additions & 5 deletions includes/Core/Admin/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function add( Context $context ) {
*/
add_action(
'current_screen',
function() {
function () {
global $menu, $_wp_admin_css_colors;

if ( ! is_array( $menu ) ) {
Expand All @@ -180,7 +180,6 @@ function() {
break;
}
}

},
100
);
Expand All @@ -198,7 +197,7 @@ function() {
$this->args['menu_title'],
$this->args['capability'],
$this->slug,
function() use ( $context ) {
function () use ( $context ) {
$this->render( $context );
}
);
Expand Down Expand Up @@ -232,7 +231,7 @@ public function enqueue_assets( Assets $assets ) {

$cb = is_callable( $this->args['enqueue_callback'] )
? $this->args['enqueue_callback']
: function( Assets $assets ) {
: function ( Assets $assets ) {
$assets->enqueue_asset( $this->slug );
};

Expand All @@ -249,7 +248,7 @@ public function enqueue_assets( Assets $assets ) {
private function render( Context $context ) {
$cb = is_callable( $this->args['render_callback'] )
? $this->args['render_callback']
: function() {
: function () {
printf( '<div id="js-%s" class="googlesitekit-page"></div>', esc_attr( $this->slug ) );
};

Expand Down
23 changes: 11 additions & 12 deletions includes/Core/Admin/Screens.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,29 @@ public function register() {
if ( $this->context->is_network_mode() ) {
add_action(
'network_admin_menu',
function() {
function () {
$this->add_screens();
}
);
}

add_action(
'admin_menu',
function() {
function () {
$this->add_screens();
}
);

add_action(
'admin_enqueue_scripts',
function( $hook_suffix ) {
function ( $hook_suffix ) {
$this->enqueue_screen_assets( $hook_suffix );
}
);

add_action(
'admin_page_access_denied',
function() {
function () {
// Redirect dashboard to splash if no dashboard access (yet).
$this->no_access_redirect_dashboard_to_splash();
// Redirect splash to (shared) dashboard if splash is dismissed.
Expand All @@ -138,7 +138,7 @@ function() {
// Ensure the menu icon always is rendered correctly, without enqueueing a global CSS file.
add_action(
'admin_head',
function() {
function () {
?>
<style type="text/css">
#adminmenu .toplevel_page_googlesitekit-dashboard img {
Expand All @@ -153,7 +153,7 @@ function() {
}
);

$remove_notices_callback = function() {
$remove_notices_callback = function () {
global $hook_suffix;

if ( empty( $hook_suffix ) ) {
Expand All @@ -171,7 +171,7 @@ function() {
add_filter( 'custom_menu_order', '__return_true' );
add_filter(
'menu_order',
function( array $menu_order ) {
function ( array $menu_order ) {
// Move the Site Kit dashboard menu item to be one after the index.php item if it exists.
$dashboard_index = array_search( 'index.php', $menu_order, true );

Expand Down Expand Up @@ -232,7 +232,7 @@ private function add_screen( Screen $screen ) {

add_action(
"load-{$hook_suffix}",
function() use ( $screen ) {
function () use ( $screen ) {
$screen->initialize( $this->context );
}
);
Expand Down Expand Up @@ -360,14 +360,14 @@ private function get_screens() {
array(
'title' => __( 'Dashboard', 'google-site-kit' ),
'capability' => Permissions::VIEW_DASHBOARD,
'enqueue_callback' => function( Assets $assets ) {
'enqueue_callback' => function ( Assets $assets ) {
if ( $this->context->input()->filter( INPUT_GET, 'permaLink' ) ) {
$assets->enqueue_asset( 'googlesitekit-entity-dashboard' );
} else {
$assets->enqueue_asset( 'googlesitekit-main-dashboard' );
}
},
'render_callback' => function( Context $context ) {
'render_callback' => function ( Context $context ) {
$is_view_only = ! $this->authentication->is_authenticated();

$setup_slug = htmlspecialchars( $context->input()->filter( INPUT_GET, 'slug' ) ?: '' );
Expand Down Expand Up @@ -408,7 +408,7 @@ private function get_screens() {
'capability' => Permissions::VIEW_SPLASH,
'parent_slug' => $show_splash_in_menu ? Screen::MENU_SLUG : self::PARENT_SLUG_NULL,
// This callback will redirect to the dashboard on successful authentication.
'initialize_callback' => function( Context $context ) {
'initialize_callback' => function ( Context $context ) {
// Get the dismissed items for this user.
$user_options = new User_Options( $context );
$dismissed_items = new Dismissed_Items( $user_options );
Expand Down Expand Up @@ -482,5 +482,4 @@ private function get_screens() {

return $screens;
}

}
5 changes: 2 additions & 3 deletions includes/Core/Admin/Standalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ final class Standalone {
public function __construct( Context $context ) {

$this->context = $context;

}

/**
Expand All @@ -64,7 +63,7 @@ public function register() {
*/
add_filter(
'admin_body_class',
function( $admin_body_classes ) {
function ( $admin_body_classes ) {
return "{$admin_body_classes} googlesitekit-standalone";
}
);
Expand All @@ -76,7 +75,7 @@ function( $admin_body_classes ) {

add_action(
'admin_head',
function() {
function () {
$this->print_standalone_styles();
}
);
Expand Down
14 changes: 7 additions & 7 deletions includes/Core/Admin_Bar/Admin_Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
*/
final class Admin_Bar {

use Requires_Javascript_Trait, Method_Proxy_Trait;
use Requires_Javascript_Trait;
use Method_Proxy_Trait;

/**
* Plugin context.
Expand Down Expand Up @@ -111,14 +112,14 @@ public function register() {
add_filter( 'amp_dev_mode_element_xpaths', array( $this, 'add_amp_dev_mode' ) );
add_filter(
'googlesitekit_rest_routes',
function( $routes ) {
function ( $routes ) {
return array_merge( $routes, $this->get_rest_routes() );
}
);

add_filter(
'googlesitekit_apifetch_preload_paths',
function( $routes ) {
function ( $routes ) {
return array_merge(
$routes,
array(
Expand Down Expand Up @@ -354,11 +355,11 @@ private function enqueue_assets() {
* @return array List of REST_Route objects.
*/
private function get_rest_routes() {
$can_authenticate = function() {
$can_authenticate = function () {
return current_user_can( Permissions::AUTHENTICATE );
};

$settings_callback = function() {
$settings_callback = function () {
return array(
'enabled' => $this->admin_bar_enabled->get(),
);
Expand All @@ -375,7 +376,7 @@ private function get_rest_routes() {
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => function( WP_REST_Request $request ) use ( $settings_callback ) {
'callback' => function ( WP_REST_Request $request ) use ( $settings_callback ) {
$data = $request->get_param( 'data' );

if ( isset( $data['enabled'] ) ) {
Expand All @@ -402,5 +403,4 @@ private function get_rest_routes() {
),
);
}

}
1 change: 0 additions & 1 deletion includes/Core/Admin_Bar/Admin_Bar_Enabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ protected function get_default() {
protected function get_sanitize_callback() {
return 'boolval';
}

}
Loading

0 comments on commit 9c3d558

Please sign in to comment.