From e8c14ff13e55e0c192cc95c5fd3c08afcf9b464f Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 26 Sep 2024 17:41:59 -0600 Subject: [PATCH] Better handling for undefined constant --- includes/Classifai/Command/RSSImporterCommand.php | 7 +++++-- phpstan.neon.dist | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/Classifai/Command/RSSImporterCommand.php b/includes/Classifai/Command/RSSImporterCommand.php index 3633d31dd..a5301364d 100644 --- a/includes/Classifai/Command/RSSImporterCommand.php +++ b/includes/Classifai/Command/RSSImporterCommand.php @@ -200,8 +200,11 @@ public function get_url_meta( $url ) { $options['headers'] = []; } - $options['headers']['x-api-key'] = defined( MERCURY_PARSER_API_KEY ) ?? ''; /** @phpstan-ignore constant.notFound (If constant not defined, will use empty string instead) */ - $options['timeout'] = 60; // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout + if ( defined( \MERCURY_PARSER_API_KEY ) && \MERCURY_PARSER_API_KEY ) { + $options['headers']['x-api-key'] = \MERCURY_PARSER_API_KEY; + } + + $options['timeout'] = 60; // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout $request_url = 'https://mercury.postlight.com/parser?url=' . rawurlencode( $url ); $response = wp_remote_get( $request_url, $options ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get diff --git a/phpstan.neon.dist b/phpstan.neon.dist index caba1f421..9c30e3c8f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,7 +12,7 @@ parameters: ignoreErrors: # The JSDoc standard we use on hooks is not compatible with PHPStan. - '#One or more @param tags has an invalid name or invalid syntax#' - - '#PHPDoc tag @(.+) has invalid value \({(.+)}(.*)\): Unexpected token "{"#' + # - '#PHPDoc tag @(.+) has invalid value \({(.+)}(.*)\): Unexpected token "{"#' # Could look to fix this in the future. - '#@param tag must not be named \$this. Choose a descriptive alias, for example \$instance#' # Ignore ElasticPress for now, as we'll need to stub this. @@ -20,5 +20,6 @@ parameters: # These constants are defined but we'd need to stub them for PHPStan to know. - '#Constant CLASSIFAI_.+ not found#' - '#Constant WATSON_.+ not found#' + - '#Constant MERCURY_PARSER_API_KEY not found#' WPCompat: requiresAtLeast: '6.1'