mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
[Downgrade] Remove excessive abstract class inheritance, use single service (#5717)
This commit is contained in:
parent
47743269e8
commit
05788745fd
@ -48,16 +48,16 @@
|
||||
"symfony/finder": "^4.4.8|^5.1",
|
||||
"symfony/http-kernel": "^4.4.8|^5.1",
|
||||
"symfony/process": "^4.4.8|^5.1",
|
||||
"symplify/astral": "dev-master",
|
||||
"symplify/autowire-array-parameter": "dev-master",
|
||||
"symplify/console-color-diff": "dev-master",
|
||||
"symplify/package-builder": "dev-master",
|
||||
"symplify/rule-doc-generator": "dev-master",
|
||||
"symplify/set-config-resolver": "dev-master",
|
||||
"symplify/simple-php-doc-parser": "dev-master",
|
||||
"symplify/skipper": "dev-master",
|
||||
"symplify/smart-file-system": "dev-master",
|
||||
"symplify/symfony-php-config": "dev-master",
|
||||
"symplify/astral": "^9.2.3",
|
||||
"symplify/autowire-array-parameter": "^9.2.3",
|
||||
"symplify/console-color-diff": "^9.2.3",
|
||||
"symplify/package-builder": "^9.2.3",
|
||||
"symplify/rule-doc-generator": "^9.2.3",
|
||||
"symplify/set-config-resolver": "^9.2.3",
|
||||
"symplify/simple-php-doc-parser": "^9.2.3",
|
||||
"symplify/skipper": "^9.2.3",
|
||||
"symplify/smart-file-system": "^9.2.3",
|
||||
"symplify/symfony-php-config": "^9.2.3",
|
||||
"webmozart/assert": "^1.9"
|
||||
},
|
||||
"require-dev": {
|
||||
@ -71,14 +71,14 @@
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"symfony/security-core": "^5.2",
|
||||
"symfony/security-http": "^5.2",
|
||||
"symplify/changelog-linker": "dev-master",
|
||||
"symplify/coding-standard": "dev-master",
|
||||
"symplify/changelog-linker": "^9.2.3",
|
||||
"symplify/coding-standard": "^9.2.3",
|
||||
"symplify/easy-ci": "^9.1.0",
|
||||
"symplify/easy-coding-standard": "dev-master",
|
||||
"symplify/easy-testing": "dev-master",
|
||||
"symplify/easy-coding-standard": "^9.2.3",
|
||||
"symplify/easy-testing": "^9.2.3",
|
||||
"symplify/monorepo-builder": "^9.2",
|
||||
"symplify/phpstan-extensions": "dev-master",
|
||||
"symplify/phpstan-rules": "dev-master",
|
||||
"symplify/phpstan-extensions": "^9.2.3",
|
||||
"symplify/phpstan-rules": "^9.2.3",
|
||||
"tracy/tracy": "^2.8"
|
||||
},
|
||||
"replace": {
|
||||
|
@ -2,12 +2,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeDeclarationRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeTypeParamDeclarationRector::class);
|
||||
$services->set(DowngradeTypeReturnDeclarationRector::class);
|
||||
$services->set(DowngradeTypeDeclarationRector::class);
|
||||
};
|
||||
|
@ -6,18 +6,16 @@ use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\DowngradePhp71\Rector\Array_\SymmetricArrayDestructuringToListRector;
|
||||
use Rector\DowngradePhp71\Rector\ClassConst\DowngradeClassConstantVisibilityRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\String_\DowngradeNegativeStringOffsetToStrlenRector;
|
||||
use Rector\DowngradePhp71\Rector\TryCatch\DowngradePipeToMultiCatchExceptionRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeNullableTypeParamDeclarationRector::class);
|
||||
$services->set(DowngradeNullableTypeReturnDeclarationRector::class);
|
||||
$services->set(DowngradeVoidTypeReturnDeclarationRector::class);
|
||||
$services->set(DowngradeNullableTypeDeclarationRector::class);
|
||||
$services->set(DowngradeVoidTypeDeclarationRector::class);
|
||||
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_70);
|
||||
|
@ -5,14 +5,12 @@ declare(strict_types=1);
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeParamObjectTypeDeclarationRector::class);
|
||||
$services->set(DowngradeReturnObjectTypeDeclarationRector::class);
|
||||
$services->set(DowngradeObjectTypeDeclarationRector::class);
|
||||
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_71);
|
||||
|
@ -8,7 +8,7 @@ use Rector\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector;
|
||||
use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector;
|
||||
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeContravariantArgumentTypeRector;
|
||||
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeCovariantReturnTypeRector;
|
||||
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector;
|
||||
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector;
|
||||
use Rector\DowngradePhp74\Rector\Coalesce\DowngradeNullCoalescingOperatorRector;
|
||||
use Rector\DowngradePhp74\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector;
|
||||
use Rector\DowngradePhp74\Rector\FuncCall\DowngradeStripTagsCallWithArrayRector;
|
||||
@ -39,5 +39,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
|
||||
|
||||
$services->set(DowngradeFreadFwriteFalsyToNegationRector::class);
|
||||
$services->set(DowngradeReturnSelfTypeDeclarationRector::class);
|
||||
$services->set(DowngradeSelfTypeDeclarationRector::class);
|
||||
};
|
||||
|
@ -9,11 +9,9 @@ use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector;
|
||||
use Rector\DowngradePhp80\Rector\ClassConstFetch\DowngradeClassOnObjectToGetClassRector;
|
||||
use Rector\DowngradePhp80\Rector\ClassMethod\DowngradeTrailingCommasInParamUseRector;
|
||||
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\NullsafeMethodCall\DowngradeNullsafeToTernaryOperatorRector;
|
||||
use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
@ -21,11 +19,9 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeUnionTypeTypedPropertyRector::class);
|
||||
$services->set(DowngradeUnionTypeReturnDeclarationRector::class);
|
||||
$services->set(DowngradeUnionTypeParamDeclarationRector::class);
|
||||
$services->set(DowngradeParamMixedTypeDeclarationRector::class);
|
||||
$services->set(DowngradeReturnMixedTypeDeclarationRector::class);
|
||||
$services->set(DowngradeReturnStaticTypeDeclarationRector::class);
|
||||
$services->set(DowngradeUnionTypeDeclarationRector::class);
|
||||
$services->set(DowngradeMixedTypeDeclarationRector::class);
|
||||
$services->set(DowngradeStaticTypeDeclarationRector::class);
|
||||
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74);
|
||||
|
@ -1,4 +1,4 @@
|
||||
# 673 Rules Overview
|
||||
# 667 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
@ -34,17 +34,17 @@
|
||||
|
||||
- [DoctrineGedmoToKnplabs](#doctrinegedmotoknplabs) (7)
|
||||
|
||||
- [DowngradePhp70](#downgradephp70) (2)
|
||||
- [DowngradePhp70](#downgradephp70) (1)
|
||||
|
||||
- [DowngradePhp71](#downgradephp71) (9)
|
||||
- [DowngradePhp71](#downgradephp71) (7)
|
||||
|
||||
- [DowngradePhp72](#downgradephp72) (3)
|
||||
- [DowngradePhp72](#downgradephp72) (2)
|
||||
|
||||
- [DowngradePhp73](#downgradephp73) (4)
|
||||
|
||||
- [DowngradePhp74](#downgradephp74) (11)
|
||||
|
||||
- [DowngradePhp80](#downgradephp80) (12)
|
||||
- [DowngradePhp80](#downgradephp80) (10)
|
||||
|
||||
- [EarlyReturn](#earlyreturn) (11)
|
||||
|
||||
@ -2535,7 +2535,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
|
||||
### SplitDoubleAssignRector
|
||||
|
||||
Split multiple inline assigns to `each` own lines default value, to prevent undefined array issues
|
||||
Split multiple inline assigns to each own lines default value, to prevent undefined array issues
|
||||
|
||||
- class: [`Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector`](/rules/coding-style/src/Rector/Assign/SplitDoubleAssignRector.php)
|
||||
|
||||
@ -4337,10 +4337,11 @@ Turns fluent interface calls to classic ones.
|
||||
|
||||
```diff
|
||||
$someClass = new SomeClass();
|
||||
-return $someClass->someFunction()
|
||||
- ->otherFunction();
|
||||
+$someClass->someFunction();
|
||||
+$someClass->otherFunction();
|
||||
|
||||
-return $someClass->someFunction()
|
||||
- ->otherFunction();
|
||||
+return $someClass;
|
||||
```
|
||||
|
||||
@ -5759,44 +5760,22 @@ Change Tree from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
## DowngradePhp70
|
||||
|
||||
### DowngradeTypeParamDeclarationRector
|
||||
### DowngradeTypeDeclarationRector
|
||||
|
||||
Remove the type params, add `@param` tags instead
|
||||
Remove the type params and return type, add `@param` and `@return` tags instead
|
||||
|
||||
- class: [`Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeParamDeclarationRector`](/rules/downgrade-php70/src/Rector/FunctionLike/DowngradeTypeParamDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeDeclarationRector`](/rules/downgrade-php70/src/Rector/FunctionLike/DowngradeTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run(string $input)
|
||||
- public function run(string $input): string
|
||||
+ /**
|
||||
+ * @param string $input
|
||||
+ * @return string
|
||||
+ */
|
||||
+ public function run($input)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeTypeReturnDeclarationRector
|
||||
|
||||
Remove returning types, add a `@return` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector`](/rules/downgrade-php70/src/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function getResponse(): string
|
||||
+ /**
|
||||
+ * @return string
|
||||
+ */
|
||||
+ public function getResponse()
|
||||
{
|
||||
return 'Hello world';
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -5825,42 +5804,21 @@ Downgrade class constant visibility
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeIterablePseudoTypeParamDeclarationRector
|
||||
### DowngradeIterablePseudoTypeDeclarationRector
|
||||
|
||||
Remove the iterable pseudo type params, add `@param` tags instead
|
||||
Remove the iterable pseudo type params and returns, add `@param` and `@return` tags instead
|
||||
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeIterablePseudoTypeParamDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeIterablePseudoTypeParamDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeIterablePseudoTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run(iterable $iterator)
|
||||
- public function run(iterable $iterator): iterable
|
||||
+ /**
|
||||
+ * @param mixed[]|\Traversable $iterator
|
||||
+ */
|
||||
+ public function run($iterator)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeIterablePseudoTypeReturnDeclarationRector
|
||||
|
||||
Remove returning iterable pseud type, add a `@return` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeIterablePseudoTypeReturnDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeIterablePseudoTypeReturnDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run(): iterable
|
||||
+ /**
|
||||
+ * @return mixed[]|\Traversable
|
||||
+ */
|
||||
+ public function run()
|
||||
+ public function run($iterator)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
@ -5886,47 +5844,22 @@ Downgrade negative string offset to `strlen`
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeNullableTypeParamDeclarationRector
|
||||
### DowngradeNullableTypeDeclarationRector
|
||||
|
||||
Remove the nullable type params, add `@param` tags instead
|
||||
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeNullableTypeParamDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run(?string $input)
|
||||
- public function run(?string $input): ?string
|
||||
+ /**
|
||||
+ * @param string|null $input
|
||||
+ * @return string|null $input
|
||||
+ */
|
||||
+ public function run($input)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeNullableTypeReturnDeclarationRector
|
||||
|
||||
Remove returning nullable types, add a `@return` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeNullableTypeReturnDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function getResponseOrNothing(bool $flag): ?string
|
||||
+ /**
|
||||
+ * @return string|null
|
||||
+ */
|
||||
+ public function getResponseOrNothing(bool $flag)
|
||||
{
|
||||
if ($flag) {
|
||||
return 'Hello world';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -5953,11 +5886,11 @@ Downgrade single one | separated to multi catch exception
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeVoidTypeReturnDeclarationRector
|
||||
### DowngradeVoidTypeDeclarationRector
|
||||
|
||||
Remove "void" return type, add a `"@return` void" tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeVoidTypeReturnDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp71\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector`](/rules/downgrade-php71/src/Rector/FunctionLike/DowngradeVoidTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
@ -5989,18 +5922,19 @@ Downgrade Symmetric array destructuring to `list()` function
|
||||
|
||||
## DowngradePhp72
|
||||
|
||||
### DowngradeParamObjectTypeDeclarationRector
|
||||
### DowngradeObjectTypeDeclarationRector
|
||||
|
||||
Remove the 'PHPStan\Type\ObjectWithoutClassType' param type, add a `@param` tag instead
|
||||
Remove the "object" param and return type, add a `@param` and `@return` tags instead
|
||||
|
||||
- class: [`Rector\DowngradePhp72\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector`](/rules/downgrade-php72/src/Rector/FunctionLike/DowngradeParamObjectTypeDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp72\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector`](/rules/downgrade-php72/src/Rector/FunctionLike/DowngradeObjectTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function someFunction(object $someObject)
|
||||
- public function someFunction(object $someObject): object
|
||||
+ /**
|
||||
+ * @param object $someObject
|
||||
+ * @return object
|
||||
+ */
|
||||
+ public function someFunction($someObject)
|
||||
{
|
||||
@ -6043,28 +5977,6 @@ Remove argument type declarations in the parent and in all child classes, whenev
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeReturnObjectTypeDeclarationRector
|
||||
|
||||
Remove "object" return type, add a `"@return` object" tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp72\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector`](/rules/downgrade-php72/src/Rector/FunctionLike/DowngradeReturnObjectTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function getSomeObject(): object
|
||||
+ /**
|
||||
+ * @return object
|
||||
+ */
|
||||
+ public function getSomeObject()
|
||||
{
|
||||
return new SomeObject();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## DowngradePhp73
|
||||
|
||||
### DowngradeFlexibleHeredocSyntaxRector
|
||||
@ -6238,7 +6150,9 @@ Remove contravariant argument type declarations
|
||||
class A
|
||||
{
|
||||
public function contraVariantArguments(ChildType $type)
|
||||
{ /* … */ }
|
||||
- {
|
||||
- }
|
||||
+ { }
|
||||
}
|
||||
|
||||
class B extends A
|
||||
@ -6248,7 +6162,8 @@ Remove contravariant argument type declarations
|
||||
+ * @param ParentType $type
|
||||
+ */
|
||||
+ public function contraVariantArguments($type)
|
||||
{ /* … */ }
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -6267,7 +6182,8 @@ Make method return same type as parent
|
||||
class A
|
||||
{
|
||||
public function covariantReturnTypes(): ParentType
|
||||
{ /* … */ }
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A
|
||||
@ -6277,7 +6193,8 @@ Make method return same type as parent
|
||||
+ * @return ChildType
|
||||
+ */
|
||||
+ public function covariantReturnTypes(): ParentType
|
||||
{ /* … */ }
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -6333,14 +6250,14 @@ Remove "_" as thousands separator in numbers
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeReturnSelfTypeDeclarationRector
|
||||
### DowngradeSelfTypeDeclarationRector
|
||||
|
||||
Remove "self" return type, add a `"@return` self" tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp74\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector`](/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeReturnSelfTypeDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp74\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector`](/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeSelfTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class A
|
||||
class SomeClass
|
||||
{
|
||||
- public function foo(): self
|
||||
+ public function foo()
|
||||
@ -6456,6 +6373,28 @@ Downgrade `match()` to `switch()`
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeMixedTypeDeclarationRector
|
||||
|
||||
Remove the "mixed" param and return type, add a `@param` and `@return` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeMixedTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function someFunction(mixed $anything): mixed
|
||||
+ /**
|
||||
+ * @param mixed $anything
|
||||
+ * @return mixed
|
||||
+ */
|
||||
+ public function someFunction($anything)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeNonCapturingCatchesRector
|
||||
|
||||
Downgrade catch () without variable to one
|
||||
@ -6494,27 +6433,6 @@ Change nullsafe operator to ternary operator rector
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeParamMixedTypeDeclarationRector
|
||||
|
||||
Remove the 'PHPStan\Type\MixedType' param type, add a `@param` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeParamMixedTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function someFunction(mixed $anything)
|
||||
+ /**
|
||||
+ * @param mixed $anything
|
||||
+ */
|
||||
+ public function someFunction($anything)
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradePropertyPromotionRector
|
||||
|
||||
Change constructor property promotion to property asssign
|
||||
@ -6536,36 +6454,11 @@ Change constructor property promotion to property asssign
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeReturnMixedTypeDeclarationRector
|
||||
### DowngradeStaticTypeDeclarationRector
|
||||
|
||||
Remove "mixed" return type, add a `"@return` mixed" tag instead
|
||||
Remove "static" return and param type, add a `"@param` `$this"` and `"@return` `$this"` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeReturnMixedTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function getAnything(bool $flag): mixed
|
||||
+ /**
|
||||
+ * @return mixed
|
||||
+ */
|
||||
+ public function getAnything(bool $flag)
|
||||
{
|
||||
if ($flag) {
|
||||
return 1;
|
||||
}
|
||||
return 'Hello world'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeReturnStaticTypeDeclarationRector
|
||||
|
||||
Remove "static" return type, add a `"@return` `$this"` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeReturnStaticTypeDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeStaticTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
@ -6613,18 +6506,19 @@ Remove trailing commas in param or use list
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeUnionTypeParamDeclarationRector
|
||||
### DowngradeUnionTypeDeclarationRector
|
||||
|
||||
Remove the union type params, add `@param` tags instead
|
||||
Remove the union type params and returns, add `@param/@return` tags instead
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeUnionTypeParamDeclarationRector.php)
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function echoInput(string|int $input)
|
||||
- public function echoInput(string|int $input): int|bool
|
||||
+ /**
|
||||
+ * @param string|int $input
|
||||
+ * @return int|bool
|
||||
+ */
|
||||
+ public function echoInput($input)
|
||||
{
|
||||
@ -6635,31 +6529,6 @@ Remove the union type params, add `@param` tags instead
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeUnionTypeReturnDeclarationRector
|
||||
|
||||
Remove returning union types, add a `@return` tag instead
|
||||
|
||||
- class: [`Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector`](/rules/downgrade-php80/src/Rector/FunctionLike/DowngradeUnionTypeReturnDeclarationRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function getSomeObject(bool $flag): string|int
|
||||
+ /**
|
||||
+ * @return string|int
|
||||
+ */
|
||||
+ public function getSomeObject(bool $flag)
|
||||
{
|
||||
if ($flag) {
|
||||
return 1;
|
||||
}
|
||||
return 'Hello world';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DowngradeUnionTypeTypedPropertyRector
|
||||
|
||||
Removes union type property type definition, adding `@var` annotations instead.
|
||||
@ -7468,14 +7337,14 @@ Renames property to respect is/has/was method naming
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- private $full = false;
|
||||
+ private $isFull = false;
|
||||
-private $full = false;
|
||||
+private $isFull = false;
|
||||
|
||||
public function isFull()
|
||||
{
|
||||
- return $this->full;
|
||||
+ return $this->isFull;
|
||||
}
|
||||
public function isFull()
|
||||
{
|
||||
- return $this->full;
|
||||
+ return $this->isFull;
|
||||
}
|
||||
+
|
||||
}
|
||||
```
|
||||
@ -7539,16 +7408,16 @@ Renames value variable name in foreach loop to match expression variable
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$array = [];
|
||||
- foreach ($variables as $foo) {
|
||||
- $array[] = $property;
|
||||
+ foreach ($variables as $variable) {
|
||||
+ $array[] = $variable;
|
||||
}
|
||||
public function run()
|
||||
{
|
||||
$array = [];
|
||||
- foreach ($variables as $foo) {
|
||||
- $array[] = $property;
|
||||
+ foreach ($variables as $variable) {
|
||||
+ $array[] = $variable;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
@ -11678,14 +11547,17 @@ Change annotation to attribute
|
||||
- class: [`Rector\Php80\Rector\Class_\AnnotationToAttributeRector`](/rules/php80/src/Rector/Class_/AnnotationToAttributeRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Attributes as ORM;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
-/**
|
||||
- * @ORM\Entity
|
||||
- */
|
||||
+#[ORM\Entity]
|
||||
class SomeClass
|
||||
class SymfonyRoute
|
||||
{
|
||||
- /**
|
||||
- * @Route("/path", name="action")
|
||||
- */
|
||||
+ #[Route(path: '/path', name: 'action')]
|
||||
public function action()
|
||||
{
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -13077,7 +12949,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
|
||||
### PassFactoryToUniqueObjectRector
|
||||
|
||||
Convert new `X/Static::call()` to factories in entities, pass them via constructor to `each` other
|
||||
Convert new `X/Static::call()` to factories in entities, pass them via constructor to each other
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
|
@ -12,5 +12,5 @@ interface DowngradeParamDeclarationRectorInterface
|
||||
/**
|
||||
* Indicate if the parameter must be removed
|
||||
*/
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool;
|
||||
public function isNullableParam(Param $param, FunctionLike $functionLike): bool;
|
||||
}
|
||||
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp70\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\IntersectionType;
|
||||
use PHPStan\Type\IterableType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp70\Contract\Rector\DowngradeParamDeclarationRectorInterface;
|
||||
use Traversable;
|
||||
|
||||
abstract class AbstractDowngradeParamDeclarationRector extends AbstractRector implements DowngradeParamDeclarationRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
|
||||
/**
|
||||
* @required
|
||||
*/
|
||||
public function autowireAbstractDowngradeParamDeclarationRector(PhpDocTypeChanger $phpDocTypeChanger): void
|
||||
{
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node->params === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($node->params as $param) {
|
||||
$this->refactorParam($param, $node);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function refactorParam(Param $param, FunctionLike $functionLike): void
|
||||
{
|
||||
if (! $this->shouldRemoveParamDeclaration($param, $functionLike)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->decorateWithDocBlock($functionLike, $param);
|
||||
$param->type = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function decorateWithDocBlock(FunctionLike $functionLike, Param $param): void
|
||||
{
|
||||
if ($param->type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
if ($type instanceof IterableType) {
|
||||
$type = new UnionType([$type, new IntersectionType([new ObjectType(Traversable::class)])]);
|
||||
}
|
||||
|
||||
$paramName = $this->getName($param->var) ?? '';
|
||||
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
||||
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp70\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\CallableType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\DowngradeTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the type params and return type, add @param and @return tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(string $input): string
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param string $input
|
||||
* @return string
|
||||
*/
|
||||
public function run($input)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Function_|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$this->refactorParams($node);
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturn($node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function refactorParams(FunctionLike $functionLike): void
|
||||
{
|
||||
foreach ($functionLike->params as $param) {
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateParam(
|
||||
$param,
|
||||
$functionLike,
|
||||
[ArrayType::class, CallableType::class]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp70\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\CallableType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector\DowngradeTypeParamDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeTypeParamDeclarationRector extends AbstractDowngradeParamDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the type params, add @param tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(string $input)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param string $input
|
||||
*/
|
||||
public function run($input)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only accepted types before PHP 7.0 are `array` and `callable`
|
||||
*/
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($param->type === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
if (is_a($type, ArrayType::class, true)) {
|
||||
return false;
|
||||
}
|
||||
return ! is_a($type, CallableType::class, true);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp70\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector\DowngradeTypeReturnDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeTypeReturnDeclarationRector extends AbstractDowngradeReturnDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove returning types, add a @return tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getResponse(): string
|
||||
{
|
||||
return 'Hello world';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return 'Hello world';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
public function shouldRemoveReturnDeclaration(FunctionLike $functionLike): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -2,13 +2,13 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeTypeParamDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
@ -13,7 +13,7 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class ReturnArrayTypeOnClassMethod
|
||||
class ReturnArray
|
||||
{
|
||||
public function run(): array
|
||||
{
|
||||
@ -14,9 +14,9 @@ class ReturnArrayTypeOnClassMethod
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class ReturnArrayTypeOnClassMethod
|
||||
class ReturnArray
|
||||
{
|
||||
/**
|
||||
* @return mixed[]
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnString
|
||||
{
|
||||
public function run(): string
|
||||
{
|
||||
@ -14,9 +14,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnString
|
||||
{
|
||||
/**
|
||||
* @return string
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class SkipArray
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeDeclarationRector\Fixture;
|
||||
|
||||
class SkipCallable
|
||||
{
|
@ -4,13 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeDeclarationRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::NULLABLE_TYPE - 1);
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::SCALAR_TYPES - 1);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeTypeParamDeclarationRector::class);
|
||||
$services->set(DowngradeTypeDeclarationRector::class);
|
||||
};
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeTypeReturnDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/php_70.php';
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::NULLABLE_TYPE - 1);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(DowngradeTypeReturnDeclarationRector::class);
|
||||
};
|
17
rules/downgrade-php71/config/config.php
Normal file
17
rules/downgrade-php71/config/config.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->defaults()
|
||||
->public()
|
||||
->autowire()
|
||||
->autoconfigure();
|
||||
|
||||
$services->load('Rector\DowngradePhp71\\', __DIR__ . '/../src')
|
||||
->exclude([__DIR__ . '/../src/Rector']);
|
||||
};
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\IterableType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector\DowngradeIterablePseudoTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeIterablePseudoTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the iterable pseudo type params and returns, add @param and @return tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(iterable $iterator): iterable
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param mixed[]|\Traversable $iterator
|
||||
* @return mixed[]|\Traversable
|
||||
*/
|
||||
public function run($iterator)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Function_|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->params as $param) {
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateParamWithSpecificType(
|
||||
$param,
|
||||
$node,
|
||||
IterableType::class
|
||||
);
|
||||
}
|
||||
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, IterableType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Param;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeParamDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeParamDeclarationRector\DowngradeIterablePseudoTypeParamDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeIterablePseudoTypeParamDeclarationRector extends AbstractDowngradeParamDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the iterable pseudo type params, add @param tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(iterable $iterator)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param mixed[]|\Traversable $iterator
|
||||
*/
|
||||
public function run($iterator)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($param->type === null) {
|
||||
return false;
|
||||
}
|
||||
if (! $param->type instanceof Identifier) {
|
||||
return false;
|
||||
}
|
||||
return $param->type->toString() === 'iterable';
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeReturnDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeReturnDeclarationRector\DowngradeIterablePseudoTypeReturnDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeIterablePseudoTypeReturnDeclarationRector extends AbstractDowngradeReturnDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove returning iterable pseud type, add a @return tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(): iterable
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return mixed[]|\Traversable
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
public function shouldRemoveReturnDeclaration(FunctionLike $functionLike): bool
|
||||
{
|
||||
$functionLikeReturnType = $functionLike->returnType;
|
||||
|
||||
if ($functionLikeReturnType === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($functionLikeReturnType, 'iterable');
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector\DowngradeNullableTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeNullableTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(
|
||||
PhpDocTypeChanger $phpDocTypeChanger,
|
||||
PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator
|
||||
) {
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove the nullable type params, add @param tags instead', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(?string $input): ?string
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param string|null $input
|
||||
* @return string|null $input
|
||||
*/
|
||||
public function run($input)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->params as $param) {
|
||||
$this->refactorParamType($param, $node);
|
||||
}
|
||||
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, NullableType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function isNullableParam(Param $param): bool
|
||||
{
|
||||
if ($param->variadic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($param->type === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check it is the union type
|
||||
return $param->type instanceof NullableType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function refactorParamType(Param $param, FunctionLike $functionLike): void
|
||||
{
|
||||
if (! $this->isNullableParam($param)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->decorateWithDocBlock($functionLike, $param);
|
||||
$param->type = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function decorateWithDocBlock(FunctionLike $functionLike, Param $param): void
|
||||
{
|
||||
if ($param->type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
|
||||
$paramName = $this->getName($param->var);
|
||||
if ($paramName === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
||||
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeParamDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector\DowngradeNullableTypeParamDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeNullableTypeParamDeclarationRector extends AbstractDowngradeParamDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the nullable type params, add @param tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(?string $input)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param string|null $input
|
||||
*/
|
||||
public function run($input)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($param->variadic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($param->type === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check it is the union type
|
||||
return $param->type instanceof NullableType;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeReturnDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector\DowngradeNullableTypeReturnDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeNullableTypeReturnDeclarationRector extends AbstractDowngradeReturnDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove returning nullable types, add a @return tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getResponseOrNothing(bool $flag): ?string
|
||||
{
|
||||
if ($flag) {
|
||||
return 'Hello world';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getResponseOrNothing(bool $flag)
|
||||
{
|
||||
if ($flag) {
|
||||
return 'Hello world';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
public function shouldRemoveReturnDeclaration(FunctionLike $functionLike): bool
|
||||
{
|
||||
return $functionLike->returnType instanceof NullableType;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\DowngradeVoidTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeVoidTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove "void" return type, add a "@return void" tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, VoidType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Rector\FunctionLike;
|
||||
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\AbstractDowngradeReturnTypeDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\DowngradeVoidTypeReturnDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeVoidTypeReturnDeclarationRector extends AbstractDowngradeReturnTypeDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove "void" return type, add a "@return void" tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return VoidType::class;
|
||||
}
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\TypeDeclaration;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
|
||||
final class PhpDocFromTypeDeclarationDecorator
|
||||
{
|
||||
/**
|
||||
* @var StaticTypeMapper
|
||||
*/
|
||||
private $staticTypeMapper;
|
||||
|
||||
/**
|
||||
* @var PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
|
||||
/**
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
|
||||
/**
|
||||
* @var PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
|
||||
/**
|
||||
* @var TypeUnwrapper
|
||||
*/
|
||||
private $typeUnwrapper;
|
||||
|
||||
public function __construct(
|
||||
StaticTypeMapper $staticTypeMapper,
|
||||
PhpDocInfoFactory $phpDocInfoFactory,
|
||||
NodeNameResolver $nodeNameResolver,
|
||||
PhpDocTypeChanger $phpDocTypeChanger,
|
||||
TypeUnwrapper $typeUnwrapper
|
||||
) {
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->typeUnwrapper = $typeUnwrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
public function decorateReturn(FunctionLike $functionLike): void
|
||||
{
|
||||
if ($functionLike->returnType === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($functionLike->returnType);
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
||||
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $type);
|
||||
|
||||
$functionLike->returnType = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
* @param array<class-string<Type>> $excludedTypes
|
||||
*/
|
||||
public function decorateParam(Param $param, FunctionLike $functionLike, array $excludedTypes = []): void
|
||||
{
|
||||
if ($param->type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
foreach ($excludedTypes as $excludedType) {
|
||||
if (is_a($type, $excludedType, true)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->moveParamTypeToParamDoc($functionLike, $param, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
* @param class-string<Node|Type> $requireTypeNode
|
||||
*/
|
||||
public function decorateParamWithSpecificType(
|
||||
Param $param,
|
||||
FunctionLike $functionLike,
|
||||
string $requireTypeNode
|
||||
): void {
|
||||
if ($param->type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->isTypeMatch($param->type, $requireTypeNode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
$this->moveParamTypeToParamDoc($functionLike, $param, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
* @param class-string<Node|Type> $requireTypeNode
|
||||
*/
|
||||
public function decorateReturnWithSpecificType(FunctionLike $functionLike, string $requireTypeNode): void
|
||||
{
|
||||
if ($functionLike->returnType === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->isTypeMatch($functionLike->returnType, $requireTypeNode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->decorateReturn($functionLike);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Node|Type> $requireTypeNodeClass
|
||||
*/
|
||||
private function isTypeMatch(Node $typeNode, string $requireTypeNodeClass): bool
|
||||
{
|
||||
if (is_a($requireTypeNodeClass, Node::class, true)) {
|
||||
if (! is_a($typeNode, $requireTypeNodeClass, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_a($requireTypeNodeClass, Type::class, true)) {
|
||||
$returnType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($typeNode);
|
||||
|
||||
// cover nullable union types
|
||||
if ($returnType instanceof UnionType) {
|
||||
$returnType = $this->typeUnwrapper->unwrapNullableType($returnType);
|
||||
}
|
||||
|
||||
if (! is_a($returnType, $requireTypeNodeClass, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function moveParamTypeToParamDoc(FunctionLike $functionLike, Param $param, Type $type): void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
||||
$paramName = $this->nodeNameResolver->getName($param);
|
||||
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
|
||||
|
||||
$param->type = null;
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeParamDeclarationRector;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeIterablePseudoTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeIterablePseudoTypeParamDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeIterablePseudoTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
@ -26,6 +26,6 @@ final class DowngradeIterablePseudoTypeParamDeclarationRectorTest extends Abstra
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeIterablePseudoTypeParamDeclarationRector::class;
|
||||
return DowngradeIterablePseudoTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ParamIterable
|
||||
{
|
||||
public function run(iterable $iterator)
|
||||
{
|
||||
@ -14,12 +14,12 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ParamIterable
|
||||
{
|
||||
/**
|
||||
* @param mixed[]|\Traversable $iterator
|
||||
* @param mixed[] $iterator
|
||||
*/
|
||||
public function run($iterator)
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnIterable
|
||||
{
|
||||
public function run(): iterable
|
||||
{
|
||||
@ -14,12 +14,12 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnIterable
|
||||
{
|
||||
/**
|
||||
* @return mixed[]|\Traversable
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function run()
|
||||
{
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeIterablePseudoTypeReturnDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeIterablePseudoTypeReturnDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeIterablePseudoTypeReturnDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeIterablePseudoTypeReturnDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeNullableTypeParamDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeNullableTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
@ -26,6 +26,6 @@ final class DowngradeNullableTypeParamDeclarationRectorTest extends AbstractRect
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeNullableTypeParamDeclarationRector::class;
|
||||
return DowngradeNullableTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ParamType
|
||||
{
|
||||
public function run(?string $value)
|
||||
{
|
||||
@ -13,9 +13,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ParamType
|
||||
{
|
||||
/**
|
||||
* @param string|null $value
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnType
|
||||
{
|
||||
public function run(): ?string
|
||||
{
|
||||
@ -18,9 +18,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnType
|
||||
{
|
||||
/**
|
||||
* @return string|null
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeReturnDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeNullableTypeReturnDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeNullableTypeReturnDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector;
|
||||
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeVoidTypeReturnDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeVoidTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
@ -26,6 +26,6 @@ final class DowngradeVoidTypeReturnDeclarationRectorTest extends AbstractRectorT
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeVoidTypeReturnDeclarationRector::class;
|
||||
return DowngradeVoidTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
||||
@ -16,7 +16,7 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
/**
|
||||
@ -17,7 +17,7 @@ class DocblockTagExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
@ -14,7 +14,7 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp71\Tests\Rector\FunctionLike\DowngradeVoidTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeParamDeclarationRector;
|
||||
use Rector\DowngradePhp72\Contract\Rector\DowngradeTypeRectorInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
|
||||
abstract class AbstractDowngradeParamTypeDeclarationRector extends AbstractDowngradeParamDeclarationRector implements DowngradeTypeRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var TypeUnwrapper
|
||||
*/
|
||||
private $typeUnwrapper;
|
||||
|
||||
public function __construct(TypeUnwrapper $typeUnwrapper)
|
||||
{
|
||||
$this->typeUnwrapper = $typeUnwrapper;
|
||||
}
|
||||
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($param->variadic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($param->type === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
$type = $this->typeUnwrapper->unwrapNullableType($type);
|
||||
|
||||
return is_a($type, $this->getTypeToRemove(), true);
|
||||
}
|
||||
|
||||
protected function getRectorDefinitionDescription(): string
|
||||
{
|
||||
return sprintf("Remove the '%s' param type, add a @param tag instead", $this->getTypeToRemove());
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeReturnDeclarationRector;
|
||||
use Rector\DowngradePhp72\Contract\Rector\DowngradeTypeRectorInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
|
||||
abstract class AbstractDowngradeReturnTypeDeclarationRector extends AbstractDowngradeReturnDeclarationRector implements DowngradeTypeRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var TypeUnwrapper
|
||||
*/
|
||||
private $typeUnwrapper;
|
||||
|
||||
public function __construct(TypeUnwrapper $typeUnwrapper)
|
||||
{
|
||||
$this->typeUnwrapper = $typeUnwrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
public function shouldRemoveReturnDeclaration(FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($functionLike->returnType === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($functionLike->returnType);
|
||||
$type = $this->typeUnwrapper->unwrapNullableType($type);
|
||||
|
||||
return is_a($type, $this->getTypeToRemove(), true);
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\DowngradeObjectTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeObjectTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Function_|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->params as $param) {
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateParamWithSpecificType(
|
||||
$param,
|
||||
$node,
|
||||
ObjectWithoutClassType::class
|
||||
);
|
||||
}
|
||||
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, ObjectWithoutClassType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the "object" param and return type, add a @param and @return tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function someFunction(object $someObject): object
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param object $someObject
|
||||
* @return object
|
||||
*/
|
||||
public function someFunction($someObject)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Rector\FunctionLike;
|
||||
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\DowngradeParamObjectTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeParamObjectTypeDeclarationRector extends AbstractDowngradeParamTypeDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
$this->getRectorDefinitionDescription(),
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function someFunction(object $someObject)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param object $someObject
|
||||
*/
|
||||
public function someFunction($someObject)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return ObjectWithoutClassType::class;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Rector\FunctionLike;
|
||||
|
||||
use PHPStan\Type\ObjectWithoutClassType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\DowngradeReturnObjectTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeReturnObjectTypeDeclarationRector extends AbstractDowngradeReturnTypeDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove "object" return type, add a "@return object" tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getSomeObject(): object
|
||||
{
|
||||
return new SomeObject();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return object
|
||||
*/
|
||||
public function getSomeObject()
|
||||
{
|
||||
return new SomeObject();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return ObjectWithoutClassType::class;
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeParamObjectTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeObjectTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 7.2
|
||||
@ -27,6 +27,6 @@ final class DowngradeParamObjectTypeDeclarationRectorTest extends AbstractRector
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeParamObjectTypeDeclarationRector::class;
|
||||
return DowngradeObjectTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
class ParamDocblockExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
*/
|
||||
@ -15,9 +15,9 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
class ParamDocblockExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @param object $someObject
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
class ParamDocblockTagExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @param object $someObject
|
||||
@ -16,9 +16,9 @@ class DocblockTagExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
class ParamDocblockTagExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @param object $someObject
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
class ParamFixture
|
||||
{
|
||||
public function someFunction(object $someObject)
|
||||
{
|
||||
@ -13,9 +13,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
class ParamFixture
|
||||
{
|
||||
/**
|
||||
* @param object $someObject
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleMatchingParams
|
||||
class ParamMultipleMatchingParams
|
||||
{
|
||||
public function someFunction(object $someObject, string $someOtherVar, object $someOtherObject, ?object $nullableObject)
|
||||
{
|
||||
@ -13,9 +13,9 @@ class MultipleMatchingParams
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleMatchingParams
|
||||
class ParamMultipleMatchingParams
|
||||
{
|
||||
/**
|
||||
* @param object $someObject
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleParams
|
||||
class ParamMultipleParams
|
||||
{
|
||||
public function someFunction(object $someObject, string $someOtherVar)
|
||||
{
|
||||
@ -13,9 +13,9 @@ class MultipleParams
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleParams
|
||||
class ParamMultipleParams
|
||||
{
|
||||
/**
|
||||
* @param object $someObject
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class NullableType
|
||||
class ParamNullableType
|
||||
{
|
||||
public function someFunction(?object $someObject)
|
||||
{
|
||||
@ -13,9 +13,9 @@ class NullableType
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class NullableType
|
||||
class ParamNullableType
|
||||
{
|
||||
/**
|
||||
* @param object|null $someObject
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
class ReturnDocblockExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
*/
|
||||
@ -16,9 +16,9 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
class ReturnDocblockExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @return object
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
class ReturnDocblockTagExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @return object
|
||||
@ -17,9 +17,9 @@ class DocblockTagExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
class ReturnDocblockTagExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @return object
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
class ReturnFixture
|
||||
{
|
||||
public function getSomeObject(): object
|
||||
{
|
||||
@ -14,9 +14,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
class ReturnFixture
|
||||
{
|
||||
/**
|
||||
* @return object
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class NullableType
|
||||
class ReturnNullableType
|
||||
{
|
||||
public function getSomeObject(): ?object
|
||||
{
|
||||
@ -14,9 +14,9 @@ class NullableType
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Fixture;
|
||||
|
||||
class NullableType
|
||||
class ReturnNullableType
|
||||
{
|
||||
/**
|
||||
* @return object|null
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector\Source;
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeObjectTypeDeclarationRector\Source;
|
||||
|
||||
|
||||
class AnotherClass
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeReturnObjectTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 7.2
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeReturnObjectTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Rector\DowngradePhp72\Tests\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector\Source;
|
||||
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
|
||||
}
|
@ -8,11 +8,14 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\UnionType;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeParamDeclarationRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use ReflectionMethod;
|
||||
use ReflectionNamedType;
|
||||
@ -25,8 +28,26 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*
|
||||
* @see \Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeContravariantArgumentTypeRector\DowngradeContravariantArgumentTypeRectorTest
|
||||
*/
|
||||
final class DowngradeContravariantArgumentTypeRector extends AbstractDowngradeParamDeclarationRector
|
||||
final class DowngradeContravariantArgumentTypeRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
|
||||
public function __construct(PhpDocTypeChanger $phpDocTypeChanger)
|
||||
{
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class, Function_::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove contravariant argument type declarations', [
|
||||
@ -38,13 +59,15 @@ class ChildType extends ParentType {}
|
||||
class A
|
||||
{
|
||||
public function contraVariantArguments(ChildType $type)
|
||||
{ /* … */ }
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A
|
||||
{
|
||||
public function contraVariantArguments(ParentType $type)
|
||||
{ /* … */ }
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
@ -55,7 +78,7 @@ class ChildType extends ParentType {}
|
||||
class A
|
||||
{
|
||||
public function contraVariantArguments(ChildType $type)
|
||||
{ /* … */ }
|
||||
{ }
|
||||
}
|
||||
|
||||
class B extends A
|
||||
@ -64,14 +87,15 @@ class B extends A
|
||||
* @param ParentType $type
|
||||
*/
|
||||
public function contraVariantArguments($type)
|
||||
{ /* … */ }
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool
|
||||
public function isNullableParam(Param $param, FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($param->variadic) {
|
||||
return false;
|
||||
@ -95,6 +119,22 @@ CODE_SAMPLE
|
||||
return $this->getDifferentParamTypeFromAncestorClass($param, $functionLike) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node->params === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($node->params as $param) {
|
||||
$this->refactorParam($param, $node);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getDifferentParamTypeFromAncestorClass(Param $param, FunctionLike $functionLike): ?string
|
||||
{
|
||||
$scope = $functionLike->getAttribute(AttributeKey::SCOPE);
|
||||
@ -190,4 +230,33 @@ CODE_SAMPLE
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function refactorParam(Param $param, FunctionLike $functionLike): void
|
||||
{
|
||||
if (! $this->isNullableParam($param, $functionLike)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->decorateWithDocBlock($functionLike, $param);
|
||||
$param->type = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
private function decorateWithDocBlock(FunctionLike $functionLike, Param $param): void
|
||||
{
|
||||
if ($param->type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
|
||||
$paramName = $this->getName($param->var) ?? '';
|
||||
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
||||
$this->phpDocTypeChanger->changeParamType($phpDocInfo, $type, $param, $paramName);
|
||||
}
|
||||
}
|
||||
|
@ -7,15 +7,34 @@ namespace Rector\DowngradePhp74\Rector\ClassMethod;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Type\ThisType;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\AbstractDowngradeReturnTypeDeclarationRector;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\DowngradeReturnSelfTypeDeclarationRectorTest
|
||||
* @see \Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\DowngradeSelfTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeReturnSelfTypeDeclarationRector extends AbstractDowngradeReturnTypeDeclarationRector
|
||||
final class DowngradeSelfTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
@ -23,7 +42,7 @@ final class DowngradeReturnSelfTypeDeclarationRector extends AbstractDowngradeRe
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class A
|
||||
class SomeClass
|
||||
{
|
||||
public function foo(): self
|
||||
{
|
||||
@ -33,7 +52,7 @@ class A
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class A
|
||||
class SomeClass
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
@ -47,15 +66,12 @@ CODE_SAMPLE
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, ThisType::class);
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return ThisType::class;
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector;
|
||||
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeReturnSelfTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeSelfTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 7.4
|
||||
@ -27,6 +27,6 @@ final class DowngradeReturnSelfTypeDeclarationRectorTest extends AbstractRectorT
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeReturnSelfTypeDeclarationRector::class;
|
||||
return DowngradeSelfTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
||||
@ -16,7 +16,7 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
@ -14,7 +14,7 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
interface WithSelfInterface
|
||||
{
|
||||
@ -11,7 +11,7 @@ interface WithSelfInterface
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
interface WithSelfInterface
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
class NullableType
|
||||
{
|
||||
@ -14,7 +14,7 @@ class NullableType
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
class NullableType
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
trait WithSelfTrait
|
||||
{
|
||||
@ -14,7 +14,7 @@ trait WithSelfTrait
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeReturnSelfTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\ClassMethod\DowngradeSelfTypeDeclarationRector\Fixture;
|
||||
|
||||
trait WithSelfTrait
|
||||
{
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\DowngradeMixedTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeMixedTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the "mixed" param and return type, add a @param and @return tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function someFunction(mixed $anything): mixed
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param mixed $anything
|
||||
* @return mixed
|
||||
*/
|
||||
public function someFunction($anything)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->getParams() as $param) {
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateParamWithSpecificType($param, $node, MixedType::class);
|
||||
}
|
||||
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, MixedType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\AbstractDowngradeParamTypeDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\DowngradeParamMixedTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeParamMixedTypeDeclarationRector extends AbstractDowngradeParamTypeDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
$this->getRectorDefinitionDescription(),
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function someFunction(mixed $anything)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param mixed $anything
|
||||
*/
|
||||
public function someFunction($anything)
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return MixedType::class;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\AbstractDowngradeReturnTypeDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\DowngradeReturnMixedTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeReturnMixedTypeDeclarationRector extends AbstractDowngradeReturnTypeDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove "mixed" return type, add a "@return mixed" tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getAnything(bool $flag): mixed
|
||||
{
|
||||
if ($flag) {
|
||||
return 1;
|
||||
}
|
||||
return 'Hello world'
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAnything(bool $flag)
|
||||
{
|
||||
if ($flag) {
|
||||
return 1;
|
||||
}
|
||||
return 'Hello world'
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return MixedType::class;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PHPStan\Type\StaticType;
|
||||
use Rector\DowngradePhp72\Rector\FunctionLike\AbstractDowngradeReturnTypeDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\DowngradeReturnStaticTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeReturnStaticTypeDeclarationRector extends AbstractDowngradeReturnTypeDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove "static" return type, add a "@return $this" tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getStatic(): static
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function getStatic()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeToRemove(): string
|
||||
{
|
||||
return StaticType::class;
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Type\StaticType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\DowngradeStaticTypeDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeStaticTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove "static" return and param type, add a "@param $this" and "@return $this" tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getStatic(): static
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function getStatic()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->getParams() as $param) {
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateParamWithSpecificType($param, $node, StaticType::class);
|
||||
}
|
||||
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, StaticType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\UnionType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DowngradePhp71\TypeDeclaration\PhpDocFromTypeDeclarationDecorator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\DowngradeUnionTypeDeclarationRectorTest
|
||||
*
|
||||
* @requires PHP 8.0
|
||||
*/
|
||||
final class DowngradeUnionTypeDeclarationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocFromTypeDeclarationDecorator
|
||||
*/
|
||||
private $phpDocFromTypeDeclarationDecorator;
|
||||
|
||||
public function __construct(PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
|
||||
{
|
||||
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Function_::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the union type params and returns, add @param/@return tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function echoInput(string|int $input): int|bool
|
||||
{
|
||||
echo $input;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param string|int $input
|
||||
* @return int|bool
|
||||
*/
|
||||
public function echoInput($input)
|
||||
{
|
||||
echo $input;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
foreach ($node->getParams() as $param) {
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateParamWithSpecificType($param, $node, UnionType::class);
|
||||
}
|
||||
|
||||
$this->phpDocFromTypeDeclarationDecorator->decorateReturnWithSpecificType($node, UnionType::class);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\UnionType;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeParamDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector\DowngradeUnionTypeParamDeclarationRectorTest
|
||||
*
|
||||
* @requires PHP 8.0
|
||||
*/
|
||||
final class DowngradeUnionTypeParamDeclarationRector extends AbstractDowngradeParamDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove the union type params, add @param tags instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function echoInput(string|int $input)
|
||||
{
|
||||
echo $input;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @param string|int $input
|
||||
*/
|
||||
public function echoInput($input)
|
||||
{
|
||||
echo $input;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function shouldRemoveParamDeclaration(Param $param, FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($param->variadic) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($param->type === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check it is the union type
|
||||
return $param->type instanceof UnionType;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Rector\FunctionLike;
|
||||
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\UnionType;
|
||||
use Rector\DowngradePhp70\Rector\FunctionLike\AbstractDowngradeReturnDeclarationRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector\DowngradeUnionTypeReturnDeclarationRectorTest
|
||||
*/
|
||||
final class DowngradeUnionTypeReturnDeclarationRector extends AbstractDowngradeReturnDeclarationRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove returning union types, add a @return tag instead',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getSomeObject(bool $flag): string|int
|
||||
{
|
||||
if ($flag) {
|
||||
return 1;
|
||||
}
|
||||
return 'Hello world';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @return string|int
|
||||
*/
|
||||
public function getSomeObject(bool $flag)
|
||||
{
|
||||
if ($flag) {
|
||||
return 1;
|
||||
}
|
||||
return 'Hello world';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod|Function_ $functionLike
|
||||
*/
|
||||
public function shouldRemoveReturnDeclaration(FunctionLike $functionLike): bool
|
||||
{
|
||||
if ($functionLike->returnType === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check it is the union type
|
||||
return $functionLike->returnType instanceof UnionType;
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeParamMixedTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeMixedTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 8.0
|
||||
@ -27,6 +27,6 @@ final class DowngradeParamMixedTypeDeclarationRectorTest extends AbstractRectorT
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeParamMixedTypeDeclarationRector::class;
|
||||
return DowngradeMixedTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
||||
@ -15,7 +15,7 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
/**
|
||||
@ -16,7 +16,7 @@ class DocblockTagExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
@ -13,7 +13,7 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleMatchingParams
|
||||
{
|
||||
@ -13,7 +13,7 @@ class MultipleMatchingParams
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleMatchingParams
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleParams
|
||||
{
|
||||
@ -13,7 +13,7 @@ class MultipleParams
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class MultipleParams
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
class ReturnDocblockExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
*/
|
||||
@ -20,9 +20,9 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
class ReturnDocblockExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @return mixed
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
class ReturnDocblockTagExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @return mixed
|
||||
@ -21,9 +21,9 @@ class DocblockTagExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
class ReturnDocblockTagExists {
|
||||
/**
|
||||
* This property is the best one
|
||||
* @return mixed
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnFixture
|
||||
{
|
||||
public function getAnything(): mixed
|
||||
{
|
||||
@ -18,9 +18,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnFixture
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeParamMixedTypeDeclarationRector\Source;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector\Source;
|
||||
|
||||
|
||||
class AnotherClass
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeReturnStaticTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 8.0
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeReturnStaticTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Source;
|
||||
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeReturnMixedTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeStaticTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 8.0
|
||||
@ -27,6 +27,6 @@ final class DowngradeReturnMixedTypeDeclarationRectorTest extends AbstractRector
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeReturnMixedTypeDeclarationRector::class;
|
||||
return DowngradeStaticTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
||||
@ -20,7 +20,7 @@ class DocblockExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
/**
|
||||
@ -21,7 +21,7 @@ class DocblockTagExists {
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Fixture;
|
||||
|
||||
class DocblockTagExists {
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
@ -18,7 +18,7 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnStaticTypeDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeReturnMixedTypeDeclarationRector\Source;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeStaticTypeDeclarationRector\Source;
|
||||
|
||||
|
||||
class AnotherClass
|
@ -2,14 +2,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeUnionTypeParamDeclarationRectorTest extends AbstractRectorTestCase
|
||||
final class DowngradeUnionTypeDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
@ -27,6 +27,6 @@ final class DowngradeUnionTypeParamDeclarationRectorTest extends AbstractRectorT
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeUnionTypeParamDeclarationRector::class;
|
||||
return DowngradeUnionTypeDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ParamUnion
|
||||
{
|
||||
public function run(int|string $value)
|
||||
{
|
||||
@ -13,9 +13,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeParamDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ParamUnion
|
||||
{
|
||||
/**
|
||||
* @param int|string $value
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnUnion
|
||||
{
|
||||
public function run(): int|string
|
||||
{
|
||||
@ -18,9 +18,9 @@ class Fixture
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector\Fixture;
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector\Fixture;
|
||||
|
||||
class Fixture
|
||||
final class ReturnUnion
|
||||
{
|
||||
/**
|
||||
* @return int|string
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp80\Tests\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeReturnDeclarationRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeUnionTypeReturnDeclarationRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
* @requires PHP 8.0
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeUnionTypeReturnDeclarationRector::class;
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ services:
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
allowedParentTypes:
|
||||
- Rector\Core\Rector\AbstractRector
|
||||
- Rector\Utils\DoctrineAnnotationParserSyncer\FileSyncer\AbstractClassSyncer
|
||||
- PhpParser\NodeAbstract
|
||||
- PHPStan\Type\BooleanType
|
||||
@ -15,6 +14,23 @@ services:
|
||||
# value objects
|
||||
- Rector\Defluent\ValueObject\AbstractRootExpr
|
||||
- Symplify\SetConfigResolver\Provider\AbstractSetProvider
|
||||
allowedDirectParentTypes:
|
||||
- Rector\Core\Rector\AbstractRector
|
||||
- Rector\Core\Rector\AbstractTemporaryRector
|
||||
- Rector\PhpSpecToPHPUnit\Rector\AbstractPhpSpecToPHPUnitRector
|
||||
# solve later
|
||||
- Rector\Nette\Rector\FuncCall\AbstractPregToNetteUtilsStringsRector
|
||||
- Rector\Nette\Rector\Identical\AbstractWithFunctionToNetteUtilsStringsRector
|
||||
- Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector
|
||||
- Rector\Php72\Rector\FuncCall\AbstractConvertToAnonymousFunctionRector
|
||||
- Rector\TypeDeclaration\Rector\FunctionLike\AbstractTypeDeclarationRector
|
||||
- Rector\Transform\Rector\AbstractToMethodCallRector
|
||||
- Rector\Symfony3\Rector\MethodCall\AbstractFormAddRector
|
||||
- Rector\Symfony\Rector\MethodCall\AbstractToConstructorInjectionRector
|
||||
- Rector\NetteCodeQuality\Rector\ArrayDimFetch\AbstractArrayDimFetchToAnnotatedControlVariableRector
|
||||
- Rector\DowngradePhp74\Rector\Property\AbstractDowngradeTypedPropertyRector
|
||||
- Rector\Defluent\Rector\AbstractFluentChainMethodCallRector
|
||||
- Rector\NetteKdyby\Rector\ClassMethod\AbstractKdybyEventSubscriberRector
|
||||
|
||||
-
|
||||
class: Symplify\PHPStanRules\Rules\ServiceAndValueObjectHaveSameStartsRule
|
||||
|
Loading…
x
Reference in New Issue
Block a user