Automattic / phpcs-neutron-standard

A set of phpcs sniffs for PHP >7 development
MIT License
94 stars 7 forks source link

TypeHintSniff.php marks as error void functions which return void. #19

Closed gmazzap closed 6 years ago

gmazzap commented 6 years ago

TypeHintSniff.php is (also) used to check for functions that

The problem is that there's a false positive when a void function returns nothing as expected, but has an early return like:

function i_return_nothing( bool $condition ) {

   if (  $condition ) {
      return;
   }

   do_something();
}

In the case above, the code style raises an error for missing return type, but void return type is only something possible from PHP 7.1. If Neutron Standard targets 7.0 as well, the TypeHintSniff.php should better handle such cases.