Fixed up array_filter stuff

Closes #1071
This commit is contained in:
Graham Campbell
2015-11-07 17:21:20 +00:00
parent fb7a15aaa7
commit bf88dfced0
4 changed files with 48 additions and 29 deletions

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -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');
}
/**

View File

@@ -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');
}
}