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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Config\RectorConfig;
use Rector\NetteUtils\Rector\StaticCall\UtilsJsonStaticCallNamedArgRector;

// applies to any installed nette/utils version, the rules inside are bound
// to the exact version they are available from
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([UtilsJsonStaticCallNamedArgRector::class]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@
use PhpParser\Node\Identifier;
use Rector\Rector\AbstractRector;
use Rector\TypeDeclarationDocblocks\Enum\NetteClassName;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Tests\NetteUtils\Rector\StaticCall\UtilsJsonStaticCallNamedArgRector\UtilsJsonStaticCallNamedArgRectorTest
*/
final class UtilsJsonStaticCallNamedArgRector extends AbstractRector
final class UtilsJsonStaticCallNamedArgRector extends AbstractRector implements ComposerPackageConstraintInterface
{
/**
* The bool $pretty and bool $forceArrays params were added in nette/utils 4.0,
* before that both methods took int $flags
*/
public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
return new ComposerPackageConstraint('nette/utils', '>=4.0');
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change `' . Json::class . '::encode()` and `decode()` to named args', [
Expand Down
6 changes: 5 additions & 1 deletion src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ public function withComposerBased(
$setMap = [
SetGroup::TWIG => $twig,
SetGroup::DOCTRINE => $doctrine,
SetGroup::NETTE_UTILS => $netteUtils,
SetGroup::LARAVEL => $laravel,
SetGroup::DRUPAL => $drupal,
];
Expand All @@ -760,6 +759,11 @@ public function withComposerBased(
$this->sets[] = SymfonySetList::COMPOSER_BASED;
}

if ($netteUtils) {
// single set, as every rule inside is bound to the installed nette/utils version on its own
$this->sets[] = SetList::NETTE_UTILS_COMPOSER_BASED;
}

return $this;
}

Expand Down
5 changes: 0 additions & 5 deletions src/Set/Enum/SetGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ final class SetGroup
*/
public const string SYMFONY = 'symfony';

/**
* Version-based set provider
*/
public const string NETTE_UTILS = 'nette-utils';

/**
* Version-based set provider
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Set/SetProvider/CoreSetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Rector\Set\Contract\SetInterface;
use Rector\Set\Contract\SetProviderInterface;
use Rector\Set\Enum\SetGroup;
use Rector\Set\ValueObject\ComposerTriggeredSet;
use Rector\Set\ValueObject\Set;

final class CoreSetProvider implements SetProviderInterface
Expand All @@ -28,13 +27,6 @@ public function provide(): array
new Set(SetGroup::CORE, 'Naming', __DIR__ . '/../../../config/set/naming.php'),
new Set(SetGroup::CORE, 'Privatization', __DIR__ . '/../../../config/set/privatization.php'),
new Set(SetGroup::CORE, 'Type Declarations', __DIR__ . '/../../../config/set/type-declaration.php'),

new ComposerTriggeredSet(
SetGroup::NETTE_UTILS,
'nette/utils',
'4.0',
__DIR__ . '/../../../config/set/nette-utils/nette-utils4.php',
),
];
}
}
6 changes: 6 additions & 0 deletions src/Set/ValueObject/SetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ final class SetList

public const string NAMED_ARGS = __DIR__ . '/../../../config/set/named-args.php';

/**
* Applies to any installed nette/utils version, the rules inside are bound
* to the exact version they are available from
*/
public const string NETTE_UTILS_COMPOSER_BASED = __DIR__ . '/../../../config/set/nette-utils/composer-based.php';

/**
* Opinionated rules that match rector coding standard
*/
Expand Down
Loading