Skip to content

Commit

Permalink
Added option for analyzer_chunk_size
Browse files Browse the repository at this point in the history
  • Loading branch information
cradu committed Apr 19, 2024
1 parent 586c33b commit f9c9440
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 12 additions & 0 deletions config/git-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@
*/
'validate_paths' => env('GITHOOKS_VALIDATE_PATHS', true),

/*
|--------------------------------------------------------------------------
| Analyzer chunk size
|--------------------------------------------------------------------------
|
| This configuration option allows you to set the number of files to be
| sent in chunks to the analyzers. Can also be set to 1 to send them
| one by one.
|
*/
'analyzer_chunk_size' => env('GITHOOKS_ANALYZER_CHUNK_SIZE', 100),

/*
|--------------------------------------------------------------------------
| Output errors
Expand Down
20 changes: 17 additions & 3 deletions src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,26 @@ public function getDockerContainer(): string
*/
protected function analizeCommittedFiles(Collection $commitFiles): self
{
foreach ($commitFiles as $file) {
if (! $this->canFileBeAnalyzed($file)) {
$chunkSize = config('git-hooks.analyzer_chunk_size');

/** @var Collection<int, ChangedFile> $chunk */
foreach ($commitFiles->chunk($chunkSize) as $chunk) {
$filePaths = [];

/** @var ChangedFile $file */
foreach ($chunk as $file) {
if (! $this->canFileBeAnalyzed($file)) {
continue;
}

$filePaths[] = $file->getFilePath();
}

if (empty($filePaths)) {
continue;
}

$filePath = $file->getFilePath();
$filePath = implode(' ', $filePaths);
$command = $this->dockerCommand($this->analyzerCommand().' '.$filePath);

$params = [
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function defineEnvironment($app): void
'code_analyzers' => [],
'artisan_path' => base_path('artisan'),
'output_errors' => false,
'analyzer_chunk_size' => 100,
'validate_paths' => true,
'automatically_fix_errors' => false,
'rerun_analyzer_after_autofix' => false,
Expand Down

0 comments on commit f9c9440

Please sign in to comment.