mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-04 18:30:50 +00:00
Updated Rector to commit 7de77e518f7b47b7c7ba0d96152d4acdad958639
7de77e518f
[TypeDeclaration] Add AddTestsVoidReturnTypeWhereNoReturnRector (#5611)
This commit is contained in:
parent
1bea0c9d65
commit
f863e8b003
|
@ -1,4 +1,4 @@
|
||||||
# 358 Rules Overview
|
# 359 Rules Overview
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
|
|
||||||
- [Transform](#transform) (23)
|
- [Transform](#transform) (23)
|
||||||
|
|
||||||
- [TypeDeclaration](#typedeclaration) (42)
|
- [TypeDeclaration](#typedeclaration) (43)
|
||||||
|
|
||||||
- [Visibility](#visibility) (3)
|
- [Visibility](#visibility) (3)
|
||||||
|
|
||||||
|
@ -6495,6 +6495,26 @@ Changes defined return typehint of method and class.
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
### AddTestsVoidReturnTypeWhereNoReturnRector
|
||||||
|
|
||||||
|
Add void to PHPUnit test methods
|
||||||
|
|
||||||
|
- class: [`Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector`](../rules/TypeDeclaration/Rector/Class_/AddTestsVoidReturnTypeWhereNoReturnRector.php)
|
||||||
|
|
||||||
|
```diff
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class SomeClass extends TestCase
|
||||||
|
{
|
||||||
|
- public function testSomething()
|
||||||
|
+ public function testSomething(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
### AddVoidReturnTypeWhereNoReturnRector
|
### AddVoidReturnTypeWhereNoReturnRector
|
||||||
|
|
||||||
Add return type void to function like without any return
|
Add return type void to function like without any return
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare (strict_types=1);
|
||||||
|
namespace Rector\TypeDeclaration\Rector\Class_;
|
||||||
|
|
||||||
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Identifier;
|
||||||
|
use PhpParser\Node\Stmt\Class_;
|
||||||
|
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
|
||||||
|
use Rector\Rector\AbstractRector;
|
||||||
|
use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver;
|
||||||
|
use Rector\ValueObject\PhpVersionFeature;
|
||||||
|
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||||
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||||
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||||
|
/**
|
||||||
|
* @see \Rector\Tests\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector\AddTestsVoidReturnTypeWhereNoReturnRectorTest
|
||||||
|
*/
|
||||||
|
final class AddTestsVoidReturnTypeWhereNoReturnRector extends AbstractRector implements MinPhpVersionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
|
||||||
|
*/
|
||||||
|
private $testsNodeAnalyzer;
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
* @var \Rector\TypeDeclaration\TypeInferer\SilentVoidResolver
|
||||||
|
*/
|
||||||
|
private $silentVoidResolver;
|
||||||
|
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, SilentVoidResolver $silentVoidResolver)
|
||||||
|
{
|
||||||
|
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
|
||||||
|
$this->silentVoidResolver = $silentVoidResolver;
|
||||||
|
}
|
||||||
|
public function getRuleDefinition() : RuleDefinition
|
||||||
|
{
|
||||||
|
return new RuleDefinition('Add void to PHPUnit test methods', [new CodeSample(<<<'CODE_SAMPLE'
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class SomeClass extends TestCase
|
||||||
|
{
|
||||||
|
public function testSomething()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CODE_SAMPLE
|
||||||
|
, <<<'CODE_SAMPLE'
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class SomeClass extends TestCase
|
||||||
|
{
|
||||||
|
public function testSomething(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CODE_SAMPLE
|
||||||
|
)]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return array<class-string<Node>>
|
||||||
|
*/
|
||||||
|
public function getNodeTypes() : array
|
||||||
|
{
|
||||||
|
return [Class_::class];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param Class_ $node
|
||||||
|
*/
|
||||||
|
public function refactor(Node $node) : ?Node
|
||||||
|
{
|
||||||
|
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$hasChanged = \false;
|
||||||
|
foreach ($node->getMethods() as $classMethod) {
|
||||||
|
// has type already
|
||||||
|
if ($classMethod->returnType instanceof Node) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$this->testsNodeAnalyzer->isTestClassMethod($classMethod)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($classMethod->isAbstract()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$this->silentVoidResolver->hasExclusiveVoid($classMethod)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$classMethod->returnType = new Identifier('void');
|
||||||
|
$hasChanged = \true;
|
||||||
|
}
|
||||||
|
if ($hasChanged) {
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public function provideMinPhpVersion() : int
|
||||||
|
{
|
||||||
|
return PhpVersionFeature::VOID_TYPE;
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '48e8cfab19f5572f6419876a8f5cec0109966862';
|
public const PACKAGE_VERSION = '7de77e518f7b47b7c7ba0d96152d4acdad958639';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2024-02-12 22:57:00';
|
public const RELEASE_DATE = '2024-02-12 22:53:21';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Rector\Config\Level;
|
||||||
|
|
||||||
use Rector\Contract\Rector\RectorInterface;
|
use Rector\Contract\Rector\RectorInterface;
|
||||||
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
|
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector;
|
||||||
use Rector\TypeDeclaration\Rector\Class_\MergeDateTimePropertyTypeDeclarationRector;
|
use Rector\TypeDeclaration\Rector\Class_\MergeDateTimePropertyTypeDeclarationRector;
|
||||||
use Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector;
|
use Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector;
|
||||||
use Rector\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector;
|
use Rector\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector;
|
||||||
|
@ -53,6 +54,7 @@ final class TypeDeclarationLevel
|
||||||
// start with closure first, as safest
|
// start with closure first, as safest
|
||||||
AddClosureVoidReturnTypeWhereNoReturnRector::class,
|
AddClosureVoidReturnTypeWhereNoReturnRector::class,
|
||||||
AddFunctionVoidReturnTypeWhereNoReturnRector::class,
|
AddFunctionVoidReturnTypeWhereNoReturnRector::class,
|
||||||
|
AddTestsVoidReturnTypeWhereNoReturnRector::class,
|
||||||
AddVoidReturnTypeWhereNoReturnRector::class,
|
AddVoidReturnTypeWhereNoReturnRector::class,
|
||||||
// php 7.4
|
// php 7.4
|
||||||
AddArrowFunctionReturnTypeRector::class,
|
AddArrowFunctionReturnTypeRector::class,
|
||||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2375,6 +2375,7 @@ return array(
|
||||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnUnionTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnUnionTypeRector.php',
|
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnUnionTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnUnionTypeRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictArrayParamDimFetchRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php',
|
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictArrayParamDimFetchRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php',
|
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php',
|
||||||
|
'Rector\\TypeDeclaration\\Rector\\Class_\\AddTestsVoidReturnTypeWhereNoReturnRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/AddTestsVoidReturnTypeWhereNoReturnRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Class_\\MergeDateTimePropertyTypeDeclarationRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Class_\\MergeDateTimePropertyTypeDeclarationRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Class_\\PropertyTypeFromStrictSetterGetterRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Class_\\PropertyTypeFromStrictSetterGetterRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Class_\\ReturnTypeFromStrictTernaryRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Class_\\ReturnTypeFromStrictTernaryRector' => $baseDir . '/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php',
|
||||||
|
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
|
@ -2594,6 +2594,7 @@ class ComposerStaticInit2d887a2f87c676eb32b3e04612865e54
|
||||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnUnionTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnUnionTypeRector.php',
|
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\ReturnUnionTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/ReturnUnionTypeRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictArrayParamDimFetchRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php',
|
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictArrayParamDimFetchRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php',
|
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php',
|
||||||
|
'Rector\\TypeDeclaration\\Rector\\Class_\\AddTestsVoidReturnTypeWhereNoReturnRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/AddTestsVoidReturnTypeWhereNoReturnRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Class_\\MergeDateTimePropertyTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Class_\\MergeDateTimePropertyTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/MergeDateTimePropertyTypeDeclarationRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Class_\\PropertyTypeFromStrictSetterGetterRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Class_\\PropertyTypeFromStrictSetterGetterRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Class_\\ReturnTypeFromStrictTernaryRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Class_\\ReturnTypeFromStrictTernaryRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user