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\Moment; |
13
|
|
|
|
14
|
|
|
use Gitamin\Commands\Moment\AddMomentCommand; |
15
|
|
|
use Gitamin\Dates\DateFactory; |
16
|
|
|
//use Gitamin\Events\Moment\MomentWasAddedEvent; |
17
|
|
|
use Gitamin\Models\Moment; |
18
|
|
|
|
19
|
|
|
class AddMomentCommandHandler |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The date factory instance. |
23
|
|
|
* |
24
|
|
|
* @var \Gitamin\Dates\DateFactory |
25
|
|
|
*/ |
26
|
|
|
protected $dates; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create a new report moment command handler instance. |
30
|
|
|
* |
31
|
|
|
* @param \Gitamin\Dates\DateFactory $dates |
32
|
|
|
*/ |
33
|
|
|
public function __construct(DateFactory $dates) |
34
|
|
|
{ |
35
|
|
|
$this->dates = $dates; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Handle the report moment command. |
40
|
|
|
* |
41
|
|
|
* @param \Gitamin\Commands\Moment\AddMomentCommand $command |
42
|
|
|
* |
43
|
|
|
* @return \Gitamin\Models\Moment |
44
|
|
|
*/ |
45
|
|
|
public function handle(AddMomentCommand $command) |
46
|
|
|
{ |
47
|
|
|
$data = [ |
48
|
|
|
'action' => $command->action, |
49
|
|
|
'author_id' => $command->author_id, |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
if ($command->title) { |
53
|
|
|
$data['title'] = $command->title; |
54
|
|
|
} |
55
|
|
|
if ($command->data) { |
56
|
|
|
$data['data'] = $command->data; |
57
|
|
|
} |
58
|
|
|
// Link with the target. |
59
|
|
|
if ($command->target_type) { |
60
|
|
|
$data['target_type'] = $command->target_type; |
61
|
|
|
} |
62
|
|
|
if ($command->target_id) { |
63
|
|
|
$data['target_id'] = $command->target_id; |
64
|
|
|
} |
65
|
|
|
// Link with the project. |
66
|
|
|
if ($command->project_id) { |
67
|
|
|
$data['project_id'] = $command->project_id; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// Create the moment |
71
|
|
|
$moment = Moment::create($data); |
72
|
|
|
|
73
|
|
|
//event(new MomentWasAddedEvent($moment)); |
|
|
|
|
74
|
|
|
|
75
|
|
|
return $moment; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.