* Remove all return type.
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
"require-dev": {
|
||||
"rector/rector": "0.16.*"
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Misc\\Rector\\": "rector/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"rector": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
|
||||
+3
-1
@@ -5,19 +5,21 @@ use Rector\Set\ValueObject\DowngradeLevelSetList;
|
||||
use Rector\Set\ValueObject\DowngradeSetList;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
|
||||
use Misc\Rector\RemoveReturnType;
|
||||
|
||||
$version = getenv('PHP_VERSION');
|
||||
$version = $version ?: '72';
|
||||
$cacheDir = getenv('RECTOR_CACHE_DIR');
|
||||
$cacheDir = $cacheDir ?: '/tmp/rector_cached_files';
|
||||
|
||||
return static function (RectorConfig $rectorConfig) use ($version,$cacheDir): void {
|
||||
return static function (RectorConfig $rectorConfig) use ($version, $cacheDir): void {
|
||||
$rectorConfig->skip([
|
||||
'test/*',
|
||||
'framework/zand',
|
||||
]);
|
||||
$rectorConfig->phpVersion(constant(PhpVersion::class . '::PHP_' . $version));
|
||||
$rectorConfig->sets([constant(DowngradeLevelSetList::class . '::DOWN_TO_PHP_' . $version)]);
|
||||
$rectorConfig->rule(RemoveReturnType::class);
|
||||
// $rectorConfig->sets([constant(DowngradeSetList::class . '::PHP_' . $version)]);
|
||||
$rectorConfig->cacheClass(FileCacheStorage::class);
|
||||
$rectorConfig->cacheDirectory($cacheDir);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Misc\Rector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
final class RemoveReturnType extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove return type from method', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function foo(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$node->returnType = null;
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user