mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-04 02:10:51 +00:00
Updated Rector to commit 44ebacea719f64590b4644081e862437be7ce466
44ebacea71
[Php80] Do not remove Parameter attribute on ClassPropertyAssignToConstructorPromotionRector (#3179)
This commit is contained in:
parent
7d6c5d58c3
commit
c4151416ec
|
@ -24,7 +24,6 @@ use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
|
|||
use Rector\Naming\VariableRenamer;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php80\Guard\MakePropertyPromotionGuard;
|
||||
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
|
||||
use Rector\Php80\NodeAnalyzer\PromotedPropertyCandidateResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
|
@ -82,12 +81,7 @@ final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRect
|
|||
* @var \Rector\Php80\Guard\MakePropertyPromotionGuard
|
||||
*/
|
||||
private $makePropertyPromotionGuard;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
|
||||
*/
|
||||
private $phpAttributeAnalyzer;
|
||||
public function __construct(PromotedPropertyCandidateResolver $promotedPropertyCandidateResolver, VariableRenamer $variableRenamer, VarTagRemover $varTagRemover, ParamAnalyzer $paramAnalyzer, PhpDocTypeChanger $phpDocTypeChanger, MakePropertyPromotionGuard $makePropertyPromotionGuard, PhpAttributeAnalyzer $phpAttributeAnalyzer)
|
||||
public function __construct(PromotedPropertyCandidateResolver $promotedPropertyCandidateResolver, VariableRenamer $variableRenamer, VarTagRemover $varTagRemover, ParamAnalyzer $paramAnalyzer, PhpDocTypeChanger $phpDocTypeChanger, MakePropertyPromotionGuard $makePropertyPromotionGuard)
|
||||
{
|
||||
$this->promotedPropertyCandidateResolver = $promotedPropertyCandidateResolver;
|
||||
$this->variableRenamer = $variableRenamer;
|
||||
|
@ -95,7 +89,6 @@ final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRect
|
|||
$this->paramAnalyzer = $paramAnalyzer;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->makePropertyPromotionGuard = $makePropertyPromotionGuard;
|
||||
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
|
@ -175,7 +168,7 @@ CODE_SAMPLE
|
|||
$param->var->name = $this->getName($property);
|
||||
$param->flags = $property->flags;
|
||||
// Copy over attributes of the "old" property
|
||||
$param->attrGroups = $property->attrGroups;
|
||||
$param->attrGroups = \array_merge($param->attrGroups, $property->attrGroups);
|
||||
$this->processNullableType($property, $param);
|
||||
$this->phpDocTypeChanger->copyPropertyDocToParam($property, $param);
|
||||
}
|
||||
|
@ -216,9 +209,6 @@ CODE_SAMPLE
|
|||
if ($param->variadic) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->phpAttributeAnalyzer->hasPhpAttribute($param, 'SensitiveParameter')) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->paramAnalyzer->isNullable($param)) {
|
||||
/** @var NullableType $type */
|
||||
$type = $param->type;
|
||||
|
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'b23e1fb2ea7795a7f7bb3f6232e4fa82aa26b199';
|
||||
public const PACKAGE_VERSION = '44ebacea719f64590b4644081e862437be7ce466';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-12-09 22:42:31';
|
||||
public const RELEASE_DATE = '2022-12-10 12:53:20';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit2ca65cd9e34c9d001ac2ef47410a5c4f::getLoader();
|
||||
return ComposerAutoloaderInit9d692db4d0c49ad7d38b4ed0f996ba58::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2010,6 +2010,7 @@ return array(
|
|||
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\AddDoesNotPerformAssertionToNonAssertingTestRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\CreateMockToAnonymousClassRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\DependsAnnotationWithValueToAttributeRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\ExceptionAnnotationRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/ExceptionAnnotationRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit2ca65cd9e34c9d001ac2ef47410a5c4f
|
||||
class ComposerAutoloaderInit9d692db4d0c49ad7d38b4ed0f996ba58
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit2ca65cd9e34c9d001ac2ef47410a5c4f
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit2ca65cd9e34c9d001ac2ef47410a5c4f', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit9d692db4d0c49ad7d38b4ed0f996ba58', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit2ca65cd9e34c9d001ac2ef47410a5c4f', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit9d692db4d0c49ad7d38b4ed0f996ba58', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit9d692db4d0c49ad7d38b4ed0f996ba58::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit9d692db4d0c49ad7d38b4ed0f996ba58::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire2ca65cd9e34c9d001ac2ef47410a5c4f($fileIdentifier, $file);
|
||||
composerRequire9d692db4d0c49ad7d38b4ed0f996ba58($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit2ca65cd9e34c9d001ac2ef47410a5c4f
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire2ca65cd9e34c9d001ac2ef47410a5c4f($fileIdentifier, $file)
|
||||
function composerRequire9d692db4d0c49ad7d38b4ed0f996ba58($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f
|
||||
class ComposerStaticInit9d692db4d0c49ad7d38b4ed0f996ba58
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2250,6 +2250,7 @@ class ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f
|
|||
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\AddDoesNotPerformAssertionToNonAssertingTestRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\CreateMockToAnonymousClassRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\DependsAnnotationWithValueToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\ExceptionAnnotationRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/ExceptionAnnotationRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
|
||||
'Rector\\PHPUnit\\Rector\\ClassMethod\\ReplaceTestAnnotationWithPrefixedFunctionRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/ReplaceTestAnnotationWithPrefixedFunctionRector.php',
|
||||
|
@ -3025,9 +3026,9 @@ class ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit2ca65cd9e34c9d001ac2ef47410a5c4f::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit9d692db4d0c49ad7d38b4ed0f996ba58::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit9d692db4d0c49ad7d38b4ed0f996ba58::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit9d692db4d0c49ad7d38b4ed0f996ba58::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -1989,12 +1989,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
|
||||
"reference": "7ea9a12bb2ea605e6793fd0e12d82fea47ae4589"
|
||||
"reference": "dda0db8f8856afb1eb1302a96dc18292b9749e9b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/7ea9a12bb2ea605e6793fd0e12d82fea47ae4589",
|
||||
"reference": "7ea9a12bb2ea605e6793fd0e12d82fea47ae4589",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/dda0db8f8856afb1eb1302a96dc18292b9749e9b",
|
||||
"reference": "dda0db8f8856afb1eb1302a96dc18292b9749e9b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2020,7 +2020,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-12-08T21:25:49+00:00",
|
||||
"time": "2022-12-10T11:34:10+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6163431'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7ea9a12'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f77e493'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6163431'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main dda0db8'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f77e493'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -8,9 +8,21 @@ use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
|
|||
use Rector\Php80\ValueObject\AnnotationToAttribute;
|
||||
use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector;
|
||||
use Rector\PHPUnit\Rector\Class_\CoversAnnotationWithValueToAttributeRector;
|
||||
use Rector\PHPUnit\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector;
|
||||
use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([CoversAnnotationWithValueToAttributeRector::class]);
|
||||
$rectorConfig->rules([
|
||||
CoversAnnotationWithValueToAttributeRector::class,
|
||||
/**
|
||||
* Currently handle:
|
||||
* - @depends Methodname
|
||||
*
|
||||
* Todo:
|
||||
* - @depends Class::MethodName
|
||||
* - @depends clone, !clone, shallowClone, !shallowClone
|
||||
*/
|
||||
DependsAnnotationWithValueToAttributeRector::class,
|
||||
]);
|
||||
$rectorConfig->ruleWithConfiguration(AnnotationWithValueToAttributeRector::class, [new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\\Framework\\Attributes\\BackupGlobals', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('backupStaticAttributes', 'PHPUnit\\Framework\\Attributes\\BackupStaticProperties', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('preserveGlobalState', 'PHPUnit\\Framework\\Attributes\\PreserveGlobalState', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('dataProvider', 'PHPUnit\\Framework\\Attributes\\DataProvider'), new AnnotationWithValueToAttribute('depends', 'PHPUnit\\Framework\\Attributes\\Depends'), new AnnotationWithValueToAttribute('group', 'PHPUnit\\Framework\\Attributes\\Group'), new AnnotationWithValueToAttribute('ticket', 'PHPUnit\\Framework\\Attributes\\Ticket'), new AnnotationWithValueToAttribute('uses', 'PHPUnit\\Framework\\Attributes\\UsesClass'), new AnnotationWithValueToAttribute('testWith', 'PHPUnit\\Framework\\Attributes\\TestWith'), new AnnotationWithValueToAttribute('testDox', 'PHPUnit\\Framework\\Attributes\\TestDox')]);
|
||||
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
|
||||
// @see https://github.com/sebastianbergmann/phpunit/issues/4502
|
||||
|
|
126
vendor/rector/rector-phpunit/src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php
vendored
Normal file
126
vendor/rector/rector-phpunit/src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php
vendored
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PHPUnit\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
|
||||
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\PHPUnit\Tests\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector\DependsAnnotationWithValueToAttributeRectorTest
|
||||
*/
|
||||
final class DependsAnnotationWithValueToAttributeRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
|
||||
*/
|
||||
private $testsNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory
|
||||
*/
|
||||
private $phpAttributeGroupFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover
|
||||
*/
|
||||
private $phpDocTagRemover;
|
||||
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpDocTagRemover $phpDocTagRemover)
|
||||
{
|
||||
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
|
||||
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
|
||||
$this->phpDocTagRemover = $phpDocTagRemover;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change depends annotations with value to attribute', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SomeTest extends TestCase
|
||||
{
|
||||
public function testOne() {}
|
||||
public function testTwo() {}
|
||||
/**
|
||||
* @depends testOne
|
||||
* @depends testTwo
|
||||
*/
|
||||
public function testThree(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SomeTest extends TestCase
|
||||
{
|
||||
public function testOne() {}
|
||||
public function testTwo() {}
|
||||
#[\PHPUnit\Framework\Attributes\Depends('testOne')]
|
||||
#[\PHPUnit\Framework\Attributes\Depends('testTwo')]
|
||||
public function testThree(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
|
||||
return null;
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
|
||||
if (!$phpDocInfo instanceof PhpDocInfo) {
|
||||
return null;
|
||||
}
|
||||
/** @var PhpDocTagNode[] $desiredTagValueNodes */
|
||||
$desiredTagValueNodes = $phpDocInfo->getTagsByName('depends');
|
||||
if ($desiredTagValueNodes === []) {
|
||||
return null;
|
||||
}
|
||||
$currentClass = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$currentClass instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
|
||||
if (!$desiredTagValueNode->value instanceof GenericTagValueNode) {
|
||||
continue;
|
||||
}
|
||||
$attributeValue = $desiredTagValueNode->value->value;
|
||||
$classMethod = $currentClass->getMethod($attributeValue);
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
continue;
|
||||
}
|
||||
$attributeGroup = $this->phpAttributeGroupFactory->createFromClassWithItems('PHPUnit\\Framework\\Attributes\\Depends', [$attributeValue]);
|
||||
$node->attrGroups[] = $attributeGroup;
|
||||
// cleanup
|
||||
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
|
||||
}
|
||||
if (!$phpDocInfo->hasChanged()) {
|
||||
return null;
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user