Added sorting options to ibexa:debug:config#631
Conversation
ea930f3 to
1aad6d2
Compare
|
ibexa:debug:config
b484bd6 to
1050275
Compare
a3c7fa8 to
7202bcd
Compare
| if (!array_is_list($parameterData)) { | ||
| 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)."); | ||
| } | ||
| for ($i = 0, $count = count($parameterData); $i < $count; ++$i) { |
There was a problem hiding this comment.
| for ($i = 0, $count = count($parameterData); $i < $count; ++$i) { | |
| foreach ($parameterData as $i => $data) { |
| throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item."); | ||
| } | ||
| if (!is_scalar($parameterData[$i][$sort])) { | ||
| throw new InvalidArgumentException('--sort', "'$sort' properties aren't always scalar and can't be sorted."); |
There was a problem hiding this comment.
Instead of letting these input-validation exceptions bubble, you could catch them, print a styled error, and return Command::INVALID or use Command::FAILURE for runtime errors.
| if (!array_key_exists($sort, $parameterData[$i])) { | ||
| throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item."); | ||
| } | ||
| if (!is_scalar($parameterData[$i][$sort])) { |
There was a problem hiding this comment.
is_scalar() allows bool, int, float, string. Mixed types across items (e.g., "10" and 2, or "abc" and 1) will be coerced by <=>, often in surprising ways (non-numeric strings become 0 in numeric comparisons). You could enforce type consistency across the list for the $sort key, or detect the predominant type and normalize.
|
|
||
| if (null !== $sort && !empty($parameterData)) { | ||
| if (!is_array($parameterData)) { | ||
| throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on a list."); |
There was a problem hiding this comment.
For CLI argument validation you could use a Symfony\Component\Console\Exception\InvalidArgumentException. It integrates better with Console error styling and exit codes.
|



Description:
Sort parameter list when sortable, when it's an array of arrays by a scalar value's key.
For example, see
adminsiteaccess field templates by decreasing priority:php bin/console ibexa:debug:config field_templates --siteaccess admin --sort priority --reverse-sortFor QA:
Documentation: