Stats::hooking()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Promise stats
4
 * User: moyo
5
 * Date: 13/03/2018
6
 * Time: 3:50 PM
7
 */
8
9
namespace Carno\Promise;
10
11
use Closure;
12
13
final class Stats
14
{
15
    /**
16
     * actions
17
     */
18
    public const PROPOSED = 0x1;
19
    public const CONFIRMED = 0x2;
20
21
    /**
22
     * @var int
23
     */
24
    private static $pending = 0;
25
26
    /**
27
     * @var Closure
28
     */
29
    private static $observer = null;
30
31
    /**
32
     * @return int
33
     */
34
    public static function pending() : int
35
    {
36
        return self::$pending;
37
    }
38
39
    /**
40
     * @param Closure $set
41
     */
42
    public static function hooking(?Closure $set) : void
43
    {
44
        self::$observer = $set;
45
    }
46
47
    /**
48
     * @param Promised $ins
49
     */
50
    public static function proposed(Promised $ins) : void
51
    {
52
        self::$pending++;
53
        self::$observer && (self::$observer)(self::PROPOSED, $ins);
54
    }
55
56
    /**
57
     * @param Promised $ins
58
     */
59
    public static function confirmed(Promised $ins) : void
60
    {
61
        self::$pending--;
62
        self::$observer && (self::$observer)(self::CONFIRMED, $ins);
63
    }
64
}
65