-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathKaizenStepper.php
More file actions
55 lines (44 loc) · 1.23 KB
/
KaizenStepper.php
File metadata and controls
55 lines (44 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Rector\Configuration;
use Rector\Caching\Detector\KaizenRulesDetector;
use Rector\Contract\Rector\RectorInterface;
final class KaizenStepper
{
/**
* @var positive-int|null
*/
private ?int $stepCount = null;
public function __construct(
private readonly KaizenRulesDetector $kaizenRulesDetector
) {
}
/**
* @param positive-int $stepCount
*/
public function setStepCount(int $stepCount): void
{
$this->stepCount = $stepCount;
}
public function enabled(): bool
{
return $this->stepCount !== null;
}
/**
* @param class-string<RectorInterface> $rectorClass
*/
public function recordAppliedRule(string $rectorClass): void
{
$this->kaizenRulesDetector->addRule($rectorClass);
}
public function shouldKeepImproving(string $rectorClass): bool
{
$appliedRectorClasses = $this->kaizenRulesDetector->loadRules();
// is rule already in applied rules? keep going
if (in_array($rectorClass, $appliedRectorClasses)) {
return true;
}
// make sure we made enough changes
return count($appliedRectorClasses) < $this->stepCount;
}
}