Skip to content

Commit

Permalink
Few tiny fixes (#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Sep 2, 2024
1 parent 3aa886f commit 0ee9020
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
20 changes: 19 additions & 1 deletion src/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
final class RectorConfig extends Container
{
/**
* @var array<class-string<RectorInterface>, mixed[]>>
* @var array<class-string<ConfigurableRectorInterface>, mixed[]>>
*/
private array $ruleConfigurations = [];

Expand Down Expand Up @@ -418,4 +418,22 @@ public function reportingRealPath(bool $absolute = true): void
{
SimpleParameterProvider::setParameter(Option::ABSOLUTE_FILE_PATH, $absolute);
}

/**
* @internal Used only for bridge
* @return array<class-string<ConfigurableRectorInterface>, mixed>
*/
public function getRuleConfigurations(): array
{
return $this->ruleConfigurations;
}

/**
* @internal Used only for bridge
* @return array<class-string<RectorInterface>>
*/
public function getRectorClasses(): array
{
return $this->tags[RectorInterface::class] ?? [];
}
}
10 changes: 6 additions & 4 deletions src/Configuration/Levels/LevelRulesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ final class LevelRulesResolver
*/
public static function resolve(int $level, array $availableRules, string $methodName): array
{
// level < 0 is not allowed
Assert::natural($level, sprintf('Level must be >= 0 on %s', $methodName));

Assert::allIsAOf($availableRules, RectorInterface::class);

$rulesCount = count($availableRules);

if ($availableRules === []) {
throw new ShouldNotHappenException(sprintf(
'There is no available rules in %s, define the available rules first',
'There are no available rules in "%s()", define the available rules first',
$methodName
));
}

// level < 0 is not allowed
Assert::natural($level, sprintf('Level must be >= 0 on %s', $methodName));

// start with 0
$maxLevel = $rulesCount - 1;
if ($level > $maxLevel) {
Expand Down

0 comments on commit 0ee9020

Please sign in to comment.