Timer::getCallback()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Thruster\Component\EventLoop;
4
5
/**
6
 * Class Timer
7
 *
8
 * @package Thruster\Component\EventLoop
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
class Timer
12
{
13
    /**
14
     * @var EventLoop
15
     */
16
    protected $loop;
17
18
    /**
19
     * @var float
20
     */
21
    protected $interval;
22
23
    /**
24
     * @var callable
25
     */
26
    protected $callback;
27
28
    /**
29
     * @var bool
30
     */
31
    protected $periodic;
32
33
    /**
34
     * @var int
35
     */
36
    protected $priority;
37
38
    public function __construct(
39
        EventLoop $loop,
40
        $interval,
41
        callable $callback,
42
        bool $periodic = false,
43
        int $priority = 0
44
    ) {
45
        $this->loop = $loop;
46
        $this->interval = (float) $interval;
47
        $this->callback = $callback;
48
        $this->periodic = $periodic;
49
        $this->priority = $priority;
50
    }
51
52
    /**
53
     * @return EventLoop
54
     */
55
    public function getLoop()
56
    {
57
        return $this->loop;
58
    }
59
60
    /**
61
     * @return float
62
     */
63
    public function getInterval()
64
    {
65
        return $this->interval;
66
    }
67
68
    /**
69
     * @return callable
70
     */
71
    public function getCallback()
72
    {
73
        return $this->callback;
74
    }
75
76
    /**
77
     * @return boolean
78
     */
79
    public function isPeriodic()
80
    {
81
        return $this->periodic;
82
    }
83
84
    /**
85
     * @return int
86
     */
87
    public function getPriority()
88
    {
89
        return $this->priority;
90
    }
91
92
    public function cancel()
93
    {
94
        $this->loop->cancelTimer($this);
95
    }
96
}
97