Skip to content

Commit

Permalink
[DowngradeSymfony70] Add DowngradeSymfonyCommandAttributeRector (#558)
Browse files Browse the repository at this point in the history
* [DowngradeSymfony70] Add DowngradeSymfonyCommandAttributeRector

* description

* adding test

* add @see test

* move to subdir

* skip code-a

* skip set in configure

* fix

* fix

* fix

* fix
  • Loading branch information
samsonasik authored Jan 15, 2024
1 parent c9d78b3 commit 364641c
Show file tree
Hide file tree
Showing 22 changed files with 323 additions and 14 deletions.
1 change: 0 additions & 1 deletion config/sets/symfony/configs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 {
Expand Down
1 change: 0 additions & 1 deletion config/sets/symfony/symfony31.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;

use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
use Rector\Config\RectorConfig;

Expand Down
1 change: 0 additions & 1 deletion config/sets/symfony/symfony33.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;

use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
Expand Down
1 change: 0 additions & 1 deletion config/sets/symfony/symfony42.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use PHPStan\Type\IterableType;

use PHPStan\Type\MixedType;
use Rector\Arguments\NodeAnalyzer\ArgumentAddingScope;
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
Expand Down
1 change: 0 additions & 1 deletion config/sets/symfony/symfony51.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use PHPStan\Type\ObjectType;

# https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.1.md
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ parameters:
- '#Cognitive complexity for "Rector\\Symfony\\CodeQuality\\Rector\\Closure\\StringExtensionToConfigBuilderRector\:\:create(.*?)\(\)" is 13, keep it under 10#'

- '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'

-
message: '#Cognitive complexity for "Rector\\Symfony\\DowngradeSymfony70\\Rector\\Class_\\DowngradeSymfonyCommandAttributeRector\:\:(resolveNameAndDescription|refactor)\(\)" is 13|15, keep it under 10#'
path: rules/DowngradeSymfony70/Rector/Class_/DowngradeSymfonyCommandAttributeRector.php

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Symfony\CodeQuality\Rector\MethodCall\AssertSameResponseCodeWithDebugContentsRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Symfony\Bridge\Symfony\Routing\SymfonyRoutesProvider;
use Rector\Symfony\Configs\Rector\ClassMethod\AddRouteAnnotationRector;
use Rector\Symfony\Contract\Bridge\Symfony\Routing\SymfonyRoutesProviderInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class DowngradeSymfonyCommandAttributeRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

class SkipNotExtendsCommand
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Command\Command;

class SkipSetInConfigure extends Command
{
protected function configure(): void
{
$this->setName('app:create-user');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

#[AsCommand(name: 'app:create-user')]
class WithExistingConfigureMethod extends Command
{
protected function configure()
{
echo 'test';
}
}

?>
-----
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

class WithExistingConfigureMethod extends Command
{
protected function configure()
{
echo 'test';
$this->setName('app:create-user');
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

#[AsCommand(name: 'app:create-user')]
class WithName extends Command
{
}

?>
-----
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

class WithName extends Command
{
protected function configure()
{
$this->setName('app:create-user');
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

#[AsCommand(name: 'app:create-user', description: 'some description')]
class WithNameAndDescription extends Command
{
}

?>
-----
<?php

namespace Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\Fixture;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

class WithNameAndDescription extends Command
{
protected function configure()
{
$this->setName('app:create-user');
$this->setDescription('some description');
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(DowngradeSymfonyCommandAttributeRector::class);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;

use Rector\Symfony\Symfony43\Rector\StmtsAwareInterface\TwigBundleFilesystemLoaderToTwigRector;

return static function (RectorConfig $rectorConfig): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
declare(strict_types=1);

use PhpParser\Node\Scalar\String_;

use Psr\Container\ContainerInterface;

use Rector\Config\RectorConfig;
use Rector\Symfony\Symfony60\Rector\FuncCall\ReplaceServiceArgumentRector;
use Rector\Symfony\ValueObject\ReplaceServiceArgument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ServicesSetNameToSetTypeRector extends AbstractRector
*/
private array $alreadyChangedServiceNamesToTypes = [];

private bool $hasChanged = false;
private bool $hasChanged = false;

/**
* @var array<string, string[]>
Expand Down
Loading

0 comments on commit 364641c

Please sign in to comment.