UpdateCommentCommandHandler::filter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 1
eloc 5
nc 1
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\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