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