Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ final class Option
*/
public const string DEPRECATED_PHP_SETS_METHODS = 'deprecated_php_sets_methods';

/**
* @internal For reporting deprecated withAttributesSets() arguments
*/
public const string DEPRECATED_ATTRIBUTES_SETS_ARGS = 'deprecated_attributes_sets_args';

/**
* @internal For collect skipped start with short open tag files to be reported
*/
Expand Down
25 changes: 6 additions & 19 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use Rector\Enum\Config\Defaults;
use Rector\Exception\Configuration\InvalidConfigurationException;
use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\Contract\SetProviderInterface;
use Rector\Set\Enum\SetGroup;
Expand Down Expand Up @@ -462,6 +460,9 @@ public function withSets(array $sets): self

/**
* Upgrade your annotations to attributes
*
* @param bool $symfonyRoute Deprecated, included in $symfony
* @param bool $symfonyValidator Deprecated, included in $symfony
*/
public function withAttributesSets(
bool $symfony = false,
Expand All @@ -486,27 +487,13 @@ public function withAttributesSets(
$this->sets[] = SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES;
}

// dx for more granular upgrade
// both are part of $symfony set, no longer applied on their own
if ($symfonyRoute) {
if ($symfony) {
throw new InvalidConfigurationException(
'$symfonyRoute is already included in $symfony. Use $symfony only'
);
}

$this->withConfiguredRule(AnnotationToAttributeRector::class, [
new AnnotationToAttribute('Symfony\Component\Routing\Annotation\Route'),
]);
SimpleParameterProvider::addParameter(Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, 'symfonyRoute');
}

if ($symfonyValidator) {
if ($symfony) {
throw new InvalidConfigurationException(
'$symfonyValidator is already included in $symfony. Use $symfony only'
);
}

$this->sets[] = SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES;
SimpleParameterProvider::addParameter(Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, 'symfonyValidator');
}

if ($doctrine || $all) {
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods();
$this->deprecatedRulesReporter->reportDeprecatedCacheMetaExtensions();
$this->deprecatedRulesReporter->reportDeprecatedPhpSetsMethods();
$this->deprecatedRulesReporter->reportDeprecatedAttributesSetsArgs();

$this->missConfigurationReporter->reportSkippedNeverRegisteredRules();
$this->missConfigurationReporter->reportUnusedSkips($processResult);
Expand Down
15 changes: 15 additions & 0 deletions src/Reporting/DeprecatedRulesReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ public function reportDeprecatedPhpSetsMethods(): void
}
}

public function reportDeprecatedAttributesSetsArgs(): void
{
/** @var string[] $deprecatedAttributesSetsArgs */
$deprecatedAttributesSetsArgs = SimpleParameterProvider::provideArrayParameter(
Option::DEPRECATED_ATTRIBUTES_SETS_ARGS
);

foreach (array_unique($deprecatedAttributesSetsArgs) as $deprecatedAttributesSetsArg) {
$this->symfonyStyle->warning(sprintf(
'The "->withAttributesSets(%s: true)" argument is deprecated and no longer applied. It is already included in the "symfony: true" argument, use it instead.',
$deprecatedAttributesSetsArg
));
}
}

public function reportDeprecatedRectorUnsupportedMethods(): void
{
// to be added in related PR
Expand Down
12 changes: 3 additions & 9 deletions tests/Config/RectorConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@

namespace Rector\Tests\Config;

use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Symfony\Set\TwigSetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector;

/**
* On macOS, this file order config cause this container read other tests' config.
* so, this #[RunTestsInSeparateProcesses] is needed.
*/
#[RunTestsInSeparateProcesses]
final class RectorConfigTest extends AbstractLazyTestCase
{
public function test(): void
{
$rectorConfig = $this->getContainer();

$rectorConfig->configure()
->withSets([TwigSetList::TWIG_134])
->withRules([ReturnTypeFromReturnNewRector::class])($rectorConfig);
->withSets([SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION])
->withRules([ReturnTypeFromReturnNewRector::class]);

// only collect root withRules()
$this->assertCount(1, SimpleParameterProvider::provideArrayParameter(Option::ROOT_STANDALONE_REGISTERED_RULES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Rector\Configuration\RenamedClassesDataCollector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;

#[RunTestsInSeparateProcesses]
final class ConfigurableRectorImportConfigCallsMergeTest extends AbstractLazyTestCase
{
/**
Expand Down
Loading