From b0584dea0a1c45540e543ead39316386da6137b3 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Wed, 11 Mar 2020 12:58:12 +0200 Subject: [PATCH] Fixed type crash when URL passed to network request filters is invalid. Fixes #42 --- CHANGELOG.md | 1 + src/Record/Collector/Http_Collector.php | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8de34..6d10fa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Mustache.php version to resolve issues on PHP 7.4 +- type crash when URL passed to network request filters is invalid ## 3.3.1 - 2019-07-02 diff --git a/src/Record/Collector/Http_Collector.php b/src/Record/Collector/Http_Collector.php index 1baaa06..f246f42 100644 --- a/src/Record/Collector/Http_Collector.php +++ b/src/Record/Collector/Http_Collector.php @@ -43,11 +43,16 @@ class Http_Collector extends Stopwatch_Collector { * @param string $url The request URL. * * @return false|array|\WP_Error + * + * @psalm-suppress RedundantConditionGivenDocblockType + * @noinspection PhpUnusedParameterInspection */ - public function pre_http_request( $false, array $args, string $url ) { + public function pre_http_request( $false, $args, $url ) { - $this->start( $url, 'http' ); - $this->callers[ $url ] = wp_debug_backtrace_summary( __CLASS__, 5 ); + if ( $url && is_string( $url ) ) { + $this->start( $url, 'http' ); + $this->callers[ $url ] = wp_debug_backtrace_summary( __CLASS__, 5 ); + } return $false; } @@ -62,10 +67,15 @@ class Http_Collector extends Stopwatch_Collector { * @param string $url The request URL. * * @return array|\WP_Error + * + * @psalm-suppress RedundantConditionGivenDocblockType + * @noinspection PhpUnusedParameterInspection */ - public function http_api_debug( $response, string $type, $class, array $args, string $url ) { + public function http_api_debug( $response, $type, $class, $args, $url ) { - $this->stop( $url ); + if ( $url && is_string( $url ) ) { + $this->stop( $url ); + } return $response; }