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
     * @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

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