Exceptions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A selectWait() 0 13 4
A happened() 0 3 1
1
<?php
2
/**
3
 * Pool exceptions counter
4
 * User: moyo
5
 * Date: 2018/6/11
6
 * Time: 3:34 PM
7
 */
8
9
namespace Carno\Pool;
10
11
use Carno\Pool\Exception\SelectWaitOverflowException;
12
use Carno\Pool\Exception\SelectWaitTimeoutException;
13
14
class Exceptions
15
{
16
    /**
17
     * SelectWaitTimeout
18
     */
19
    public const SW_TIMEOUT = 0xE1;
20
21
    /**
22
     * SelectWaitOverflow
23
     */
24
    public const SW_OVERFLOW = 0xE2;
25
26
    /**
27
     * @var array
28
     */
29
    private static $happens = [];
30
31
    /**
32
     * @param string $type
33
     * @param string $identify
34
     */
35
    public static function selectWait(string $type, string $identify) : void
36
    {
37
        switch ($type) {
38
            case SelectWaitTimeoutException::class:
39
                $slot = self::SW_TIMEOUT;
40
                break;
41
            case SelectWaitOverflowException::class:
42
                $slot = self::SW_OVERFLOW;
43
                break;
44
        }
45
46
        if (isset($slot)) {
47
            self::$happens[$slot][$identify] = (self::$happens[$slot][$identify] ?? 0) + 1;
48
        }
49
    }
50
51
    /**
52
     * @param string $identify
53
     * @param string $type
54
     * @return int
55
     */
56
    public static function happened(string $identify, string $type) : int
57
    {
58
        return self::$happens[$type][$identify] ?? 0;
59
    }
60
}
61