Completed
Push — master ( 28f331...347733 )
by Phecho
03:40
created

UpdateCommentCommandHandler::filter()   A

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
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
34
     */
35
    public function __construct(DateFactory $dates)
36
    {
37
        $this->dates = $dates;
38
    }
39
40
    /**
41
     * Handle the update comment command.
42
     *
43
     * @param \Gitamin\Commands\Comment\UpdateCommentCommand $command
44
     *
45
     * @return \Gitamin\Models\Comment
46
     */
47
    public function handle(UpdateCommentCommand $command)
48
    {
49
        $comment = $command->comment;
50
        $comment->update($this->filter($command));
51
52
        event(new CommentWasUpdatedEvent($comment));
53
54
        return $comment;
55
    }
56
57
    /**
58
     * Filter the command data.
59
     *
60
     * @param \Gitamin\Commands\Comment\UpdateCommentCommand $command
61
     *
62
     * @return array
63
     */
64
    protected function filter(UpdateCommentCommand $command)
65
    {
66
        $params = [
67
            'message' => $command->message,
68
        ];
69
70
        return array_filter($params, function ($val) {
71
            return $val !== null;
72
        });
73
    }
74
}
75