|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Gitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gitamin\Handlers\Commands\Project; |
|
13
|
|
|
|
|
14
|
|
|
use Gitamin\Commands\Project\UpdateProjectCommand; |
|
15
|
|
|
use Gitamin\Events\Project\ProjectWasUpdatedEvent; |
|
16
|
|
|
use Gitamin\Models\Project; |
|
17
|
|
|
|
|
18
|
|
View Code Duplication |
class UpdateProjectCommandHandler |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Handle the update project command. |
|
22
|
|
|
* |
|
23
|
|
|
* @param \Gitamin\Commands\Project\UpdateProjectCommand $command |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Gitamin\Models\Project |
|
26
|
|
|
*/ |
|
27
|
|
|
public function handle(UpdateProjectCommand $command) |
|
28
|
|
|
{ |
|
29
|
|
|
$project = $command->project; |
|
30
|
|
|
|
|
31
|
|
|
$project->update($this->filter($command)); |
|
32
|
|
|
|
|
33
|
|
|
event(new ProjectWasUpdatedEvent($project)); |
|
34
|
|
|
|
|
35
|
|
|
return $project; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Filter the command data. |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Gitamin\Commands\Issue\UpdateProjectCommand $command |
|
42
|
|
|
* |
|
43
|
|
|
* @return array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function filter(UpdateProjectCommand $command) |
|
46
|
|
|
{ |
|
47
|
|
|
$params = [ |
|
48
|
|
|
'name' => $command->name, |
|
49
|
|
|
'description' => $command->description, |
|
50
|
|
|
'path' => $command->path, |
|
51
|
|
|
'visibility_level' => $command->visibility_level, |
|
52
|
|
|
'owner_id' => $command->owner_id, |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
return array_filter($params, function ($val) { |
|
56
|
|
|
return $val !== null; |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.