From 49e411315940023f4b22a081bb9eeb397a663aa5 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sat, 17 Oct 2015 09:59:43 +0100 Subject: [PATCH] Filter component elements that aren't set --- .../Component/AddComponentCommandHandler.php | 4 ++-- .../UpdateComponentCommandHandler.php | 24 +++++-------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/app/Handlers/Commands/Component/AddComponentCommandHandler.php b/app/Handlers/Commands/Component/AddComponentCommandHandler.php index 412eb0ae..9b4d2332 100644 --- a/app/Handlers/Commands/Component/AddComponentCommandHandler.php +++ b/app/Handlers/Commands/Component/AddComponentCommandHandler.php @@ -26,14 +26,14 @@ class AddComponentCommandHandler */ public function handle(AddComponentCommand $command) { - $component = Component::create([ + $component = Component::create(array_filter([ 'name' => $command->name, 'description' => $command->description, 'link' => $command->link, 'status' => $command->status, 'order' => $command->order, 'group_id' => $command->group_id, - ]); + ])); event(new ComponentWasAddedEvent($component)); diff --git a/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php b/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php index b639b864..06a6dc8d 100644 --- a/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php +++ b/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php @@ -27,29 +27,17 @@ class UpdateComponentCommandHandler public function handle(UpdateComponentCommand $command) { $component = $command->component; - $component->update($this->filterComponentData($command)); - - event(new ComponentWasUpdatedEvent($component)); - - return $component; - } - - /** - * Filter the command data. - * - * @param \CachetHQ\Cachet\Commands\Component\UpdateComponentCommand $command - * - * @return array - */ - protected function filterComponentData($command) - { - return array_filter([ + $component->update(array_filter([ 'name' => $command->name, 'description' => $command->description, 'link' => $command->link, 'status' => $command->status, 'order' => $command->order, 'group_id' => $command->group_id, - ]); + ])); + + event(new ComponentWasUpdatedEvent($component)); + + return $component; } }