Skip to content

Commit

Permalink
Add phpcs rule to detect unused variables; Fix existing issues (#17300)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Sep 25, 2019
1 parent 5327c03 commit a56daeb
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 21 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"squizlabs/php_codesniffer": "^3.4.2",
"phpcompatibility/php-compatibility": "^9.2.0",
"wp-coding-standards/wpcs": "^2.1.1"
"wp-coding-standards/wpcs": "^2.1.1",
"sirbrillig/phpcs-variable-analysis": "^2.7"
},
"require": {
"composer/installers": "~1.0"
Expand Down
52 changes: 50 additions & 2 deletions composer.lock

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

1 change: 1 addition & 0 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function gutenberg_build_files_notice() {
* @since 1.5.0
*/
function gutenberg_pre_init() {
global $wp_version;
if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) {
add_action( 'admin_notices', 'gutenberg_build_files_notice' );
return;
Expand Down
12 changes: 6 additions & 6 deletions lib/class-wp-rest-block-directory-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ public function register_routes() {
*
* @since 6.5.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
*/
public function permissions_check( $request ) {
public function permissions_check() {
if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) ) {
return new WP_Error(
'rest_user_cannot_view',
Expand Down Expand Up @@ -221,8 +220,8 @@ public function get_items( $request ) {

include( ABSPATH . WPINC . '/version.php' );

$url = 'http:https://api.wordpress.org/plugins/info/1.2/';
$url = add_query_arg(
$url = 'http:https://api.wordpress.org/plugins/info/1.2/';
$url = add_query_arg(
array(
'action' => 'query_plugins',
'request[block]' => $search_string,
Expand All @@ -231,11 +230,12 @@ public function get_items( $request ) {
),
$url
);
$http_url = $url;
$ssl = wp_http_supports( array( 'ssl' ) );
$ssl = wp_http_supports( array( 'ssl' ) );
if ( $ssl ) {
$url = set_url_scheme( $url, 'https' );
}

global $wp_version;
$http_args = array(
'timeout' => 15,
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
Expand Down
14 changes: 8 additions & 6 deletions lib/class-wp-rest-widget-areas-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ public function register_routes() {
'validate_callback' => 'Experimental_WP_Widget_Blocks_Manager::is_valid_sidabar_id',
);

$content_argument = array(
'description' => __( 'Sidebar content.', 'gutenberg' ),
'type' => 'string',
'required' => true,
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>.+)',
Expand Down Expand Up @@ -141,6 +135,9 @@ public function get_item_schema() {
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|bool True if the request has read access, WP_Error object otherwise.
*
* This function is overloading a function defined in WP_REST_Controller so it should have the same parameters.
* phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_items_permissions_check( $request ) {
if ( ! current_user_can( 'edit_theme_options' ) ) {
Expand All @@ -152,6 +149,7 @@ public function get_items_permissions_check( $request ) {

return true;
}
/* phpcs:enable */

/**
* Retrieves all widget areas.
Expand Down Expand Up @@ -192,6 +190,9 @@ public function get_item( $request ) {
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|bool True if the request has access to update the item, error object otherwise.
*
* This function is overloading a function defined in WP_REST_Controller so it should have the same parameters.
* phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function update_item_permissions_check( $request ) {
if ( ! current_user_can( 'edit_theme_options' ) ) {
Expand All @@ -203,6 +204,7 @@ public function update_item_permissions_check( $request ) {

return true;
}
/* phpcs:enable */

/**
* Updates a single widget area.
Expand Down
2 changes: 0 additions & 2 deletions lib/class-wp-rest-widget-updater-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public function compute_new_widget_permissions_check() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function compute_new_widget( $request ) {
$url_params = $request->get_url_params();

$widget = $request->get_param( 'identifier' );

global $wp_widget_factory;
Expand Down
1 change: 0 additions & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ function gutenberg_register_scripts_and_styles() {
//
// See: https://core.trac.wordpress.org/ticket/46107 .
// See: https://github.com/WordPress/gutenberg/pull/13451 .
global $wp_scripts;
if ( isset( $wp_scripts->registered['wp-api-fetch'] ) ) {
$wp_scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
}
Expand Down
4 changes: 1 addition & 3 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
* The main entry point for the Gutenberg experiments page.
*
* @since 6.3.0
*
* @param string $page The page name the function is being called for, `'gutenberg_customizer'` for the Customizer.
*/
function the_gutenberg_experiments( $page = 'gutenberg_page_gutenberg-experiments' ) {
function the_gutenberg_experiments() {
?>
<div
id="experiments-editor"
Expand Down
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="gutenberg,default"/>

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="allowUnusedParametersBeforeUsed" value="true"/>
</properties>
</rule>
<rule ref="WordPress.CodeAnalysis.EmptyStatement"/>

<rule ref="PEAR.Functions.FunctionCallSignature">
Expand Down

0 comments on commit a56daeb

Please sign in to comment.