Rule void_return¶
Add void return type to functions with missing or empty return statements,
but priority is given to @return annotations.
Warnings¶
This rule is RISKY¶
Modifies the signature of functions.
This rule is CONFIGURABLE¶
You can configure this rule using the following option: fix_lambda.
Configuration¶
fix_lambda¶
Whether to fix lambda functions as well.
Allowed types: bool
Default value: true
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
<?php
class Foo
{
- public function hello()
+ public function hello(): void
{
- $hello = function($a) { echo 'Hello '.$a; };
+ $hello = function($a): void { echo 'Hello '.$a; };
echo $hello('World');
}
}
Example #2¶
With configuration: ['fix_lambda' => false].
--- Original
+++ New
<?php
class Foo
{
- public function hello()
+ public function hello(): void
{
$hello = function($a) { echo 'Hello '.$a; };
echo $hello('World');
}
}
Rule sets¶
The rule is part of the following rule sets:
@PHP71Migration:risky (deprecated)
@PHP74Migration:risky (deprecated)
@PHP80Migration:risky (deprecated)
@PHP82Migration:risky (deprecated)
References¶
Fixer class: PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer
Test class: PhpCsFixer\Tests\Fixer\FunctionNotation\VoidReturnFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.