Skip to content

Commit

Permalink
fix: protect against empty key_value pair list
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijzer committed May 29, 2024
1 parent 83d438d commit d66de51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Component/Action/KeyMapperAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function apply(array $item): array
return $item;
}

$list = $this->getOption('list');
$list = array_filter($this->getOption('list'));
// when dealing with converted data we need the primary keys
// we just need to replace these keys
$newList = [];
Expand Down
11 changes: 9 additions & 2 deletions src/Component/Source/Command/SourceKeyValueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ class SourceKeyValueCommand implements SourceAwareInterface, ExecuteSourceComman
'list' => null,
'key' => null,
'value' => null,
'key_prefix' => ''
'key_prefix' => '',
'display_empty_values' => true,
];

public function execute(): array
{
return KeyValuePairBuilder::build(
$list = KeyValuePairBuilder::build(
$this->getSource()->getCachedReader(),
$this->getOption('key'),
$this->getOption('value'),
$this->getOption('key_prefix'),
);

if (true !== $this->getOption('display_empty_values')) {
return array_filter($list);
}

return $list;
}

public function executeWithOptions(array $options)
Expand Down

0 comments on commit d66de51

Please sign in to comment.