Skip to content

Commit f9c9440

Browse files
author
cradu
committed
Added option for analyzer_chunk_size
1 parent 586c33b commit f9c9440

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

config/git-hooks.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@
266266
*/
267267
'validate_paths' => env('GITHOOKS_VALIDATE_PATHS', true),
268268

269+
/*
270+
|--------------------------------------------------------------------------
271+
| Analyzer chunk size
272+
|--------------------------------------------------------------------------
273+
|
274+
| This configuration option allows you to set the number of files to be
275+
| sent in chunks to the analyzers. Can also be set to 1 to send them
276+
| one by one.
277+
|
278+
*/
279+
'analyzer_chunk_size' => env('GITHOOKS_ANALYZER_CHUNK_SIZE', 100),
280+
269281
/*
270282
|--------------------------------------------------------------------------
271283
| Output errors

src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,26 @@ public function getDockerContainer(): string
191191
*/
192192
protected function analizeCommittedFiles(Collection $commitFiles): self
193193
{
194-
foreach ($commitFiles as $file) {
195-
if (! $this->canFileBeAnalyzed($file)) {
194+
$chunkSize = config('git-hooks.analyzer_chunk_size');
195+
196+
/** @var Collection<int, ChangedFile> $chunk */
197+
foreach ($commitFiles->chunk($chunkSize) as $chunk) {
198+
$filePaths = [];
199+
200+
/** @var ChangedFile $file */
201+
foreach ($chunk as $file) {
202+
if (! $this->canFileBeAnalyzed($file)) {
203+
continue;
204+
}
205+
206+
$filePaths[] = $file->getFilePath();
207+
}
208+
209+
if (empty($filePaths)) {
196210
continue;
197211
}
198212

199-
$filePath = $file->getFilePath();
213+
$filePath = implode(' ', $filePaths);
200214
$command = $this->dockerCommand($this->analyzerCommand().' '.$filePath);
201215

202216
$params = [

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function defineEnvironment($app): void
5252
'code_analyzers' => [],
5353
'artisan_path' => base_path('artisan'),
5454
'output_errors' => false,
55+
'analyzer_chunk_size' => 100,
5556
'validate_paths' => true,
5657
'automatically_fix_errors' => false,
5758
'rerun_analyzer_after_autofix' => false,

0 commit comments

Comments
 (0)