Updated Rector to commit 2a328edef4bb5056da7ffe2b244a4e1f796ffd16

2a328edef4 [automated] Re-Generate Nodes/Rectors Documentation (#6196)
This commit is contained in:
Tomas Votruba 2024-07-28 00:32:59 +00:00
parent 608879e768
commit f2a8c55503
8 changed files with 46 additions and 190 deletions

View File

@ -1,4 +1,4 @@
# 381 Rules Overview
# 382 Rules Overview
<br>
@ -60,7 +60,7 @@
- [Transform](#transform) (25)
- [TypeDeclaration](#typedeclaration) (56)
- [TypeDeclaration](#typedeclaration) (57)
- [Visibility](#visibility) (3)
@ -7510,6 +7510,29 @@ Add typed property from assigned types
<br>
### TypedPropertyFromCreateMockAssignRector
Add typed property from assigned mock
- class: [`Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector`](../rules/TypeDeclaration/Rector/Class_/TypedPropertyFromCreateMockAssignRector.php)
```diff
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
- private $someProperty;
+ private \PHPUnit\Framework\MockObject\MockObject $someProperty;
protected function setUp(): void
{
$this->someProperty = $this->createMock(SomeMockedClass::class);
}
}
```
<br>
### TypedPropertyFromJMSSerializerAttributeTypeRector
Add typed property from JMS Serializer Type attribute

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '7d6b6ed95f9c6c4731a0915f9624ec342548de65';
public const PACKAGE_VERSION = '2a328edef4bb5056da7ffe2b244a4e1f796ffd16';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-07-27 09:36:17';
public const RELEASE_DATE = '2024-07-28 00:30:30';
/**
* @var int
*/

View File

@ -1875,12 +1875,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "bff1daf9ef9fa9d0917607d2ad09a7cabd1ccb27"
"reference": "b28442b85cbfa059b98d08dddecd90c4ca80fd6f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/bff1daf9ef9fa9d0917607d2ad09a7cabd1ccb27",
"reference": "bff1daf9ef9fa9d0917607d2ad09a7cabd1ccb27",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/b28442b85cbfa059b98d08dddecd90c4ca80fd6f",
"reference": "b28442b85cbfa059b98d08dddecd90c4ca80fd6f",
"shasum": ""
},
"require": {
@ -1909,7 +1909,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-07-08T19:49:00+00:00",
"time": "2024-07-27T10:49:51+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -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/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 3ba7adb'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main c053b97'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 887a20a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main bff1daf'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 3ba7adb'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main c053b97'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 887a20a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main b28442b'));
private function __construct()
{
}

View File

@ -7,8 +7,7 @@ use Rector\Config\RectorConfig;
use Rector\Symfony\Configs\Rector\Closure\ServiceArgsToServiceNamedArgRector;
use Rector\Symfony\Configs\Rector\Closure\ServiceSetStringNameToClassNameRector;
use Rector\Symfony\Configs\Rector\Closure\ServiceSettersToSettersAutodiscoveryRector;
use Rector\Symfony\Configs\Rector\Closure\ServicesSetNameToSetTypeRector;
use Rector\Symfony\Configs\Rector\Closure\ServiceTagsToDefaultsAutoconfigureRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ServiceArgsToServiceNamedArgRector::class, ServiceSetStringNameToClassNameRector::class, ServiceSettersToSettersAutodiscoveryRector::class, ServicesSetNameToSetTypeRector::class, ServiceTagsToDefaultsAutoconfigureRector::class]);
$rectorConfig->rules([ServiceArgsToServiceNamedArgRector::class, ServiceSetStringNameToClassNameRector::class, ServiceSettersToSettersAutodiscoveryRector::class, ServiceTagsToDefaultsAutoconfigureRector::class]);
};

View File

@ -1,4 +1,4 @@
# 84 Rules Overview
# 83 Rules Overview
## ActionSuffixRemoverRector
@ -285,7 +285,7 @@ Add `Symfony\Component\Console\Attribute\AsCommand` to Symfony Commands and remo
{
- public static $defaultName = 'sunshine';
-
- public static $defaultDescription = 'Ssome description';
- public static $defaultDescription = 'some description';
}
```
@ -1474,9 +1474,15 @@ Replaces #[Security] framework-bundle attribute with Symfony native #[IsGranted]
class PostController extends Controller
{
- #[Security("is_granted('ROLE_ADMIN')")]
+ #[IsGranted('ROLE_ADMIN')]
public function index()
{
}
- #[Security("is_granted('ROLE_ADMIN') and is_granted('ROLE_FRIENDLY_USER')")]
+ #[IsGranted(new Expression("is_granted('ROLE_ADMIN') and is_granted('ROLE_FRIENDLY_USER')"))]
public function index()
public function list()
{
}
}
@ -1571,25 +1577,6 @@ Change `$services->set(...,` ...)->tag(...) to `$services->defaults()->autodisco
<br>
## ServicesSetNameToSetTypeRector
Change `$services->set("name_type",` SomeType::class) to bare type, useful since Symfony 3.4
- class: [`Rector\Symfony\Configs\Rector\Closure\ServicesSetNameToSetTypeRector`](../rules/Configs/Rector/Closure/ServicesSetNameToSetTypeRector.php)
```diff
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
- $services->set('some_name', App\SomeClass::class);
+ $services->set(App\SomeClass::class);
};
```
<br>
## SignalableCommandInterfaceReturnTypeRector
Return int or false from `SignalableCommandInterface::handleSignal()` instead of void

View File

@ -4,51 +4,16 @@ declare (strict_types=1);
namespace Rector\Symfony\Configs\Rector\Closure;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Rector\AbstractRector;
use Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Symfony\Tests\Configs\Rector\Closure\ServicesSetNameToSetTypeRector\ServicesSetNameToSetTypeRectorTest
* @deprecated This rule is deprecated. It does not have context about rest of application, will create invalid code.
*/
final class ServicesSetNameToSetTypeRector extends AbstractRector
final class ServicesSetNameToSetTypeRector extends AbstractRector implements DeprecatedInterface
{
/**
* @readonly
* @var \Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector
*/
private $symfonyPhpClosureDetector;
/**
* @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
/**
* @var array<string, string>
*/
private $alreadyChangedServiceNamesToTypes = [];
/**
* @var bool
*/
private $hasChanged = \false;
/**
* @var array<string, string[]>
*/
private $servicesNamesByType = [];
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector, ValueResolver $valueResolver)
{
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
$this->valueResolver = $valueResolver;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change $services->set("name_type", SomeType::class) to bare type, useful since Symfony 3.4', [new CodeSample(<<<'CODE_SAMPLE'
@ -83,124 +48,6 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
$this->hasChanged = \false;
if (!$this->symfonyPhpClosureDetector->detect($node)) {
return null;
}
$duplicatedTypeNames = $this->resolveDuplicatedTypeNames($node);
$this->handleSetServices($node, $duplicatedTypeNames);
$this->handleRefServiceFunctionReferences($node);
if ($this->hasChanged) {
return $node;
}
return null;
}
private function isSetServices(MethodCall $methodCall) : bool
{
if (!$this->isName($methodCall->name, 'set')) {
return \false;
}
return $this->isObjectType($methodCall->var, new ObjectType('Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ServicesConfigurator'));
}
/**
* @param string[] $serviceNamesToSkip
*/
private function handleSetServices(Closure $closure, array $serviceNamesToSkip) : void
{
$this->traverseNodesWithCallable($closure->stmts, function (Node $node) use($serviceNamesToSkip) : ?MethodCall {
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->isSetServices($node)) {
return null;
}
// must be exactly 2 args
if (\count($node->args) !== 2) {
return null;
}
// exchange type and service name
$args = $node->getArgs();
$firstArg = $args[0];
if (!$firstArg->value instanceof String_) {
return null;
}
// skip
if ($this->valueResolver->isValues($firstArg->value, $serviceNamesToSkip)) {
return null;
}
$secondArg = $args[1];
/** @var string $serviceName */
$serviceName = $this->valueResolver->getValue($firstArg->value);
$serviceType = $this->valueResolver->getValue($secondArg->value);
if (!\is_string($serviceType)) {
return null;
}
$this->alreadyChangedServiceNamesToTypes[$serviceName] = $serviceType;
// move 2nd arg to 1st position
$node->args = [$args[1]];
$this->hasChanged = \true;
return $node;
});
}
private function handleRefServiceFunctionReferences(Closure $closure) : void
{
$this->traverseNodesWithCallable($closure, function (Node $node) : ?Node {
if (!$node instanceof FuncCall) {
return null;
}
if (!$this->isNames($node->name, ['Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service', 'Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ref'])) {
return null;
}
$args = $node->getArgs();
if ($args === []) {
return null;
}
$firstArg = $args[0];
foreach ($this->alreadyChangedServiceNamesToTypes as $serviceName => $serviceType) {
if (!$this->valueResolver->isValue($firstArg->value, $serviceName)) {
continue;
}
// replace string value with type
$classConstFetch = new ClassConstFetch(new FullyQualified($serviceType), 'class');
$node->args = [new Arg($classConstFetch)];
$this->hasChanged = \true;
}
return $node;
});
}
/**
* @return string[]
*/
private function resolveDuplicatedTypeNames(Closure $closure) : array
{
$this->servicesNamesByType = [];
$this->traverseNodesWithCallable($closure, function (Node $node) {
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->isSetServices($node)) {
return null;
}
$args = $node->getArgs();
if (\count($args) !== 2) {
return null;
}
$firstArg = $args[0];
$secondArg = $args[1];
$serviceName = $this->valueResolver->getValue($firstArg->value);
$serviceType = $this->valueResolver->getValue($secondArg->value);
if (!\is_string($serviceType)) {
return null;
}
$this->servicesNamesByType[$serviceType][] = $serviceName;
});
$duplicatedTypeNames = [];
foreach ($this->servicesNamesByType as $servicesNames) {
if (\count($servicesNames) <= 1) {
continue;
}
$duplicatedTypeNames = \array_merge($duplicatedTypeNames, $servicesNames);
}
return $duplicatedTypeNames;
}
}