UpdateCommentCommandHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 9 1
A filter() 0 10 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\Comment;
13
14
use Gitamin\Commands\Comment\UpdateCommentCommand;
15
use Gitamin\Dates\DateFactory;
16
use Gitamin\Events\Comment\CommentWasUpdatedEvent;
17
use Gitamin\Models\Comment;
18
19
class UpdateCommentCommandHandler
20
{
21
    /**
22
     * The date factory instance.
23
     *
24
     * @var \Gitamin\Dates\DateFactory
25
     */
26
    protected $dates;
27
28
    /**
29
     * Create a new update comment 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 comment command.
40
     *
41
     * @param \Gitamin\Commands\Comment\UpdateCommentCommand $command
42
     *
43
     * @return \Gitamin\Models\Comment
44
     */
45
    public function handle(UpdateCommentCommand $command)
46
    {
47
        $comment = $command->comment;
48
        $comment->update($this->filter($command));
49
50
        event(new CommentWasUpdatedEvent($comment));
51
52
        return $comment;
53
    }
54
55
    /**
56
     * Filter the command data.
57
     *
58
     * @param \Gitamin\Commands\Comment\UpdateCommentCommand $command
59
     *
60
     * @return array
61
     */
62
    protected function filter(UpdateCommentCommand $command)
63
    {
64
        $params = [
65
            'message' => $command->message,
66
        ];
67
68
        return array_filter($params, function ($val) {
69
            return $val !== null;
70
        });
71
    }
72
}
73