Skip to content

Commit 1050275

Browse files
committed
DebugConfigResolverCommand.php: Enhance error handling
1 parent 0cc5ad0 commit 1050275

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/bundle/Core/Command/DebugConfigResolverCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111111

112112
if (null !== $sort && !empty($parameterData)) {
113113
if (!is_array($parameterData)) {
114-
throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on list.");
114+
throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on a list.");
115115
}
116116
if (!array_is_list($parameterData)) {
117-
throw new InvalidArgumentException('--sort', "'$parameter' is a hash or an object. Sort can be used only on list.");
117+
throw new InvalidArgumentException('--sort', "'$parameter' is a hash but sort can be used only on a list (an array with numeral keys incremented from zero).");
118118
}
119-
if (!array_key_exists($sort, $parameterData[0])) {
120-
throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on '$parameter' list items.");
121-
}
122-
if (!is_scalar($parameterData[0][$sort])) {
123-
throw new InvalidArgumentException('--sort', "'{$parameter}[n][{$sort}]' properties aren't scalar and can't be sorted.");
119+
for ($i=0, $count = count($parameterData); $i < $count; $i++) {
120+
if (!array_key_exists($sort, $parameterData[$i])) {
121+
throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item.");
122+
}
123+
if (!is_scalar($parameterData[$i][$sort])) {
124+
throw new InvalidArgumentException('--sort', "'$sort' properties aren't always scalar and can't be sorted.");
125+
}
124126
}
125127
if ($input->getOption('reverse-sort')) {
126128
usort($parameterData, static fn (array $a, array $b): int => $b[$sort] <=> $a[$sort]);

0 commit comments

Comments
 (0)