Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I can indeed see the following errors after doing |
| wp_trigger_error( __FUNCTION__, esc_html( $message ) ); | ||
| $function_name = __FUNCTION__; | ||
| $trigger_error = static function ( string $message ) use ( &$function_name ): void { | ||
| wp_trigger_error( $function_name, esc_html( $message ) ); |
There was a problem hiding this comment.
Good catch. This was wrong!
There was a problem hiding this comment.
right, PHPSTan caught that - __FUNCTION__ is not the same inside a closure.
| $trigger_error = static function ( string $message, int $error_level = E_USER_NOTICE ) use ( $this_function ): void { | ||
| // Default to E_USER_NOTICE. | ||
| if ( ! in_array( $error_level, array( E_USER_NOTICE, E_USER_WARNING, E_USER_ERROR, E_USER_DEPRECATED ), true ) ) { | ||
| $error_level = E_USER_NOTICE; | ||
| } | ||
| wp_trigger_error( $this_function, esc_html( $message ), $error_level ); | ||
| }; |
There was a problem hiding this comment.
It's too bad that this doesn't seem to work:
/**
* Triggers error.
*
* @param string $message The message explaining the error.
* @param int $error_level Optional. The designated error type for this error.
*
* @phpstan-param E_USER_DEPRECATED|E_USER_ERROR|E_USER_NOTICE|E_USER_NOTICE $error_level
*/
$trigger_error = static function ( string $message, int $error_level = E_USER_NOTICE ) use ( $this_function ): void {
if ( ! in_array( $error_level, array( E_USER_ERROR, E_USER_NOTICE, E_USER_NOTICE, E_USER_DEPRECATED ), true ) ) {
throw new InvalidArgumentException( 'Invalid error level provided.' );
}
wp_trigger_error( $this_function, esc_html( $message ), $error_level );
};If I do $trigger_error( 'foo', 181293 ) it doesn't trigger any PHPStan static analysis error.
There was a problem hiding this comment.
But you do get a "InvalidArgumentException", right?
There was a problem hiding this comment.
Yeah, I mean more this part:
@phpstan-param E_USER_DEPRECATED|E_USER_ERROR|E_USER_NOTICE|E_USER_NOTICE $error_level
I'm not getting any static analysis issues when passing an integer other than those.
Co-authored-by: Weston Ruter <[email protected]>
|
Unit tests are failing in |
I've opened #1634 to address this. |
Summary
Fixes errors raised when running
composer phpstanRelevant technical choices