UpdateIssueCommandHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 0
cbo 3
dl 0
loc 69
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 13 1
A handle() 0 21 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\UpdateIssueCommand;
15
use Gitamin\Dates\DateFactory;
16
use Gitamin\Events\Issue\IssueWasUpdatedEvent;
17
use Gitamin\Models\Issue;
18
19
class UpdateIssueCommandHandler
20
{
21
    /**
22
     * The date factory instance.
23
     *
24
     * @var \Gitamin\Dates\DateFactory
25
     */
26
    protected $dates;
27
28
    /**
29
     * Create a new update issue 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 update issue command.
40
     *
41
     * @param \Gitamin\Commands\Issue\UpdateIssueCommand $command
42
     *
43
     * @return \Gitamin\Models\Issue
44
     */
45
    public function handle(UpdateIssueCommand $command)
46
    {
47
        $issue = $command->issue;
48
        $issue->update($this->filter($command));
49
50
        // The issue occurred at a different time.
51
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
52
        if ($command->issue_date) {
53
            $issueDate = $this->dates->createNormalized('d/m/Y H:i', $command->issue_date);
54
55
            $issue->update([
56
                'created_at' => $issueDate,
57
                'updated_at' => $issueDate,
58
            ]);
59
        }
60
        */
61
62
        event(new IssueWasUpdatedEvent($issue));
63
64
        return $issue;
65
    }
66
67
    /**
68
     * Filter the command data.
69
     *
70
     * @param \Gitamin\Commands\Issue\UpdateIssueCommand $command
71
     *
72
     * @return array
73
     */
74
    protected function filter(UpdateIssueCommand $command)
75
    {
76
        $params = [
77
            'title' => $command->title,
78
            'description' => $command->description,
79
            'author_id' => $command->author_id,
80
            'project_id' => $command->project_id,
81
        ];
82
83
        return array_filter($params, function ($val) {
84
            return $val !== null;
85
        });
86
    }
87
}
88