Completed
Push — master ( 06f45f...113e18 )
by Gusev
11:42
created

Event::getAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace TelegramBot\Api\Events;
4
5
use TelegramBot\Api\Types\Message;
6
use TelegramBot\Api\Types\Update;
7
8
class Event
9
{
10
    /**
11
     * @var \Closure
12
     */
13
    protected $checker;
14
15
    /**
16
     * @var \Closure
17
     */
18
    protected $action;
19
20
    /**
21
     * Event constructor.
22
     *
23
     * @param \Closure $action
24
     * @param \Closure|null $checker
25
     */
26 11
    public function __construct(\Closure $action, \Closure $checker)
27
    {
28 11
        $this->action = $action;
29 11
        $this->checker = $checker;
30 11
    }
31
32
    /**
33
     * @return \Closure
34
     */
35 1
    public function getAction()
36
    {
37 1
        return $this->action;
38
    }
39
40
    /**
41
     * @return \Closure|null
42
     */
43 2
    public function getChecker()
44
    {
45 2
        return $this->checker;
46
    }
47
48
    /**
49
     * @param \TelegramBot\Api\Types\Update
50
     *
51
     * @return mixed
52
     */
53 3
    public function executeChecker(Update $message)
54
    {
55 3
        if (is_callable($this->checker)) {
56 2
            return call_user_func($this->checker, $message);
57
        }
58
59 1
        return false;
60
    }
61
62
    /**
63
     * @param \TelegramBot\Api\Types\Update
64
     *
65
     * @return mixed
66
     */
67 3
    public function executeAction(Update $message)
68
    {
69 3
        if (is_callable($this->action)) {
70 2
            return call_user_func($this->action, $message);
71
        }
72
73 1
        return false;
74
    }
75
}
76