Skip to content

Commit f242763

Browse files
committed
Fixed QA errors.
1 parent fca43aa commit f242763

File tree

6 files changed

+48
-41
lines changed

6 files changed

+48
-41
lines changed

plugins/wpgraphql-logging/psalm.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@
3636
<file name="src/Logger/Database/DatabaseEntity.php"/>
3737
</errorLevel>
3838
</MissingFile>
39+
40+
<RedundantCast>
41+
<errorLevel type="suppress">
42+
<file name="src/Admin/View/List/Templates/wpgraphql-logger-view.php"/>
43+
</errorLevel>
44+
</RedundantCast>
3945
</issueHandlers>
4046
</psalm>

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

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

9090
/**
9191
* Define bulk actions.
92+
*
93+
* @return array<string, string> The bulk actions.
9294
*/
9395
public function get_bulk_actions(): array {
9496
return [
@@ -103,14 +105,14 @@ public function get_bulk_actions(): array {
103105
public function process_bulk_action(): void {
104106
$repository = $this->repository;
105107

106-
if ('delete' === $this->current_action() && !empty($_POST['log'])) {
107-
$ids = array_map('absint', (array) $_POST['log']);
108-
foreach ($ids as $id) {
109-
$repository->delete($id);
108+
if ( 'delete' === $this->current_action() && ! empty( $_POST['log'] ) ) { // @phpcs:ignore WordPress.Security.NonceVerification.Missing
109+
$ids = array_map( 'absint', (array) $_POST['log'] ); // @phpcs:ignore WordPress.Security.NonceVerification.Missing
110+
foreach ( $ids as $id ) {
111+
$repository->delete( $id );
110112
}
111113
}
112114

113-
if ('delete_all' === $this->current_action()) {
115+
if ( 'delete_all' === $this->current_action() ) {
114116
$repository->delete_all();
115117
}
116118
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
exit;
1717
}
1818
?>
19-
19+
2020
<div class="wrap">
2121
<h1 class="wp-heading-inline"><?php esc_html_e( 'WPGraphQL Logs', 'wpgraphql-logging' ); ?></h1>
2222
<hr class="wp-header-end">
2323

2424
<form method="post">
2525
<?php
2626
$list_table->prepare_items();
27-
$list_table->display_bulk_actions_top();
27+
// $list_table->display_bulk_actions_top();
2828
$list_table->display();
29-
$list_table->display_bulk_actions_bottom();
29+
// $list_table->display_bulk_actions_bottom();
3030
?>
3131
</form>
3232
</div>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@
1919
</tr>
2020
<tr>
2121
<th><?php esc_html_e( 'Datetime', 'wpgraphql-logging' ); ?></th>
22-
<td><?php echo esc_html( $log->get_datetime() ?? '' ); ?></td>
22+
<td><?php echo esc_html( (string) $log->get_datetime() ); ?></td>
2323
</tr>
2424
<tr>
2525
<th><?php esc_html_e( 'Channel', 'wpgraphql-logging' ); ?></th>
26-
<td><?php echo esc_html( $log->get_channel() ?? '' ); ?></td>
26+
<td><?php echo esc_html( (string) $log->get_channel() ); ?></td>
2727
</tr>
2828
<tr>
2929
<th><?php esc_html_e( 'Level', 'wpgraphql-logging' ); ?></th>
30-
<td><?php echo esc_html( $log->get_level_name() ?? '' ); ?></td>
30+
<td><?php echo esc_html( (string) $log->get_level_name() ); ?></td>
3131
</tr>
3232
<tr>
3333
<th><?php esc_html_e( 'Message', 'wpgraphql-logging' ); ?></th>
34-
<td><code><?php echo esc_html( $log->get_message() ); ?></code></td>
34+
<td><code><?php echo esc_html( (string) $log->get_message() ); ?></code></td>
3535
</tr>
3636
<tr>
3737
<th><?php esc_html_e( 'Context', 'wpgraphql-logging' ); ?></th>
38-
<td><pre><?php echo esc_html( wp_json_encode( $log->get_context(), JSON_PRETTY_PRINT ) ); ?></pre></td>
38+
<td><pre><?php echo esc_html( (string) wp_json_encode( $log->get_context(), JSON_PRETTY_PRINT ) ); ?></pre></td>
3939
</tr>
4040
<tr>
4141
<th><?php esc_html_e( 'Extra', 'wpgraphql-logging' ); ?></th>
42-
<td><pre><?php echo esc_html( wp_json_encode( $log->get_extra(), JSON_PRETTY_PRINT ) ); ?></pre></td>
42+
<td><pre><?php echo esc_html( (string) wp_json_encode( $log->get_extra(), JSON_PRETTY_PRINT ) ); ?></pre></td>
4343
</tr>
4444
</tbody>
4545
</table>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ protected function render_list_page(): void {
115115
protected function render_view_page(): void {
116116
$log_id = isset( $_GET['log'] ) ? absint( $_GET['log'] ) : 0; // @phpcs:ignore WordPress.Security.NonceVerification.Recommended
117117

118-
if ( ! $log_id ) {
118+
if ( 0 === (int) $log_id ) {
119119
echo '<div class="notice notice-error"><p>' . esc_html__( 'Invalid log ID.', 'wpgraphql-logging' ) . '</p></div>';
120120
return;
121121
}
122122

123123
$repository = new LogsRepository();
124124
$log = $repository->get_log( $log_id );
125125

126-
if ( ! $log ) {
126+
if ( is_null( $log ) ) {
127127
echo '<div class="notice notice-error"><p>' . esc_html__( 'Log not found.', 'wpgraphql-logging' ) . '</p></div>';
128128
return;
129129
}

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,31 @@ public function get_log( int $id ): ?DatabaseEntity {
7979
}
8080

8181
/**
82-
* Delete a single log entry by ID.
83-
*
84-
* @param int $id
85-
* @return bool
86-
*/
87-
public function delete(int $id): bool {
88-
global $wpdb;
89-
$table_name = DatabaseEntity::get_table_name();
82+
* Delete a single log entry by ID.
83+
*
84+
* @param int $id
85+
*/
86+
public function delete(int $id): bool {
87+
global $wpdb;
88+
$table_name = DatabaseEntity::get_table_name();
9089

91-
if ($id <= 0) {
92-
return false;
93-
}
90+
if ( $id <= 0 ) {
91+
return false;
92+
}
9493

95-
$result = $wpdb->delete($table_name, ['id' => $id], ['%d']); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
96-
return false !== $result;
97-
}
94+
$result = $wpdb->delete( $table_name, [ 'id' => $id ], [ '%d' ] ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
95+
return false !== $result;
96+
}
9897

99-
/**
100-
* Delete all log entries.
101-
*
102-
* @return bool True if all logs were deleted successfully, false otherwise.
103-
*/
104-
public function delete_all(): bool {
105-
global $wpdb;
106-
$table_name = DatabaseEntity::get_table_name();
107-
$result = $wpdb->query("TRUNCATE TABLE {$table_name}"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
108-
return false !== $result;
109-
}
98+
/**
99+
* Delete all log entries.
100+
*
101+
* @return bool True if all logs were deleted successfully, false otherwise.
102+
*/
103+
public function delete_all(): bool {
104+
global $wpdb;
105+
$table_name = DatabaseEntity::get_table_name();
106+
$result = $wpdb->query( $wpdb->prepare( 'TRUNCATE TABLE %s', $table_name ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
107+
return false !== $result;
108+
}
110109
}

0 commit comments

Comments
 (0)