Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<?php declare(strict_types=1);

use PHPStan\Command\AnalyseCommand;
use PHPStan\Command\BisectCommand;
use PHPStan\Command\ClearResultCacheCommand;
use PHPStan\Command\DiagnoseCommand;
use PHPStan\Command\DumpParametersCommand;
Expand Down Expand Up @@ -129,6 +130,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
$reversedComposerAutoloaderProjectPaths = array_values(array_unique(array_reverse($composerAutoloaderProjectPaths)));

$application->add(new AnalyseCommand($reversedComposerAutoloaderProjectPaths, $analysisStartTime));
$application->add(new BisectCommand());
$application->add(new WorkerCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new ClearResultCacheCommand($reversedComposerAutoloaderProjectPaths));
$application->add(new FixerWorkerCommand($reversedComposerAutoloaderProjectPaths));
Expand Down
36 changes: 36 additions & 0 deletions src/Command/Bisect/BinarySearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types = 1);

namespace PHPStan\Command\Bisect;

use InvalidArgumentException;
use function array_slice;
use function ceil;
use function count;
use function log;

final class BinarySearch
{

/**
* @template T
* @param list<T> $items Items ordered from oldest to newest (at least 2)
* @return BinarySearchStep<T>
*/
public static function getStep(array $items): BinarySearchStep
{
$count = count($items);
if ($count < 2) {
throw new InvalidArgumentException('Binary search requires at least 2 items.');
}

$mid = (int) (($count - 1) / 2);

return new BinarySearchStep(
$items[$mid],
array_slice($items, $mid + 1),
array_slice($items, 0, $mid + 1),
(int) ceil(log($count, 2)),
);
}

}
25 changes: 25 additions & 0 deletions src/Command/Bisect/BinarySearchStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace PHPStan\Command\Bisect;

/**
* @template T
*/
final class BinarySearchStep
{

/**
* @param T $item Item to test
* @param list<T> $ifGood Remaining items to search if this item is good
* @param list<T> $ifBad Remaining items to search if this item is bad
*/
public function __construct(
public readonly mixed $item,
public readonly array $ifGood,
public readonly array $ifBad,
public readonly int $stepsRemaining,
)
{
}

}
Loading
Loading