From 7634a8d71fb71eb2883d3bac5817d1bf1259b0b5 Mon Sep 17 00:00:00 2001 From: Mohan Raj Date: Sun, 11 Feb 2024 17:22:15 +0000 Subject: [PATCH] fix phpcs errors --- composer.json | 2 +- composer.lock | 14 +++++++------- includes/Api/Flags.php | 9 +++++---- includes/Flag.php | 10 +++++----- plugin.php | 4 ++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index f4925df..3f65f7f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "wordpress/wordpress": "^6.4", "phpunit/phpunit": "^9.4", "brain/monkey": "^2.6", - "newsuk/nuk-wp-phpcs-config": "^0.1.0", + "newsuk/nuk-wp-phpcs-config": "^0.2.0", "newsuk/nuk-wp-phpstan-config": "^0.1.0", "newsuk/nuk-wp-phpmd-config": "^0.1.0", "yoast/wp-test-utils": "^1.2" diff --git a/composer.lock b/composer.lock index 8aa3dc8..8fd3236 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1afbaeb104a5222a664f1628b3f4668e", + "content-hash": "18ffe1f48b59bc950dcf57d4a504e218", "packages": [], "packages-dev": [ { @@ -716,16 +716,16 @@ }, { "name": "newsuk/nuk-wp-phpcs-config", - "version": "v0.1.0", + "version": "v0.2.0", "source": { "type": "git", "url": "https://github.com/newsuk/nuk-wp-phpcs-config.git", - "reference": "71ea2a822b75663a5698f0e5500d15fd0b17f25c" + "reference": "4b40381fdef843885ea71d098c753378c659a68d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newsuk/nuk-wp-phpcs-config/zipball/71ea2a822b75663a5698f0e5500d15fd0b17f25c", - "reference": "71ea2a822b75663a5698f0e5500d15fd0b17f25c", + "url": "https://api.github.com/repos/newsuk/nuk-wp-phpcs-config/zipball/4b40381fdef843885ea71d098c753378c659a68d", + "reference": "4b40381fdef843885ea71d098c753378c659a68d", "shasum": "" }, "require": { @@ -749,9 +749,9 @@ "description": "PHPCS configuration for WordPress VIP plugins and themes", "support": { "issues": "https://github.com/newsuk/nuk-wp-phpcs-config/issues", - "source": "https://github.com/newsuk/nuk-wp-phpcs-config/tree/v0.1.0" + "source": "https://github.com/newsuk/nuk-wp-phpcs-config/tree/v0.2.0" }, - "time": "2024-01-16T15:38:00+00:00" + "time": "2024-02-05T10:05:13+00:00" }, { "name": "newsuk/nuk-wp-phpmd-config", diff --git a/includes/Api/Flags.php b/includes/Api/Flags.php index 1fd5438..0b93527 100644 --- a/includes/Api/Flags.php +++ b/includes/Api/Flags.php @@ -54,14 +54,14 @@ public function register_routes(): void { [ 'methods' => WP_REST_Server::READABLE, 'callback' => [ $this, 'get_all_flags' ], - 'permission_callback' => function () { + 'permission_callback' => static function () { return current_user_can( 'manage_options' ); }, ], [ 'methods' => WP_REST_Server::EDITABLE, 'callback' => [ $this, 'post_flags' ], - 'permission_callback' => function () { + 'permission_callback' => static function () { return current_user_can( 'manage_options' ); }, 'validate_callback' => [ $this, 'validate_flag_input' ], @@ -108,10 +108,11 @@ public function post_flags( WP_REST_Request $request ) { * Validates flag input from POST method. * * @param WP_REST_Request $request Request object. - * * @return bool + * + * @phpstan-param WP_REST_Request $request */ - public function validate_flag_input( $request ) { + public function validate_flag_input( WP_REST_Request $request ) { $input_data = $request->get_json_params(); if ( ! isset( $input_data['flags'] ) || gettype( $input_data['flags'] ) !== 'array' ) { diff --git a/includes/Flag.php b/includes/Flag.php index b344452..4c1a43f 100644 --- a/includes/Flag.php +++ b/includes/Flag.php @@ -34,13 +34,13 @@ class Flag { * @since 1.0.0 */ public static function is_enabled( string $flag ): bool { - $flags = get_option( self::$option_name ); + $flags = get_option( self::$option_name, [] ); - $helper = new Helper(); - if ( $helper->search_flag( $flags, 'name', $flag ) ) { - return true; + if ( ! is_array( $flags ) ) { + return false; } - return false; + $helper = new Helper(); + return $helper->search_flag( $flags, 'name', $flag ); } } diff --git a/plugin.php b/plugin.php index 5724cfa..e4ca6be 100644 --- a/plugin.php +++ b/plugin.php @@ -39,7 +39,7 @@ // Enqueure scripts, styles in settings page. add_action( 'admin_enqueue_scripts', - function ( string $page ): void { + static function ( string $page ): void { if ( 'toplevel_page_mr-feature-flags' === $page ) { mr_feature_flags_load_settings_scripts(); } @@ -130,7 +130,7 @@ function mr_feature_flags_scripts_enqueue(): void { // Displays setting page link in plugin page. add_filter( 'plugin_action_links_mr-feature-flags/plugin.php', - function ( $links ) { + static function ( $links ) { $url = esc_url( add_query_arg( 'page',