szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
267 stars 25 forks source link

Fix dynamic return type extension for `has_filter()`/`has_action()` #151

Closed IanDelMar closed 1 year ago

IanDelMar commented 1 year ago

This PR fixes the return type of has_filter() and has_action() for maybe false types.

A maybe false type such as callable|string|array|false is not an instance of MixedType in https://github.com/szepeviktor/phpstan-wordpress/blob/5c6c6c47b77251ba2c0753c3ff8842cb08190f9e/src/HasFilterDynamicFunctionReturnTypeExtension.php#L42-L47

Failing test:

// Maybe false callback
/** @var callable|string|array|false $callback */
$callback = $_GET['callback'];
assertType('bool|int', has_filter('', $callback));
assertType('bool|int', has_action('', $callback));

This PR also replaces a deprecated instanceof ConstantBooleanType.