Skip to content

Commit 1232a62

Browse files
committed
Merge branch 2.1.x into 2.2.x
2 parents edd5f9f + ae20323 commit 1232a62

5 files changed

Lines changed: 670 additions & 0 deletions

File tree

bin/phpstan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?php declare(strict_types=1);
33

44
use PHPStan\Command\AnalyseCommand;
5+
use PHPStan\Command\BisectCommand;
56
use PHPStan\Command\ClearResultCacheCommand;
67
use PHPStan\Command\DiagnoseCommand;
78
use PHPStan\Command\DumpParametersCommand;
@@ -129,6 +130,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
129130
$reversedComposerAutoloaderProjectPaths = array_values(array_unique(array_reverse($composerAutoloaderProjectPaths)));
130131

131132
$application->add(new AnalyseCommand($reversedComposerAutoloaderProjectPaths, $analysisStartTime));
133+
$application->add(new BisectCommand());
132134
$application->add(new WorkerCommand($reversedComposerAutoloaderProjectPaths));
133135
$application->add(new ClearResultCacheCommand($reversedComposerAutoloaderProjectPaths));
134136
$application->add(new FixerWorkerCommand($reversedComposerAutoloaderProjectPaths));
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Command\Bisect;
4+
5+
use InvalidArgumentException;
6+
use function array_slice;
7+
use function ceil;
8+
use function count;
9+
use function log;
10+
11+
final class BinarySearch
12+
{
13+
14+
/**
15+
* @template T
16+
* @param list<T> $items Items ordered from oldest to newest (at least 2)
17+
* @return BinarySearchStep<T>
18+
*/
19+
public static function getStep(array $items): BinarySearchStep
20+
{
21+
$count = count($items);
22+
if ($count < 2) {
23+
throw new InvalidArgumentException('Binary search requires at least 2 items.');
24+
}
25+
26+
$mid = (int) (($count - 1) / 2);
27+
28+
return new BinarySearchStep(
29+
$items[$mid],
30+
array_slice($items, $mid + 1),
31+
array_slice($items, 0, $mid + 1),
32+
(int) ceil(log($count, 2)),
33+
);
34+
}
35+
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Command\Bisect;
4+
5+
/**
6+
* @template T
7+
*/
8+
final class BinarySearchStep
9+
{
10+
11+
/**
12+
* @param T $item Item to test
13+
* @param list<T> $ifGood Remaining items to search if this item is good
14+
* @param list<T> $ifBad Remaining items to search if this item is bad
15+
*/
16+
public function __construct(
17+
public readonly mixed $item,
18+
public readonly array $ifGood,
19+
public readonly array $ifBad,
20+
public readonly int $stepsRemaining,
21+
)
22+
{
23+
}
24+
25+
}

0 commit comments

Comments
 (0)