Skip to content

Commit 1929e44

Browse files
committed
Got rid of duplicate foreach loop when selecting the packages.
1 parent 2626704 commit 1929e44

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

src/Composer/Satis/Command/BuildCommand.php

+18-34
Original file line numberDiff line numberDiff line change
@@ -209,52 +209,36 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
209209
$links[] = new Link('__root__', $name, new MultiConstraint(array()), 'requires', '*');
210210
}
211211
} else {
212+
$packages = array();
212213
if($filterForPackages) {
213-
// collect all the packages based on the given $packagesFilter
214-
$packages = array();
215-
foreach($packagesFilter as $filter) {
214+
// apply package filter if defined
215+
foreach ($packagesFilter as $filter) {
216216
$packages += $repo->findPackages($filter);
217217
}
218+
} else {
219+
// process other repos directly
220+
$packages = $repo->getPackages();
221+
}
218222

219-
foreach($packages as $package) {
220-
// skip aliases
221-
if ($package instanceof AliasPackage) {
222-
continue;
223-
}
223+
foreach ($packages as $package) {
224+
// skip aliases
225+
if ($package instanceof AliasPackage) {
226+
continue;
227+
}
224228

225-
if ($package->getStability() > BasePackage::$stabilities[$minimumStability]) {
226-
continue;
227-
}
229+
if ($package->getStability() > BasePackage::$stabilities[$minimumStability]) {
230+
continue;
231+
}
228232

233+
// add matching package if not yet selected
234+
if (!isset($selected[$package->getName()])) {
229235
if ($verbose) {
230-
$output->writeln('Selected '.$package->getPrettyName().' ('.$package->getPrettyVersion().') based on the given filter options');
236+
$output->writeln('Selected '.$package->getPrettyName().' ('.$package->getPrettyVersion().')');
231237
}
232238

233239
$selected[$package->getUniqueName()] = $package;
234240
}
235241
}
236-
else {
237-
// process other repos directly
238-
foreach ($repo->getPackages() as $package) {
239-
// skip aliases
240-
if ($package instanceof AliasPackage) {
241-
continue;
242-
}
243-
244-
if ($package->getStability() > BasePackage::$stabilities[$minimumStability]) {
245-
continue;
246-
}
247-
248-
// add matching package if not yet selected
249-
if (!isset($selected[$package->getName()])) {
250-
if ($verbose) {
251-
$output->writeln('Selected '.$package->getPrettyName().' ('.$package->getPrettyVersion().')');
252-
}
253-
254-
$selected[$package->getUniqueName()] = $package;
255-
}
256-
}
257-
}
258242
}
259243
}
260244
} else {

0 commit comments

Comments
 (0)