Skip to content

Commit 90a29cb

Browse files
committed
[dx] load composer-based sets from laravel and drupal
1 parent 6af747a commit 90a29cb

3 files changed

Lines changed: 11 additions & 29 deletions

File tree

‎composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"webmozart/assert": "^2.4"
4242
},
4343
"require-dev": {
44+
"driftingly/rector-laravel": "^2.6",
4445
"nette/robot-loader": "^4.1",
45-
"symfony/process": "^8.1",
4646
"php-parallel-lint/php-parallel-lint": "^1.4",
4747
"phpstan/extension-installer": "^1.4",
4848
"phpstan/phpstan-deprecation-rules": "^2.0",
@@ -52,6 +52,7 @@
5252
"rector/jack": "^1.1",
5353
"rector/swiss-knife": "^2.4.1",
5454
"shipmonk/composer-dependency-analyser": "^1.8",
55+
"symfony/process": "^8.1",
5556
"symplify/easy-coding-standard": "^13.2.13",
5657
"symplify/phpstan-rules": "^14.13",
5758
"tomasvotruba/class-leak": "^2.1",

‎src/Configuration/RectorConfigBuilder.php‎

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Rector\Symfony\Set\TwigSetList;
3333
use Rector\ValueObject\Configuration\LevelOverflow;
3434
use Rector\ValueObject\PhpVersion;
35+
use RectorLaravel\Set\LaravelSetList;
3536
use Symfony\Component\Finder\Finder;
3637
use Webmozart\Assert\Assert;
3738

@@ -56,17 +57,6 @@ final class RectorConfigBuilder
5657
'withCodingStyleLevel' => [SetList::CODING_STYLE, 'coding style'],
5758
];
5859

59-
/**
60-
* The composer-based set of the extensions that rector-src does not require, so their set list class cannot be
61-
* imported here. Resolved at run-time; an extension that ships no such set falls back to its set group.
62-
*
63-
* @var array<SetGroup::*, string>
64-
*/
65-
private const array EXTENSION_COMPOSER_BASED_SET_LISTS = [
66-
SetGroup::LARAVEL => 'RectorLaravel\\Set\\LaravelSetList::COMPOSER_BASED',
67-
SetGroup::DRUPAL => 'DrupalRector\\Set\\DrupalSetList::COMPOSER_BASED',
68-
];
69-
7060
/**
7161
* @var string[]
7262
*/
@@ -693,24 +683,13 @@ public function withComposerBased(
693683
bool $laravel = false,
694684
bool $drupal = false,
695685
): self {
696-
$setMap = [
697-
SetGroup::LARAVEL => $laravel,
698-
SetGroup::DRUPAL => $drupal,
699-
];
700-
701-
foreach ($setMap as $setGroup => $isEnabled) {
702-
if (! $isEnabled) {
703-
continue;
704-
}
705-
706-
$setListConstant = self::EXTENSION_COMPOSER_BASED_SET_LISTS[$setGroup];
707-
if (defined($setListConstant)) {
708-
$setFilePath = constant($setListConstant);
709-
Assert::string($setFilePath);
686+
if ($laravel) {
687+
$this->sets[] = LaravelSetList::COMPOSER_BASED;
688+
}
710689

711-
// single set, as every rule inside is bound to the installed package version on its own
712-
$this->sets[] = $setFilePath;
713-
}
690+
if ($drupal && class_exists('DrupalRector\Set\DrupalSetList')) {
691+
// waits on https://github.com/palantirnet/drupal-rector/pull/419/files#diff-c6bd4ee854830efc1363a7d99c1b6a2e7e64f2499a51e503174ab777de7e64e5
692+
$this->sets[] = DrupalSetList::COMPOSER_BASED;
714693
}
715694

716695
if ($phpunit) {

‎src/Set/Enum/SetGroup.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ final class SetGroup
1414
public const string PHP = 'php';
1515

1616
/**
17+
* @deprecated Use composer-based.php set instead
1718
* Version-based set provider
1819
*/
1920
public const string LARAVEL = 'laravel';
2021

2122
/**
23+
* @deprecated Use composer-based.php set instead
2224
* Version-based set provider
2325
*/
2426
public const string DRUPAL = 'drupal';

0 commit comments

Comments
 (0)