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\Issue; |
13
|
|
|
|
14
|
|
|
use Gitamin\Commands\Issue\AddIssueCommand; |
15
|
|
|
use Gitamin\Dates\DateFactory; |
16
|
|
|
use Gitamin\Events\Issue\IssueWasAddedEvent; |
17
|
|
|
use Gitamin\Models\Issue; |
18
|
|
|
use Gitamin\Models\Project; |
19
|
|
|
|
20
|
|
|
class AddIssueCommandHandler |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The date factory instance. |
24
|
|
|
* |
25
|
|
|
* @var \Gitamin\Dates\DateFactory |
26
|
|
|
*/ |
27
|
|
|
protected $dates; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Create a new report issue command handler instance. |
31
|
|
|
* |
32
|
|
|
* @param \Gitamin\Dates\DateFactory $dates |
33
|
|
|
* |
34
|
|
|
* @return void |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
public function __construct(DateFactory $dates) |
37
|
|
|
{ |
38
|
|
|
$this->dates = $dates; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Handle the report issue command. |
43
|
|
|
* |
44
|
|
|
* @param \Gitamin\Commands\Issue\AddIssueCommand $command |
45
|
|
|
* |
46
|
|
|
* @return \Gitamin\Models\Issue |
47
|
|
|
*/ |
48
|
|
|
public function handle(AddIssueCommand $command) |
49
|
|
|
{ |
50
|
|
|
$data = [ |
51
|
|
|
'title' => $command->title, |
52
|
|
|
'description' => $command->description, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
// Link with the user. |
56
|
|
|
if ($command->author_id) { |
57
|
|
|
$data['author_id'] = $command->author_id; |
58
|
|
|
} |
59
|
|
|
// Link with the project. |
60
|
|
|
if ($command->project_id) { |
61
|
|
|
$data['project_id'] = $command->project_id; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Create the issue |
65
|
|
|
$issue = Issue::create($data); |
66
|
|
|
|
67
|
|
|
event(new IssueWasAddedEvent($issue)); |
68
|
|
|
|
69
|
|
|
return $issue; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.