Event::getChecker()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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