Skip to content

Commit 0128d2c

Browse files
committed
Fixed some suppressed psalm errors.
1 parent 36985d5 commit 0128d2c

File tree

12 files changed

+30
-29
lines changed

12 files changed

+30
-29
lines changed

plugins/wpgraphql-logging/src/Admin/Settings/Fields/Field/AbstractSettingsField.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,36 @@ public function should_render_for_tab( string $tab_key ): bool {
5757
* @param string $section The section ID.
5858
* @param string $page The page URI.
5959
* @param array<string, mixed> $args The field arguments.
60+
*
61+
* @psalm-suppress InvalidArgument
6062
*/
6163
public function add_settings_field( string $section, string $page, array $args ): void {
64+
$args['class'] = $this->css_class;
6265
add_settings_field(
6366
$this->get_id(),
6467
$this->title,
6568
[ $this, 'render_field_callback' ],
6669
$page,
6770
$section,
68-
[
69-
'class' => $this->css_class,
70-
]
71+
$args
7172
);
7273
}
7374

7475
/**
7576
* Callback function to render the field.
7677
*
7778
* @param array<string, mixed> $args The field arguments.
79+
*
80+
* @throws \Exception If the tab key or settings key is empty.
7881
*/
7982
public function render_field_callback( array $args ): void {
8083
$tab_key = (string) ( $args['tab_key'] ?? '' );
8184
$settings_key = (string) ( $args['settings_key'] ?? '' );
8285

86+
if ( '' === $tab_key || '' === $settings_key ) {
87+
throw new \Exception( 'Tab key or settings key is empty' );
88+
}
89+
8390
$config_helper = ConfigurationHelper::get_instance();
8491
$option_value = $config_helper->get_config();
8592

plugins/wpgraphql-logging/src/Admin/Settings/Menu/MenuPage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function registration_callback(): void {
103103
set_query_var( $query_var, $args );
104104
}
105105

106-
// phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable -- $this->template is validated and defined within the class
107-
include_once $this->template;
106+
include_once $this->template; // @phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
108107
}
109108
}

