AddIssueCommandHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 11

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 23
rs 9.0857
cc 3
eloc 11
nc 4
nop 1
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 View Code Duplication
class AddIssueCommandHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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