Turn an inner named function declared inside a class method into a private method, as inner named functions are not supported by PHPStan
class SomeClass
{
public function run(): void
{
- function inner(): void
- {
- echo 'hello';
- }
+ $this->inner();
+ }
- inner();
+ private function inner(): void
+ {
+ echo 'hello';
}
}
Configure your rector.php:
<?php
use Rector\CodeQuality\Rector\Class_\InnerFunctionToPrivateMethodRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
InnerFunctionToPrivateMethodRector::class,
]);