Skip to content

Commit ccfb39d

Browse files
committed
lint: fix psalm errors
1 parent 5ba71b5 commit ccfb39d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

plugins/wpgraphql-logging/src/Admin/View/List/List_Table.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,36 @@ public function get_bulk_actions(): array {
121121
*/
122122
public function process_bulk_action(): void {
123123
$action = $this->current_action();
124+
124125
if ( ! in_array( $action, [ 'delete', 'bulk_delete', 'delete_all' ], true ) ) {
125126
return;
126127
}
127128

129+
// Nonce action WordPress uses for bulk actions is 'bulk-' . $this->_args['plural']
128130
$nonce_action = 'bulk-' . $this->_args['plural'];
129-
$nonce = $_REQUEST['_wpnonce'] ?? '';
130-
131-
if ( false === wp_verify_nonce( $nonce, $nonce_action ) ) {
131+
$nonce_value = $_REQUEST['_wpnonce'] ?? '';
132+
133+
// Ensure nonce is a string for wp_verify_nonce
134+
$nonce = is_string( $nonce_value ) ? $nonce_value : '';
135+
136+
// Fix for PHPStan: wp_verify_nonce returns int|false, need explicit boolean check
137+
$nonce_result = wp_verify_nonce( $nonce, $nonce_action );
138+
if ( false === $nonce_result ) {
132139
wp_die( esc_html__( 'Nonce verification failed!', 'wpgraphql-logging' ) );
133140
}
134141

135142
$deleted_count = 0;
136143

137-
// WordPress sometimes sends 'delete' for selected items (action or action2), treat it as 'bulk_delete'.
144+
// WordPress sometimes sends 'delete' for selected items
138145
if ( in_array( $action, [ 'delete', 'bulk_delete' ], true ) && ! empty( $_REQUEST['log'] ) ) {
139146
$ids = array_map( 'absint', (array) $_REQUEST['log'] );
140-
if ( ! empty( $ids ) ) {
141-
foreach ( $ids as $id ) {
147+
// Remove redundant empty check since array_map always returns array
148+
foreach ( $ids as $id ) {
149+
if ( $id > 0 ) { // Only process valid IDs
142150
$this->repository->delete( $id );
143151
}
144-
$deleted_count = count( $ids );
145152
}
153+
$deleted_count = count( array_filter( $ids, static fn( $id ) => $id > 0 ) );
146154
}
147155

148156
if ( 'delete_all' === $action ) {
@@ -152,13 +160,14 @@ public function process_bulk_action(): void {
152160
}
153161

154162
if ( $deleted_count > 0 ) {
155-
// Preserve filters during redirect.
163+
// Preserve filters during redirect
156164
$preserved_filters = [];
157165
$filter_keys = [ 'level_filter', 'start_date', 'end_date' ];
158166

159167
foreach ( $filter_keys as $key ) {
160-
if ( ! empty( $_REQUEST[ $key ] ) ) {
161-
$preserved_filters[ $key ] = sanitize_text_field( wp_unslash( (string) $_REQUEST[ $key ] ) );
168+
$value = $_REQUEST[ $key ] ?? null;
169+
if ( ! empty( $value ) && is_string( $value ) ) {
170+
$preserved_filters[ $key ] = sanitize_text_field( wp_unslash( $value ) );
162171
}
163172
}
164173

@@ -175,8 +184,7 @@ public function process_bulk_action(): void {
175184
exit;
176185
}
177186
}
178-
179-
187+
180188
/**
181189
* Get the columns for the logs table.
182190
*

0 commit comments

Comments
 (0)