小编Chl*_*lem的帖子

配置 Rector 并使用 symfony 6/php8 的简单规则

我想使用 Rector 重构我的代码,因为我将项目更新为 symfony 5.4 到 6.1。我的php项目版本:8.1.5

所以,我想使用一个简单的规则,将我的注释更改为带有 ector 的属性。但是当我使用命令执行ector时:vendor/bin/rector process src

校长通知我:[OK]校长完成了!

但我的文件没有改变,我的实体注释也没有改变。我尝试按照此文档来配置我的rector.php并将rector与symfony一起使用。

https://github.com/rectorphp/rector-symfony

https://github.com/rectorphp/rector

我做错了什么?

这是我的rector.php

<?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,
        ]);*/
};

Run Code Online (Sandbox Code Playgroud)

这是我的composer.json


{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "dev",
    "prefer-stable": …
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony rector

5
推荐指数
2
解决办法
6191
查看次数

参数必须是 ?array 类型,给定字符串,在 Doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php Annotations/DocParser.php 中调用

我不明白 API 平台上的错误。

\n

Doctrine\\ORM\\Mapping\\ManyToOne::__construct():参数 #2 ($cascade) 必须是 ?array 类型,给定字符串,在 /Users/charleslem/symfony/API-plateform-php-8/ 中调用Api-plateform-php8-symfony5/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php 第 944 行。

\n

什么说法错误讲。我没有指示。

\n

我的代码:

\n

第一个实体:

\n
\nnamespace App\\Entity;\n\nuse ApiPlatform\\Core\\Annotation\\ApiResource;\nuse App\\Repository\\PostRepository;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Symfony\\Component\\Serializer\\Annotation\\Groups;\nuse Symfony\\Component\\Validator\\Constraints\\Length;\n\n//read:collection pour lire une collection d'article\n//read:item correspond \xc3\xa0 la lecture d'un seul item\n/*ici je souhaite afficher les attributs title et slug quand je demande une collection d'article mais afficher \n    mais afficher en plus le contennu ainsi que la date quand je fais une requete d'un seul article\n*/\n\n/**\n * @ORM\\Entity(repositoryClass=PostRepository::class)\n …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm api-platform.com

0
推荐指数
1
解决办法
6227
查看次数

标签 统计

symfony ×2

api-platform.com ×1

doctrine ×1

doctrine-orm ×1

php ×1

rector ×1