plugins/wpgraphql-logging/src/Admin/View/Download/DownloadLogService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function generate_csv( int $log_id ): void {
5656
if ( ! is_resource( $output ) ) {
5757
wp_die( esc_html__( 'Failed to create CSV output.', 'wpgraphql-logging' ) );
5858
}
59-
$writer = Writer::createFromStream( $output );
59+
$writer = Writer::from( $output );
6060

6161
$headers = $this->get_headers( $log );
6262
$content = $this->get_content( $log );

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function prepare_items(): void {
7676

7777
$per_page = $this->get_items_per_page( 'logs_per_page', self::DEFAULT_PER_PAGE );
7878
$current_page = $this->get_pagenum();
79-
$request = $_REQUEST ?? [];
79+
$request = ( ! empty( $_REQUEST ) ? $_REQUEST : [] );
8080
$where = $this->process_where( $request );
8181
$total_items = $this->log_service->count_entities_by_where( $where );
8282

@@ -135,17 +135,15 @@ public function process_bulk_action(): void {
135135
$nonce_action = 'bulk-' . esc_attr( $this->_args['plural'] );
136136
$nonce_value = isset( $_REQUEST['_wpnonce'] ) && is_string( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
137137

138-
$nonce = is_string( $nonce_value ) ? $nonce_value : '';
139-
140-
$nonce_result = wp_verify_nonce( $nonce, $nonce_action );
138+
$nonce_result = wp_verify_nonce( $nonce_value, $nonce_action );
141139
if ( false === $nonce_result ) {
142140
wp_die( esc_html__( 'Nonce verification failed!', 'wpgraphql-logging' ) );
143141
}
144142

145143
$deleted_count = 0;
146144

147145
// WordPress sometimes sends 'delete' for selected items.
148-
if ( in_array( $action, [ 'delete', 'bulk_delete' ], true ) && ! empty( $_REQUEST['log'] ) ) {
146+
if ( in_array( $action, [ 'delete', 'bulk_delete' ], true ) && isset( $_REQUEST['log'] ) && '' !== $_REQUEST['log'] ) {
149147
$ids = array_map( 'absint', (array) $_REQUEST['log'] );
150148
// Remove redundant empty check since array_map always returns array.
151149
foreach ( $ids as $id ) {
@@ -171,7 +169,7 @@ public function process_bulk_action(): void {
171169

172170
foreach ( $filter_keys as $key ) {
173171
$value = isset( $_REQUEST[ $key ] ) && is_string( $_REQUEST[ $key ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $key ] ) ) : null;
174-
if ( ! empty( $value ) ) {
172+
if ( null !== $value && '' !== $value ) {
175173
$preserved_filters[ $key ] = $value;
176174
}
177175
}
@@ -394,7 +392,7 @@ public function get_memory_usage(WordPressDatabaseEntity $item): string {
394392
public function get_request_headers(WordPressDatabaseEntity $item): string {
395393
$extra = $item->get_extra();
396394
$request_headers = $extra['request_headers'] ?? [];
397-
if ( empty( $request_headers ) || ! is_array( $request_headers ) ) {
395+
if ( ! is_array( $request_headers ) ) {
398396
return '';
399397
}
400398

plugins/wpgraphql-logging/src/Admin/ViewLogsPage.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,7 @@ protected function get_post_value(string $key): ?string {
245245
if ( ! is_string( $value ) || '' === $value ) {
246246
return null;
247247
}
248-
$value = wp_unslash( $value );
249-
if ( ! is_string( $value ) ) {
250-
return null;
251-
}
252-
return sanitize_text_field( $value );
248+
return sanitize_text_field( wp_unslash( $value ) );
253249
}
254250

255251
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public function log_pre_request( ?string $query, ?string $operation_name, ?array
8989
*/
9090
public function log_graphql_before_execute( Request $request ): void {
9191
try {
92-
/** @var \GraphQL\Server\OperationParams $params */
92+
/** @var \GraphQL\Server\OperationParams|null $params */
9393
$params = $request->params;
94-
if ( null === $params || ! \is_object( $params ) ) {
94+
if ( ! is_object( $params ) ) {
9595
return;
9696
}
9797
$query = $params->query;

plugins/wpgraphql-logging/src/Logger/Database/WordPressDatabaseEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ public function get_query(): ?string {
197197
}
198198

199199
$request = $context['request'] ?? null;
200-
if ( empty( $request ) || ! is_array( $request ) ) {
200+
if ( ! is_array( $request ) ) {
201201
return $query;
202202
}
203203

204204
$params = $request['params'] ?? null;
205-
if ( empty( $params ) || ! is_array( $params ) ) {
205+
if ( ! is_array( $params ) ) {
206206
return $query;
207207
}
208208

plugins/wpgraphql-logging/src/Logger/Database/WordPressDatabaseLogService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function prepare_sql(string $sql, array $where_conditions): string {
242242
$safe_operators = $this->get_safe_operators();
243243
$allowed_columns = $this->get_allowed_columns();
244244
foreach ( $where_conditions as $column => $condition ) {
245-
if ( ! is_array( $condition ) || ! isset( $condition['column'] ) || ! isset( $condition['value'] ) || ! isset( $condition['operator'] ) ) {
245+
if ( ! isset( $condition['column'] ) || ! isset( $condition['value'] ) || ! isset( $condition['operator'] ) ) {
246246
continue;
247247
}
248248

plugins/wpgraphql-logging/src/Logger/Handlers/WordPressDatabaseHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ protected function write( LogRecord $record ): void {
3434
$level->value,
3535
$level->name,
3636
$record->message,
37-
$record->context ?? [],
38-
$record->extra ?? []
37+
$record->context,
38+
$record->extra
3939
);
4040
} catch ( Throwable $e ) {
4141
do_action( 'wpgraphql_logging_write_database_error', $e, $record );

plugins/wpgraphql-logging/src/Logger/Processors/DataSanitizationProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function get_custom_rules(): array {
9090
];
9191

9292
foreach ( $fields as $action => $field_string ) {
93-
if ( empty( $field_string ) || ! is_string( $field_string ) ) {
93+
if ( ! is_string( $field_string ) || '' === trim( $field_string ) ) {
9494
continue;
9595
}
9696

@@ -124,7 +124,7 @@ protected function apply_rule(array &$data, string $key, string $rule): void {
124124

125125
$keys = explode( '.', $key );
126126
$last_key = array_pop( $keys );
127-
$current = &$this->navigate_to_parent( $data, $keys );
127+
$current = $this->navigate_to_parent( $data, $keys );
128128

129129
if ( null === $current || ! array_key_exists( $last_key, $current ) ) {
130130
return;

0 commit comments

Comments
 (0)