Completed
Push — master ( 040845...784fee )
by Kirill
02:34
created

GitterMessage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getUserFromMessage() 0 9 1
1
<?php
2
/**
3
 * This file is part of Platform package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Karma\System\Gitter;
11
12
use Carbon\Carbon;
13
use Karma\Platform\Io\UserInterface;
14
use Karma\Platform\Io\AbstractMessage;
15
use Karma\Platform\Io\ChannelInterface;
16
17
/**
18
 * Class GitterMessage
19
 * @package Karma\System\Gitter
20
 */
21
class GitterMessage extends AbstractMessage
22
{
23
    /**
24
     * 5 * 60 sec = 5 min
25
     */
26
    protected const MESSAGE_EDIT_TIMEOUT = 5 * 60;
27
28
    /**
29
     * GitterMessage constructor.
30
     * @param ChannelInterface $channel
31
     * @param array $data
32
     */
33
    public function __construct(ChannelInterface $channel, array $data)
34
    {
35
        $user = $this->getUserFromMessage($channel, $data);
36
37
        parent::__construct($channel, $user, $data['id'], $data['html']);
38
39
        $this->createdAt = Carbon::parse($data['sent']);
40
    }
41
42
    /**
43
     * @param ChannelInterface $channel
44
     * @param array $data
45
     * @return UserInterface
46
     */
47
    private function getUserFromMessage(ChannelInterface $channel, array $data): UserInterface
0 ignored issues
show
Unused Code introduced by
The parameter $channel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        /** @var GitterSystem $system */
50
        $system = $this->getChannel()->getSystem();
51
52
        return $system->getUser($data['fromUser'], function () use ($system, $data): UserInterface {
0 ignored issues
show
Bug introduced by
The method getUser() cannot be called from this context as it is declared protected in class Karma\Platform\Io\AbstractSystem.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
53
            return new GitterUser($system, $data['fromUser']);
54
        });
55
    }
56
}
57