Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP_CLI::error() doesn't always terminate #213

Open
johnbillion opened this issue Feb 26, 2024 · 5 comments
Open

WP_CLI::error() doesn't always terminate #213

johnbillion opened this issue Feb 26, 2024 · 5 comments

Comments

@johnbillion
Copy link
Contributor

The WP_CLI::error() method is marked as an early terminating method, but it doesn't terminate if the $exit parameter is set to false.

Its entry in the earlyTerminatingMethodCalls config should be removed and replaced with something else that's conditional, but I'm not sure what.

@szepeviktor
Copy link
Owner

szepeviktor commented Feb 26, 2024

I tell you not to use that $exit parameter.
Just like

- Do not enable `exit_error` in `WP_CLI::launch` or `WP_CLI::runcommand` to keep your code testable

It feels really-really bad to handle these parts of WordPress.
That is all I could contribute.

@herndlm
Copy link
Contributor

herndlm commented Feb 26, 2024

@IanDelMar
Copy link
Contributor

Why is WP_CLI::error() handled in szepeviktor/phpstan-wordpress and not in php-stubs/wp-cli-stubs?

@szepeviktor
Copy link
Owner

Why is WP_CLI::error() handled in szepeviktor/phpstan-wordpress and not in php-stubs/wp-cli-stubs?

Stubs are not PHPStan extensions.

@IanDelMar
Copy link
Contributor

Of course, but this could be handled quite easily with a conditional return type. Simply add a file, e.g., overrides.stub:

class WP_CLI
{
  /**
   * @return ($exit is true|int<1, max> ? never : void)
   */
  public static function error($message, $exit = true)
  {
  }
}

and instruct users to add it to stubFiles in their PHPStan config file, or advise them to add the earlyTerminatingMethodCalls entry in their custom config. Just sharing ideas as the issue is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants