我想使用Rector来重构我的代码,因为我将我的项目更新到symfony 5.4到6.1.我的php项目版本:8.1.5
所以,我想使用一个简单的规则,将我的注解更改为attribut with rector.但当我执行rector with command时:供应商/bin/rector流程源
校长通知我:[OK]校长已完成!
但是我的文件没有改变,我的实体注解也没有改变。我试着按照这个文档来配置我的rector.php,并在symfony中使用rector。
https://github.com/rectorphp/rector-symfony
https://github.com/rectorphp/rector
我做错了什么?
这是我的博客
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Symfony\Rector\MethodCall\StringFormTypeToClassRector;
use Rector\Symfony\Rector\Class_\CommandPropertyToAttributeRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src'
]);
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon');
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
$rectorConfig->ruleWithConfiguration(
AnnotationToAttributeRector::class,
[new AnnotationToAttribute('Symfony\Routing\Annotation\Route')]
);
// register a single rule
//$rectorConfig->rule(CommandPropertyToAttributeRector::class);
// define sets of rules
/* $rectorConfig->sets([
SymfonySetList::SYMFONY_60,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
]);*/
};
这是我的composer.json
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/annotations": "^1.12",
"doctrine/dbal": "^2.0",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.8",
"fakerphp/faker": "^1.19",
"gedmo/doctrine-extensions": "^3.8",
"giggsey/libphonenumber-for-php": "^8.12",
"knplabs/knp-paginator-bundle": "^5.3",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^6.2",
"symfony/asset": "6.1.*",
"symfony/console": "6.1.*",
"symfony/doctrine-bridge": "6.1.*",
"symfony/dotenv": "6.1.*",
"symfony/expression-language": "6.1.*",
"symfony/flex": "^1.3.1",
"symfony/form": "6.1.*",
"symfony/framework-bundle": "6.1.*",
"symfony/http-client": "6.1.*",
"symfony/http-foundation": "6.1.*",
"symfony/intl": "6.1.*",
"symfony/mailer": "6.1.*",
"symfony/mime": "6.1.*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "6.1.*",
"symfony/options-resolver": "6.1.*",
"symfony/process": "6.1.*",
"symfony/property-access": "6.1.*",
"symfony/property-info": "5.4.*",
"symfony/proxy-manager-bridge": "6.1.*",
"symfony/rate-limiter": "6.1.*",
"symfony/runtime": "6.1.*",
"symfony/security-bundle": "6.1.*",
"symfony/serializer": "6.1.*",
"symfony/string": "6.1.*",
"symfony/translation": "6.1.*",
"symfony/twig-bundle": "6.1.*",
"symfony/validator": "6.1.*",
"symfony/web-link": "6.1.*",
"symfony/webpack-encore-bundle": "^1.14",
"symfony/yaml": "6.0.*",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
},
"require-dev": {
"fakerphp/faker": "^1.19",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-doctrine": "^1.3",
"rector/rector": "^0.13.9",
"symfony/browser-kit": "6.1.*",
"symfony/css-selector": "6.1.*",
"symfony/debug-bundle": "6.1.*",
"symfony/maker-bundle": "^1.30",
"symfony/phpunit-bridge": "6.1.*",
"symfony/stopwatch": "6.1.*",
"symfony/var-dumper": "6.1.*",
"symfony/web-profiler-bundle": "6.1.*"
},
谢谢你的帮助!
3条答案
按热度按时间ma8fv8wu1#
因此,这里的问题是composer.json中的php版本
我们只需要改变php版本7到8
将“php”:“〉=7.2.5”修改为“php”:“^8.0”
再见
j7dteeu82#
我不知道确切的原因,但对我来说,解决方案是删除路径配置:
并且只使用路径作为二进制调用的参数:
php vendor/bin/rector process <PATH>
4dc9hkyq3#
它对我很有效: