Skip to content

Commit

Permalink
Merge pull request #254 from kingkero
Browse files Browse the repository at this point in the history
Refactor array_merge out of loops
  • Loading branch information
sebastianfeldmann authored Aug 30, 2024
2 parents 53cdd84 + 21cfb06 commit 454d537
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/Git/ChangedFiles/Detector/PrePush.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ private function collectChangedFiles(array $ranges, array $filter): array
$newHash = 'HEAD';
}
if (!empty($oldHash)) {
$files = array_merge(
$files,
$this->repository->getDiffOperator()->getChangedFiles($oldHash, $newHash, $filter)
);
$files[] = $this->repository->getDiffOperator()->getChangedFiles($oldHash, $newHash, $filter);
}
}
return array_unique($files);
return array_unique(array_merge(...$files));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Hook/File/Action/DoesNotContainRegex.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ protected function getFilesToCheck(Repository $repository): array
$index = $repository->getIndexOperator();
$files = [];
foreach ($this->fileExtensions as $ext) {
$files = array_merge($files, $index->getStagedFilesOfType($ext));
$files[] = $index->getStagedFilesOfType($ext);
}
return $files;
return array_merge(...$files);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Runner/Config/Setup/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ protected function getPHPActionOptions(): array
$options = [];
$addOption = $this->io->ask(' <info>Add a validator option?</info> <comment>[y,n]</comment> ', 'n');
while (IOUtil::answerToBool($addOption)) {
$options = array_merge($options, $this->getPHPActionOption());
$options[] = $this->getPHPActionOption();
// add another action?
$addOption = $this->io->ask(' <info>Add another validator option?</info> <comment>[y,n]</comment> ', 'n');
}
return $options;
return array_merge(...$options);
}

/**
Expand Down

0 comments on commit 454d537

Please sign in to comment.