Skip to content

Commit 67b5a6d

Browse files
authored
Merge pull request #2902 from justlevine/chore/handle-unused-variables
chore: handle unused variables (phpcs)
2 parents 1fb731a + 3bf8f33 commit 67b5a6d

File tree

9 files changed

+15
-17
lines changed

9 files changed

+15
-17
lines changed

phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,9 @@
158158
<rule ref="SlevomatCodingStandard.PHP.TypeCast" />
159159

160160
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable" />
161+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable" >
162+
<properties>
163+
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true" />
164+
</properties>
165+
</rule>
161166
</ruleset>

src/Admin/Settings/SettingsRegistry.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ public function callback_wysiwyg( array $args ) {
448448
public function callback_file( array $args ) {
449449
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
450450
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
451-
$id = $args['section'] . '[' . $args['id'] . ']';
452451
$label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File', 'wp-graphql' );
453452

454453
$html = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s">', $size, $args['section'], $args['id'], $value );
@@ -583,7 +582,7 @@ public function get_sanitize_callback( $slug = '' ) {
583582
}
584583

585584
// Iterate over registered fields and see if we can find proper callback
586-
foreach ( $this->settings_fields as $section => $options ) {
585+
foreach ( $this->settings_fields as $options ) {
587586
foreach ( $options as $option ) {
588587
if ( $slug !== $option['name'] ) {
589588
continue;

src/Data/NodeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public function parse_request( string $uri, $extra_query_vars = '' ) {
532532
}
533533

534534
// Convert urldecoded spaces back into '+'.
535-
foreach ( get_taxonomies( [ 'show_in_graphql' => true ], 'objects' ) as $taxonomy => $t ) {
535+
foreach ( get_taxonomies( [ 'show_in_graphql' => true ], 'objects' ) as $t ) {
536536
if ( $t->query_var && isset( $this->wp->query_vars[ $t->query_var ] ) ) {
537537
$this->wp->query_vars[ $t->query_var ] = str_replace( ' ', '+', $this->wp->query_vars[ $t->query_var ] );
538538
}

src/Model/Post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ protected function init() {
549549
if ( empty( $registered_templates ) ) {
550550
return $template;
551551
}
552-
$post_type = $this->data->post_type;
552+
553553
$set_template = get_post_meta( $this->data->ID, '_wp_page_template', true );
554554
$template_name = get_page_template_slug( $this->data->ID );
555555

src/Mutation/MediaItemCreate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static function mutate_and_get_payload() {
155155
$sanitized_file_path = sanitize_file_name( $input['filePath'] );
156156

157157
// Check that the filetype is allowed
158-
$check_file = wp_check_filetype( $uploaded_file_url );
158+
$check_file = wp_check_filetype( $sanitized_file_path );
159159

160160
// if the file doesn't pass the check, throw an error
161161
if ( ! $check_file['ext'] || ! $check_file['type'] || ! wp_http_validate_url( $uploaded_file_url ) ) {

src/Type/Enum/TimezoneEnum.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function register_type() {
4343
load_textdomain( 'continents-cities', $mofile );
4444
$mo_loaded = true;
4545
}
46-
46+
4747
$zonen = [];
4848
foreach ( timezone_identifiers_list() as $zone ) {
4949
$zone = explode( '/', $zone );
@@ -72,18 +72,13 @@ public static function register_type() {
7272
}
7373
usort( $zonen, '_wp_timezone_choice_usort_callback' );
7474

75-
foreach ( $zonen as $key => $zone ) {
75+
foreach ( $zonen as $zone ) {
7676
// Build value in an array to join later
7777
$value = [ $zone['continent'] ];
7878
if ( empty( $zone['city'] ) ) {
7979
// It's at the continent level (generally won't happen)
8080
$display = $zone['t_continent'];
8181
} else {
82-
// It's inside a continent group
83-
// Continent optgroup
84-
if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
85-
$label = $zone['t_continent'];
86-
}
8782
// Add the city to the value
8883
$value[] = $zone['city'];
8984
$display = $zone['t_city'];

src/Type/InterfaceType/ContentTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function register_content_template_types() {
4747
}
4848

4949
// Register each template to the schema
50-
foreach ( $page_templates as $file => $name ) {
50+
foreach ( $page_templates as $name ) {
5151
$name = ucwords( $name );
5252
$replaced_name = preg_replace( '/[^\w]/', '', $name );
5353

src/Type/ObjectType/MediaSize.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public static function register_type() {
4242
'type' => 'Int',
4343
'description' => __( 'The filesize of the resource', 'wp-graphql' ),
4444
'resolve' => static function ( $image, $args, $context, $info ) {
45-
$src_url = null;
46-
4745
if ( ! empty( $image['ID'] ) && ! empty( $image['file'] ) ) {
4846
$original_file = get_attached_file( absint( $image['ID'] ) );
4947
$filesize_path = ! empty( $original_file ) ? path_join( dirname( $original_file ), $image['file'] ) : null;
48+
5049
return ! empty( $filesize_path ) ? filesize( $filesize_path ) : null;
5150
}
5251

src/Type/ObjectType/RootQuery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,8 @@ static function ( $post ) use ( $post_type_object ) {
824824
),
825825
'args' => $post_by_args,
826826
'resolve' => static function ( $source, array $args, $context ) use ( $post_type_object ) {
827-
$post_object = null;
828-
$post_id = 0;
827+
$post_id = 0;
828+
829829
if ( ! empty( $args['id'] ) ) {
830830
$id_components = Relay::fromGlobalId( $args['id'] );
831831
if ( empty( $id_components['id'] ) || empty( $id_components['type'] ) ) {

0 commit comments

Comments
 (0)