Skip to content

Commit d5e3447

Browse files
authored
Fix QM collector typing issue (#868)
1 parent 502eec7 commit d5e3447

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v1.19.1
9+
10+
### Fixed
11+
12+
- Fixed potential issue with bad typing on the Query Monitor package.
13+
814
## v1.19.0
915

1016
- Fix issue introduced in v1.18.1 with packages being moved to `require-dev`.

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ parameters:
5151
- "#ReflectionClass does not specify its types#"
5252
- "#ReflectionAttribute does not specify its types#"
5353
- "#@return is not subtype of template type TKey#"
54-
- "#WP_REST_Request does not specify its types#"
55-
- "#WP_REST_Request but does not specify its types#"
5654
- "#query of method wpdb::prepare#"
5755
-
5856
identifier: method.childReturnType

src/mantle/query-monitor/collector/class-remote-request-collector.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,28 @@ public function process(): void {
275275
foreach ( $this->requests as $key => $request ) {
276276
// Provide a timeout response if none exists).
277277
if ( ! isset( $this->responses[ $key ] ) ) {
278-
$response = [
278+
$this->responses[ $key ] = [
279279
'args' => $request['args'],
280280
'response' => new WP_Error(
281281
'http_request_timed_out',
282282
__( 'The HTTP request did not receive a response before the timeout period expired.', 'mantle' ),
283283
),
284-
'stop' => floatval( $request['start'] + $response['args']['timeout'] ),
284+
'stop' => floatval( $request['start'] + ( $request['args']['timeout'] ?? 0 ) ),
285285
'url' => $request['url'],
286286
];
287287
}
288288

289289
// Convert the response to a Http Client Response instance.
290-
$response = $this->responses[ $key ]['response'] instanceof Response
291-
? $this->responses[ $key ]['response']
292-
: Response::create( $this->responses[ $key ]['response'] );
290+
$response = match ( true ) {
291+
$this->responses[ $key ]['response'] instanceof Response => $this->responses[ $key ]['response'],
292+
is_array( $this->responses[ $key ]['response'] ) => Response::create( $this->responses[ $key ]['response'] ),
293+
is_wp_error( $this->responses[ $key ]['response'] ) => Response::create( $this->responses[ $key ]['response'] ),
294+
default => null,
295+
};
296+
297+
if ( ! $response instanceof Response ) {
298+
continue;
299+
}
293300

294301
$this->data->requests[ $key ] = [
295302
'args' => $request['args'],

0 commit comments

Comments
 (0)