szepeviktor/phpstan-wordpress

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

Closed this issue · 2 comments

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: phpstan/phpstan#9889

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

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