Skip to content

Commit

Permalink
Cleanup and enable unused variable warning
Browse files Browse the repository at this point in the history
- Removes flag ignore warnings in composer.json
- Fixes Unused variable warnings

Most cases were: `foreach ( $some_array as $key => $value )`
with the $key value not being used. If ommited the foreach
will just set the value and ignore the key.
  • Loading branch information
mkaz committed Oct 28, 2020
1 parent a03ea51 commit 08aac8e
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist --runtime-set ignore_warnings_on_exit 1"
"lint": "phpcs --standard=phpcs.xml.dist"
}
}
3 changes: 1 addition & 2 deletions lib/block-supports/generated-classname.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ function gutenberg_get_block_default_classname( $block_name ) {
* Add the generated classnames to the output.
*
* @param WP_Block_Type $block_type Block Type.
* @param array $block_attributes Block attributes.
*
* @return array Block CSS classes and inline styles.
*/
function gutenberg_apply_generated_classname_support( $block_type, $block_attributes ) {
function gutenberg_apply_generated_classname_support( $block_type ) {
$has_generated_classname_support = true;
$attributes = array();
if ( property_exists( $block_type, 'supports' ) ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/class-wp-block-supports.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function apply_block_supports() {
}

$output = array();
foreach ( $this->block_supports as $name => $block_support_config ) {
foreach ( $this->block_supports as $block_support_config ) {
if ( ! isset( $block_support_config['apply'] ) ) {
continue;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ private function register_attributes() {
$block_type->attributes = array();
}

foreach ( $this->block_supports as $name => $block_support_config ) {
foreach ( $this->block_supports as $block_support_config ) {
if ( ! isset( $block_support_config['register_attribute'] ) ) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-block-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function get_items( $request ) {
$namespace = $request['namespace'];
}

foreach ( $block_types as $slug => $obj ) {
foreach ( $block_types as $obj ) {
if ( $namespace ) {
$pieces = explode( '/', $obj->name );
$block_namespace = $pieces[0];
Expand Down
3 changes: 1 addition & 2 deletions lib/class-wp-rest-customizer-nonces.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ public function register_routes() {
/**
* Checks if a given request has access to read menu items if they have access to edit them.
*
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
*/
public function permissions_check( $request ) {
public function permissions_check() {
$post_type = get_post_type_object( 'nav_menu_item' );
if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit posts in this post type.', 'gutenberg' ), array( 'status' => rest_authorization_required_code() ) );
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-widget-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected function get_widgets() {
global $wp_registered_widgets;

$widgets = array();
foreach ( $wp_registered_widgets as $slug => $widget ) {
foreach ( $wp_registered_widgets as $widget ) {
$widget_callback = $widget['callback'];
unset( $widget['callback'] );

Expand Down
5 changes: 2 additions & 3 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ function gutenberg_filter_oembed_result( $response, $handler, $request ) {
*
* @param WP_REST_Response $response The response object.
* @param WP_Theme $theme Theme object used to create response.
* @param WP_REST_Request $request Request object.
*/
function gutenberg_filter_rest_prepare_theme( $response, $theme, $request ) {
function gutenberg_filter_rest_prepare_theme( $response, $theme ) {
$data = $response->get_data();
$fields = array_keys( $data );

Expand Down Expand Up @@ -125,7 +124,7 @@ function gutenberg_filter_rest_prepare_theme( $response, $theme, $request ) {
$response->set_data( $data );
return $response;
}
add_filter( 'rest_prepare_theme', 'gutenberg_filter_rest_prepare_theme', 10, 3 );
add_filter( 'rest_prepare_theme', 'gutenberg_filter_rest_prepare_theme', 10, 2 );

/**
* Registers the block directory.
Expand Down
2 changes: 1 addition & 1 deletion phpunit/class-rest-nav-menu-items-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ protected function check_menu_item_data( $post, $data, $context, $links ) {
$this->assertEquals( $links['about'][0]['href'], rest_url( 'wp/v2/types/' . self::POST_TYPE ) );

$num = 0;
foreach ( $taxonomies as $key => $taxonomy ) {
foreach ( $taxonomies as $taxonomy ) {
$this->assertEquals( $taxonomy->name, $links['https://api.w.org/term'][ $num ]['attributes']['taxonomy'] );
$this->assertEquals( add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/' . $taxonomy->rest_base ) ), $links['https://api.w.org/term'][ $num ]['href'] );
$num ++;
Expand Down

0 comments on commit 08aac8e

Please sign in to comment.