Skip to content
Closed
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
3 changes: 3 additions & 0 deletions src/Command/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected function configure(): void
new InputOption('watch', mode: InputOption::VALUE_NONE, description: 'Launch PHPStan Pro'),
new InputOption('pro', mode: InputOption::VALUE_NONE, description: 'Launch PHPStan Pro'),
new InputOption('fail-without-result-cache', mode: InputOption::VALUE_NONE, description: 'Return non-zero exit code when result cache is not used'),
new InputOption('dirty', mode: InputOption::VALUE_NONE, description: 'Only analyze files that have uncommitted changes'),
]);
}

Expand Down Expand Up @@ -147,6 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$pro = (bool) $input->getOption('watch') || (bool) $input->getOption('pro');
$fix = (bool) $input->getOption('fix');
$failWithoutResultCache = (bool) $input->getOption('fail-without-result-cache');
$dirty = (bool) $input->getOption('dirty');

/** @var string|false|null $generateBaselineFile */
$generateBaselineFile = $input->getOption('generate-baseline');
Expand Down Expand Up @@ -190,6 +192,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$tmpFile,
$insteadOfFile,
true,
$dirty,
);
} catch (InceptionNotSuccessfulException $e) {
return 1;
Expand Down
1 change: 1 addition & 0 deletions src/Command/ClearResultCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
null,
null,
true,
false,
);
} catch (InceptionNotSuccessfulException) {
return 1;
Expand Down
9 changes: 8 additions & 1 deletion src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static function begin(
?string $singleReflectionFile,
?string $singleReflectionInsteadOfFile,
bool $cleanupContainerCache,
bool $dirty,
): InceptionResult
{
$stdOutput = new SymfonyOutput($output, new SymfonyStyle(new ErrorsConsoleStyle($input, $output)));
Expand Down Expand Up @@ -239,7 +240,13 @@ public static function begin(
$defaultLevelUsed = true;
}

$paths = array_map(static fn (string $path): string => $currentWorkingDirectoryFileHelper->normalizePath($currentWorkingDirectoryFileHelper->absolutizePath($path)), $paths);
if ($dirty) {
$dirtyPathsHelper = new DirtyFilesHelper();
$paths = array_map(static fn (string $path): string => $currentWorkingDirectoryFileHelper
->normalizePath($currentWorkingDirectoryFileHelper->absolutizePath($path)), $dirtyPathsHelper->getGitDirtyFiles());
} else {
$paths = array_map(static fn (string $path): string => $currentWorkingDirectoryFileHelper->normalizePath($currentWorkingDirectoryFileHelper->absolutizePath($path)), $paths);
}

$analysedPathsFromConfig = [];
$containerFactory = new ContainerFactory($currentWorkingDirectory);
Expand Down
1 change: 1 addition & 0 deletions src/Command/DiagnoseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
null,
null,
false,
false,
);
} catch (InceptionNotSuccessfulException) {
return 1;
Expand Down
43 changes: 43 additions & 0 deletions src/Command/DirtyFilesHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types = 1);

namespace PHPStan\Command;

final class DirtyFilesHelper
{
private function getGitRepoRoot(): ?string
{
exec('git rev-parse --show-toplevel 2>&1', $output, $returnVar);
if ($returnVar !== 0) {
return null;
}

return trim($output[0]);
}

/**
* @return string[]
*/
public function getGitDirtyFiles(): array
{
$repoPath = $this->getGitRepoRoot();
if ($repoPath === null) {
return [];
}

$cmd = 'cd ' . escapeshellarg($repoPath) . ' && git status --porcelain';

exec($cmd, $output, $returnVar);
if ($returnVar !== 0) {
return [];
}

$dirtyFiles = [];

foreach ($output as $line) {
$filePath = substr($line, 3);
$dirtyFiles[] = $filePath;
}

return $dirtyFiles;
}
}
1 change: 1 addition & 0 deletions src/Command/DumpParametersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
null,
null,
false,
false,
);
} catch (InceptionNotSuccessfulException) {
return 1;
Expand Down
1 change: 1 addition & 0 deletions src/Command/FixerWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
null,
null,
false,
false,
);
} catch (InceptionNotSuccessfulException) {
return 1;
Expand Down
1 change: 1 addition & 0 deletions src/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$tmpFile,
$insteadOfFile,
false,
false,
);
} catch (InceptionNotSuccessfulException $e) {
return 1;
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function testBegin(
null,
null,
false,
false,
);
if ($expectException) {
$this->fail();
Expand Down Expand Up @@ -309,6 +310,7 @@ public function testResolveParameters(
null,
null,
false,
false,
);
$parameters = $result->getContainer()->getParameters();
foreach ($expectedParameters as $name => $expectedValue) {
Expand Down
Loading