Skip to content

Commit

Permalink
[automated] Update Rector Dependencies (#2630)
Browse files Browse the repository at this point in the history
* [automated] Update Rector Dependencies

* Fix

* copy paste original resolveFromFilePath() as private method on RectorSetsTreeProvider

* Fix phpsta

---------

Co-authored-by: TomasVotruba <[email protected]>
Co-authored-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent e394ab9 commit f043f21
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 26 additions & 4 deletions src/Sets/RectorSetsTreeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace App\Sets;

use ReflectionProperty;
use App\RuleFilter\ValueObject\RectorSet;
use Rector\Bridge\SetProviderCollector;
use Rector\Bridge\SetRectorsResolver;
use Rector\Config\RectorConfig;
use Rector\Contract\Rector\RectorInterface;
use Rector\Set\Contract\SetInterface;
use RectorLaravel\Set\LaravelSetProvider;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -88,19 +90,39 @@ public function provideCommunity(): array
return $communityRectorSets;
}

/**
* @return array<class-string<RectorInterface>>
*/
public function resolveFromFilePath(string $configFilePath): array
{
Assert::fileExists($configFilePath);

$rectorConfig = new RectorConfig();
/** @var callable $configCallable */
$configCallable = require $configFilePath;
$configCallable($rectorConfig);

// get tagged class-names
$tagsReflectionProperty = new ReflectionProperty($rectorConfig, 'tags');
$tags = $tagsReflectionProperty->getValue($rectorConfig);

$rectorClasses = $tags[RectorInterface::class] ?? [];
sort($rectorClasses);

return array_unique($rectorClasses);
}

/**
* @param SetInterface[] $sets
* @return RectorSet[]
*/
private function createRectorSetsFromSetProviders(array $sets): array
{
Assert::allIsInstanceOf($sets, SetInterface::class);

$setRectorsResolver = new SetRectorsResolver();
$rectorSets = [];

foreach ($sets as $set) {
$rectorClasses = $setRectorsResolver->resolveFromFilePath($set->getSetFilePath());
$rectorClasses = $this->resolveFromFilePath($set->getSetFilePath());
$rectorSets[] = new RectorSet($set->getGroupName(), $set->getName(), $rectorClasses);
}

Expand Down

0 comments on commit f043f21

Please sign in to comment.