|
8 | 8 | use Rector\Bridge\SetProviderCollector; |
9 | 9 | use Rector\Bridge\SetRectorsResolver; |
10 | 10 | use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; |
| 11 | +use Rector\Composer\InstalledPackageResolver; |
11 | 12 | use Rector\Config\Level\CodeQualityLevel; |
12 | 13 | use Rector\Config\Level\DeadCodeLevel; |
13 | 14 | use Rector\Config\Level\TypeDeclarationLevel; |
@@ -165,11 +166,8 @@ final class RectorConfigBuilder |
165 | 166 |
|
166 | 167 | public function __invoke(RectorConfig $rectorConfig): void |
167 | 168 | { |
168 | | - // @experimental 2024-06 |
169 | 169 | if ($this->setGroups !== []) { |
170 | | - $setProviderCollector = $rectorConfig->make(SetProviderCollector::class); |
171 | | - $setManager = new SetManager($setProviderCollector); |
172 | | - |
| 170 | + $setManager = new SetManager(new SetProviderCollector(), new InstalledPackageResolver(getcwd())); |
173 | 171 | $this->groupLoadedSets = $setManager->matchBySetGroups($this->setGroups); |
174 | 172 | } |
175 | 173 |
|
@@ -704,79 +702,48 @@ public function withPreparedSets( |
704 | 702 | bool $doctrineCodeQuality = false, |
705 | 703 | bool $symfonyCodeQuality = false, |
706 | 704 | bool $symfonyConfigs = false, |
707 | | - // composer based |
708 | | - bool $twig = false, |
709 | | - bool $phpunit = false, |
710 | 705 | ): self { |
711 | 706 | Notifier::notifyNotSuitableMethodForPHP74(__METHOD__); |
712 | 707 |
|
713 | | - if ($deadCode) { |
714 | | - $this->sets[] = SetList::DEAD_CODE; |
715 | | - } |
716 | | - |
717 | | - if ($codeQuality) { |
718 | | - $this->sets[] = SetList::CODE_QUALITY; |
719 | | - } |
720 | | - |
721 | | - if ($codingStyle) { |
722 | | - $this->sets[] = SetList::CODING_STYLE; |
723 | | - } |
724 | | - |
725 | | - if ($typeDeclarations) { |
726 | | - $this->sets[] = SetList::TYPE_DECLARATION; |
727 | | - } |
728 | | - |
729 | | - if ($privatization) { |
730 | | - $this->sets[] = SetList::PRIVATIZATION; |
731 | | - } |
732 | | - |
733 | | - if ($naming) { |
734 | | - $this->sets[] = SetList::NAMING; |
735 | | - } |
736 | | - |
737 | | - if ($instanceOf) { |
738 | | - $this->sets[] = SetList::INSTANCEOF; |
739 | | - } |
740 | | - |
741 | | - if ($earlyReturn) { |
742 | | - $this->sets[] = SetList::EARLY_RETURN; |
743 | | - } |
744 | | - |
745 | | - if ($strictBooleans) { |
746 | | - $this->sets[] = SetList::STRICT_BOOLEANS; |
747 | | - } |
748 | | - |
749 | | - if ($carbon) { |
750 | | - $this->sets[] = SetList::CARBON; |
751 | | - } |
752 | | - |
753 | | - if ($rectorPreset) { |
754 | | - $this->sets[] = SetList::RECTOR_PRESET; |
755 | | - } |
756 | | - |
757 | | - if ($phpunitCodeQuality) { |
758 | | - $this->sets[] = PHPUnitSetList::PHPUNIT_CODE_QUALITY; |
759 | | - } |
760 | | - |
761 | | - if ($doctrineCodeQuality) { |
762 | | - $this->sets[] = DoctrineSetList::DOCTRINE_CODE_QUALITY; |
763 | | - } |
764 | | - |
765 | | - if ($symfonyCodeQuality) { |
766 | | - $this->sets[] = SymfonySetList::SYMFONY_CODE_QUALITY; |
767 | | - } |
768 | | - |
769 | | - if ($symfonyConfigs) { |
770 | | - $this->sets[] = SymfonySetList::CONFIGS; |
| 708 | + $setMap = [ |
| 709 | + $deadCode => SetList::DEAD_CODE, |
| 710 | + $codeQuality => SetList::CODE_QUALITY, |
| 711 | + $codingStyle => SetList::CODING_STYLE, |
| 712 | + $typeDeclarations => SetList::TYPE_DECLARATION, |
| 713 | + $privatization => SetList::PRIVATIZATION, |
| 714 | + $naming => SetList::NAMING, |
| 715 | + $instanceOf => SetList::INSTANCEOF, |
| 716 | + $earlyReturn => SetList::EARLY_RETURN, |
| 717 | + $strictBooleans => SetList::STRICT_BOOLEANS, |
| 718 | + $carbon => SetList::CARBON, |
| 719 | + $rectorPreset => SetList::RECTOR_PRESET, |
| 720 | + $phpunitCodeQuality => PHPUnitSetList::PHPUNIT_CODE_QUALITY, |
| 721 | + $doctrineCodeQuality => DoctrineSetList::DOCTRINE_CODE_QUALITY, |
| 722 | + $symfonyCodeQuality => SymfonySetList::SYMFONY_CODE_QUALITY, |
| 723 | + $symfonyConfigs => SymfonySetList::CONFIGS, |
| 724 | + ]; |
| 725 | + |
| 726 | + foreach ($setMap as $isEnabled => $setPath) { |
| 727 | + if ($isEnabled) { |
| 728 | + $this->sets[] = $setPath; |
| 729 | + } |
771 | 730 | } |
772 | 731 |
|
773 | | - // @experimental 2024-06 |
774 | | - if ($twig) { |
775 | | - $this->setGroups[] = SetGroup::TWIG; |
776 | | - } |
| 732 | + return $this; |
| 733 | + } |
777 | 734 |
|
778 | | - if ($phpunit) { |
779 | | - $this->setGroups[] = SetGroup::PHPUNIT; |
| 735 | + public function withComposerBased(bool $twig = false, bool $doctrine = false, bool $phpunit = false): self |
| 736 | + { |
| 737 | + $setMap = [ |
| 738 | + $twig => SetGroup::TWIG, |
| 739 | + $doctrine => SetGroup::DOCTRINE, |
| 740 | + $phpunit => SetGroup::PHPUNIT, |
| 741 | + ]; |
| 742 | + |
| 743 | + foreach ($setMap as $isEnabled => $setPath) { |
| 744 | + if ($isEnabled) { |
| 745 | + $this->setGroups[] = $setPath; |
| 746 | + } |
780 | 747 | } |
781 | 748 |
|
782 | 749 | return $this; |
|
0 commit comments