szepeviktor / phpstan-wordpress

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

Error: `Action callback returns Instance but should not return anything` #198

Closed crstauf closed 10 months ago

crstauf commented 11 months ago

Source file (WordPress mu-plugin): https://github.com/cssllc/mu-plugins/blob/add-phpcs-phpstan/src/cssllc-woocommerce.php

Error:

 ------ ----------------------------------------------------------------------------
  Line   cssllc-woocommerce.php
 ------ ----------------------------------------------------------------------------
  379    Action callback returns CSSLLC_WooCommerce but should not return anything.
 ------ ----------------------------------------------------------------------------

Initially reported here: https://github.com/phpstan/phpstan/discussions/9889

johnbillion commented 11 months ago

I think that's correct. The instance method is returning an instance of CSSLLC_WooCommerce and it's hooked into an action.

crstauf commented 11 months ago

Ooooh. So I need to change to a callback that will initialize the instance, and not return it. Wow. 🤦‍♂️