Skip to content

Commit 454d537

Browse files
Merge pull request #254 from kingkero
Refactor array_merge out of loops
2 parents 53cdd84 + 21cfb06 commit 454d537

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/Git/ChangedFiles/Detector/PrePush.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,10 @@ private function collectChangedFiles(array $ranges, array $filter): array
103103
$newHash = 'HEAD';
104104
}
105105
if (!empty($oldHash)) {
106-
$files = array_merge(
107-
$files,
108-
$this->repository->getDiffOperator()->getChangedFiles($oldHash, $newHash, $filter)
109-
);
106+
$files[] = $this->repository->getDiffOperator()->getChangedFiles($oldHash, $newHash, $filter);
110107
}
111108
}
112-
return array_unique($files);
109+
return array_unique(array_merge(...$files));
113110
}
114111

115112
/**

src/Hook/File/Action/DoesNotContainRegex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ protected function getFilesToCheck(Repository $repository): array
9090
$index = $repository->getIndexOperator();
9191
$files = [];
9292
foreach ($this->fileExtensions as $ext) {
93-
$files = array_merge($files, $index->getStagedFilesOfType($ext));
93+
$files[] = $index->getStagedFilesOfType($ext);
9494
}
95-
return $files;
95+
return array_merge(...$files);
9696
}
9797

9898
/**

src/Runner/Config/Setup/Advanced.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ protected function getPHPActionOptions(): array
107107
$options = [];
108108
$addOption = $this->io->ask(' <info>Add a validator option?</info> <comment>[y,n]</comment> ', 'n');
109109
while (IOUtil::answerToBool($addOption)) {
110-
$options = array_merge($options, $this->getPHPActionOption());
110+
$options[] = $this->getPHPActionOption();
111111
// add another action?
112112
$addOption = $this->io->ask(' <info>Add another validator option?</info> <comment>[y,n]</comment> ', 'n');
113113
}
114-
return $options;
114+
return array_merge(...$options);
115115
}
116116

117117
/**

0 commit comments

Comments
 (0)