Code Duplication    Length = 52-53 lines in 2 locations

app/Handlers/Commands/Issue/AddIssueCommandHandler.php 1 location

@@ 20-71 (lines=52) @@
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
    public function __construct(DateFactory $dates)
35
    {
36
        $this->dates = $dates;
37
    }
38
39
    /**
40
     * Handle the report issue command.
41
     *
42
     * @param \Gitamin\Commands\Issue\AddIssueCommand $command
43
     *
44
     * @return \Gitamin\Models\Issue
45
     */
46
    public function handle(AddIssueCommand $command)
47
    {
48
        $data = [
49
            'title' => $command->title,
50
            'description' => $command->description,
51
        ];
52
53
        // Link with the user.
54
        if ($command->author_id) {
55
            $data['author_id'] = $command->author_id;
56
        }
57
        // Link with the project.
58
        if ($command->project_id) {
59
            $data['project_id'] = $command->project_id;
60
        }
61
62
        // Create the issue
63
        $issue = Issue::create($data);
64
65
        event(new IssueWasAddedEvent($issue));
66
67
        return $issue;
68
    }
69
}
70

app/Handlers/Commands/Comment/AddCommentCommandHandler.php 1 location

@@ 20-72 (lines=53) @@
17
use Gitamin\Models\Comment;
18
use Gitamin\Models\Project;
19
20
class AddCommentCommandHandler
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
    public function __construct(DateFactory $dates)
35
    {
36
        $this->dates = $dates;
37
    }
38
39
    /**
40
     * Handle the report comment command.
41
     *
42
     * @param \Gitamin\Commands\Comment\AddCommentCommand $command
43
     *
44
     * @return \Gitamin\Models\Comment
45
     */
46
    public function handle(AddCommentCommand $command)
47
    {
48
        $data = [
49
            'message' => $command->message,
50
            'target_type' => $command->target_type,
51
            'target_id' => $command->target_id,
52
        ];
53
54
        // Link with the user.
55
        if ($command->author_id) {
56
            $data['author_id'] = $command->author_id;
57
        }
58
        // Link with the project.
59
        if ($command->project_id) {
60
            $data['project_id'] = $command->project_id;
61
        }
62
63
        // Create the comment
64
        $comment = Comment::create($data);
65
66
        event(new CommentWasAddedEvent($comment));
67
68
        return $comment;
69
    }
70
}
71