rector/src/Configuration/Levels/LevelRulesResolver.php
Tomas Votruba 7810dc2e74 Updated Rector to commit 487f162d53fe42f6d76557ca6cd49d93ceb911e8
487f162d53 [experimental] Add withTypeCoverageLevel() method to streamline Rector integration to new projects (#5553)
2024-02-05 08:01:59 +00:00

25 lines
809 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Configuration\Levels;
use Rector\Contract\Rector\RectorInterface;
use RectorPrefix202402\Webmozart\Assert\Assert;
final class LevelRulesResolver
{
/**
* @param array<class-string<RectorInterface>> $availableRules
* @return array<class-string<RectorInterface>>
*/
public static function resolve(int $level, array $availableRules, string $methodName) : array
{
$rulesCount = \count($availableRules);
Assert::range($level, 0, $rulesCount - 1, 'Level %s is not available "' . $methodName . '" method. Pick one between %2$s (lowest) and %3$s (highest).');
$levelRules = [];
for ($i = 0; $i <= $level; ++$i) {
$levelRules[] = $availableRules[$i];
}
return $levelRules;
}
}