From 17d7628512a6b57f6fb59d4740112f39fabeb0be Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Wed, 29 May 2024 13:09:28 +0200 Subject: [PATCH] fix: protect against empty key_value pair list --- src/Component/Action/KeyMapperAction.php | 2 +- src/Component/Debugger/ItemDebugger.php | 3 ++- .../Source/Command/SourceKeyValueCommand.php | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Component/Action/KeyMapperAction.php b/src/Component/Action/KeyMapperAction.php index 99f1db6c..c360c470 100644 --- a/src/Component/Action/KeyMapperAction.php +++ b/src/Component/Action/KeyMapperAction.php @@ -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 = []; diff --git a/src/Component/Debugger/ItemDebugger.php b/src/Component/Debugger/ItemDebugger.php index dbf5ca9d..fc0d2311 100644 --- a/src/Component/Debugger/ItemDebugger.php +++ b/src/Component/Debugger/ItemDebugger.php @@ -8,6 +8,7 @@ class ItemDebugger { public function log($item, $message) { - dump($message, TypeGuesser::guess($item)); + dump($message, $item); + //dump($message, TypeGuesser::guess($item)); } } \ No newline at end of file diff --git a/src/Component/Source/Command/SourceKeyValueCommand.php b/src/Component/Source/Command/SourceKeyValueCommand.php index 6bc2294d..9c181217 100644 --- a/src/Component/Source/Command/SourceKeyValueCommand.php +++ b/src/Component/Source/Command/SourceKeyValueCommand.php @@ -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)