Skip to content

Commit

Permalink
Better handling for undefined constant
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Sep 26, 2024
1 parent e356d69 commit e8c14ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions includes/Classifai/Command/RSSImporterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ 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.
- '#ElasticPress#'
# 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'

0 comments on commit e8c14ff

Please sign in to comment.