diff --git a/app/Handlers/Commands/Component/AddComponentCommandHandler.php b/app/Handlers/Commands/Component/AddComponentCommandHandler.php index b3bd9791..11fd1c0c 100644 --- a/app/Handlers/Commands/Component/AddComponentCommandHandler.php +++ b/app/Handlers/Commands/Component/AddComponentCommandHandler.php @@ -26,21 +26,30 @@ class AddComponentCommandHandler */ public function handle(AddComponentCommand $command) { - $componentData = array_filter([ - 'name' => $command->name, - 'description' => $command->description, - 'link' => $command->link, - 'status' => $command->status, - 'order' => $command->order, - 'group_id' => $command->group_id, - ]); - - $componentData['enabled'] = $command->enabled; - - $component = Component::create($componentData); + $component = Component::create($this->filter($command)); event(new ComponentWasAddedEvent($component)); return $component; } + + /** + * Filter the command data. + * + * @param \CachetHQ\Cachet\Commands\Incident\AddComponentCommand $command + * + * @return array + */ + protected function filter(AddComponentCommand $command) + { + return array_filter([ + 'name' => $command->name, + 'description' => $command->description, + 'link' => $command->link, + 'status' => $command->status, + 'enabled' => $command->enabled, + 'order' => $command->order, + 'group_id' => $command->group_id, + ], 'is_null'); + } } diff --git a/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php b/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php index d6cbb414..1e42c81b 100644 --- a/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php +++ b/app/Handlers/Commands/Component/UpdateComponentCommandHandler.php @@ -27,21 +27,31 @@ class UpdateComponentCommandHandler public function handle(UpdateComponentCommand $command) { $component = $command->component; - $componentData = array_filter([ - 'name' => $command->name, - 'description' => $command->description, - 'link' => $command->link, - 'status' => $command->status, - 'order' => $command->order, - 'group_id' => $command->group_id, - ]); - $componentData['enabled'] = $command->enabled; - - $component->update($componentData); + $component->update($this->filter($command)); event(new ComponentWasUpdatedEvent($component)); return $component; } + + /** + * Filter the command data. + * + * @param \CachetHQ\Cachet\Commands\Incident\UpdateComponentCommand $command + * + * @return array + */ + protected function filter(UpdateComponentCommand $command) + { + return array_filter([ + 'name' => $command->name, + 'description' => $command->description, + 'link' => $command->link, + 'status' => $command->status, + 'enabled' => $command->enabled, + 'order' => $command->order, + 'group_id' => $command->group_id, + ], 'is_null'); + } } diff --git a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index 7a6bed4f..c2ce129b 100644 --- a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -55,7 +55,7 @@ class UpdateIncidentCommandHandler } $incident = $command->incident; - $incident->update($this->filterIncidentData($command)); + $incident->update($this->filter($command)); // The incident occurred at a different time. if ($command->incident_date) { @@ -86,7 +86,7 @@ class UpdateIncidentCommandHandler * * @return array */ - protected function filterIncidentData($command) + protected function filter(UpdateIncidentCommand $command) { return array_filter([ 'name' => $command->name, @@ -96,7 +96,7 @@ class UpdateIncidentCommandHandler 'component_id' => $command->component_id, 'component_status' => $command->component_status, 'notify' => $command->notify, - ]); + ], 'is_null'); } /** diff --git a/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php b/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php index 11d0ce56..ff54f992 100644 --- a/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php +++ b/app/Handlers/Commands/Metric/UpdateMetricCommandHandler.php @@ -28,7 +28,7 @@ class UpdateMetricCommandHandler { $metric = $command->metric; - $metric->update($this->filterMetricData($command)); + $metric->update($this->filter($command)); event(new MetricWasUpdatedEvent($metric)); @@ -42,7 +42,7 @@ class UpdateMetricCommandHandler * * @return array */ - protected function filterMetricData($command) + protected function filter(UpdateMetricCommand $command) { return array_filter([ 'name' => $command->name, @@ -52,6 +52,6 @@ class UpdateMetricCommandHandler 'calc_type' => $command->calc_type, 'display_chart' => $command->display_chart, 'places' => $command->places, - ]); + ], 'is_null'); } }