Event   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 58
ccs 12
cts 12
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 3 1
A getChecker() 0 3 1
A __construct() 0 4 1
A executeAction() 0 3 1
A executeChecker() 0 7 2
1
<?php
2
3
namespace TelegramBot\Api\Events;
4
5
use TelegramBot\Api\Types\Update;
6
7
class Event
8
{
9
    /**
10
     * @var \Closure|null
11
     */
12
    protected $checker;
13
14
    /**
15
     * @var \Closure
16
     */
17
    protected $action;
18
19
    /**
20
     * Event constructor.
21
     *
22
     * @param \Closure $action
23
     * @param \Closure|null $checker
24
     */
25
    public function __construct(\Closure $action, \Closure $checker = null)
26 11
    {
27
        $this->action = $action;
28 11
        $this->checker = $checker;
29 11
    }
30 11
31
    /**
32
     * @return \Closure
33
     */
34
    public function getAction()
35 1
    {
36
        return $this->action;
37 1
    }
38
39
    /**
40
     * @return \Closure|null
41
     */
42
    public function getChecker()
43 2
    {
44
        return $this->checker;
45 2
    }
46
47
    /**
48
     * @return mixed
49
     */
50
    public function executeChecker(Update $message)
51
    {
52
        if (is_callable($this->checker)) {
53 3
            return call_user_func($this->checker, $message);
0 ignored issues
show
Bug introduced by
It seems like $this->checker can also be of type null; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
            return call_user_func(/** @scrutinizer ignore-type */ $this->checker, $message);
Loading history...
54
        }
55 3
56 2
        return false;
57
    }
58
59 1
    /**
60
     * @return mixed
61
     */
62
    public function executeAction(Update $message)
63
    {
64
        return call_user_func($this->action, $message);
65
    }
66
}
67