Skip to content

Commit 74a2821

Browse files
committed
Fixed code quality issues with phpcs
1 parent d887e72 commit 74a2821

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public function get_bulk_actions(): array {
118118
*
119119
* @phpcs:disable WordPress.Security.NonceVerification.Missing
120120
* @phpcs:disable WordPress.Security.NonceVerification.Recommended
121+
* @phpcs:disable Generic.Metrics.NestingLevel.TooHigh
122+
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
123+
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
124+
* @phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
121125
*/
122126
public function process_bulk_action(): void {
123127
$action = $this->current_action();
@@ -126,8 +130,8 @@ public function process_bulk_action(): void {
126130
return;
127131
}
128132

129-
$nonce_action = 'bulk-' . $this->_args['plural'];
130-
$nonce_value = $_REQUEST['_wpnonce'] ?? '';
133+
$nonce_action = 'bulk-' . esc_attr( $this->_args['plural'] );
134+
$nonce_value = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST['_wpnonce'] ) ) : '';
131135

132136
$nonce = is_string( $nonce_value ) ? $nonce_value : '';
133137

@@ -141,9 +145,9 @@ public function process_bulk_action(): void {
141145
// WordPress sometimes sends 'delete' for selected items.
142146
if ( in_array( $action, [ 'delete', 'bulk_delete' ], true ) && ! empty( $_REQUEST['log'] ) ) {
143147
$ids = array_map( 'absint', (array) $_REQUEST['log'] );
144-
// Remove redundant empty check since array_map always returns array
148+
// Remove redundant empty check since array_map always returns array.
145149
foreach ( $ids as $id ) {
146-
if ( $id > 0 ) { // Only process valid IDs
150+
if ( $id > 0 ) { // Only process valid IDs.
147151
$this->repository->delete( $id );
148152
}
149153
}
@@ -164,9 +168,9 @@ public function process_bulk_action(): void {
164168
$filter_keys = [ 'level_filter', 'start_date', 'end_date' ];
165169

166170
foreach ( $filter_keys as $key ) {
167-
$value = $_REQUEST[ $key ] ?? null;
171+
$value = isset( $_REQUEST[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $_REQUEST[ $key ] ) ) : null;
168172
if ( ! empty( $value ) && is_string( $value ) ) {
169-
$preserved_filters[ $key ] = sanitize_text_field( wp_unslash( $value ) );
173+
$preserved_filters[ $key ] = $value;
170174
}
171175
}
172176

plugins/wpgraphql-logging/src/Admin/View/Templates/wpgraphql-logger-filters.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@
66
exit;
77
}
88

9-
// Current filter values.
10-
$current_level = $_POST['level_filter'] ?? '';
11-
$current_start_date = $_POST['start_date'] ?? '';
12-
$current_end_date = $_POST['end_date'] ?? '';
9+
$wpgraphql_logging_current_level = isset( $_POST['level_filter'] ) ? sanitize_text_field( wp_unslash( $_POST['level_filter'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
10+
$wpgraphql_logging_current_start_date = isset( $_POST['start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['start_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
11+
$wpgraphql_logging_current_end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
1312

14-
$log_levels = [ 'debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency' ];
13+
// Currently only use info and error.
14+
$wpgraphql_logging_log_levels = [ 'info', 'error' ];
15+
$wpgraphql_logging_log_levels = apply_filters( 'wpgraphql_logging_log_levels', $wpgraphql_logging_log_levels );
1516
?>
1617

1718
<div class="alignleft actions" style="display: inline-flex; align-items: center; gap: 8px; margin-right: 10px;">
1819
<input type="text"
1920
name="start_date"
2021
class="wpgraphql-logging-datepicker"
2122
placeholder="Start Date"
22-
value="<?php echo esc_attr( $current_start_date ); ?>"
23+
value="<?php echo esc_attr( $wpgraphql_logging_current_start_date ); ?>"
2324
style="width: 120px;" />
2425

2526
<input type="text"
2627
name="end_date"
2728
class="wpgraphql-logging-datepicker"
2829
placeholder="End Date"
29-
value="<?php echo esc_attr( $current_end_date ); ?>"
30+
value="<?php echo esc_attr( $wpgraphql_logging_current_end_date ); ?>"
3031
style="width: 120px;" />
3132

3233
<select name="level_filter" style="width: 120px;">
3334
<option value="">All Levels</option>
34-
<?php foreach ( $log_levels as $level ) : ?>
35-
<option value="<?php echo esc_attr( $level ); ?>" <?php selected( $current_level, $level ); ?>>
36-
<?php echo esc_html( ucfirst( $level ) ); ?>
35+
<?php foreach ( $wpgraphql_logging_log_levels as $wpgraphql_logging_level ) : ?>
36+
<option value="<?php echo esc_attr( $wpgraphql_logging_level ); ?>" <?php selected( $wpgraphql_logging_current_level, $wpgraphql_logging_level ); ?>>
37+
<?php echo esc_html( ucfirst( $wpgraphql_logging_level ) ); ?>
3738
</option>
3839
<?php endforeach; ?>
3940
</select>

plugins/wpgraphql-logging/src/Events/Events.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,4 @@ final class Events {
6060
* @var string
6161
*/
6262
public const REQUEST_RESULTS = 'graphql_request_results';
63-
6463
}

plugins/wpgraphql-logging/src/Logger/LoggingHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function is_logging_enabled( array $config, ?string $query_string = nu
2828
$is_enabled = false;
2929
}
3030

31-
// Do not log the seedQuery for Faust.js
31+
// Do not log the seedQuery for Faust.js.
3232
if ( $is_enabled && ( 'query GetSeedNode' === trim( $query_string ) ) ) {
3333
$is_enabled = false;
3434
}

0 commit comments

Comments
 (0)