Open
Description
Consider this example:
<?php
class Test
{
public function test($params)
{
return $this->commit(function() use ($params)
{
$whatever = 5;
return $whatever;
});
}
private function commit($callback)
{
//complex logic using $callback can go here
$callback();
}
}
PHPCheckstyle warns me about it:
File "/home/rr-/test/test.php" warning, line 6 - Function test has unused code after RETURN.
even though it isn't true. To make the warning go away, I need to refactor the code like this:
<?php
class Test
{
public function test($params)
{
$callback = function() use ($params)
{
$whatever = 5;
return $whatever;
};
return $this->commit($callback);
}
private function commit($callback)
{
//complex logic using $callback can go here
$callback();
}
}