Completed
Push — master ( 44ea6a...ba5abe )
by Cees-Jan
04:55
created

AsyncTableRegistry::info()   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 1
Metric Value
c 1
b 0
f 1
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 WyriHaximus\React\Cake\Orm;
4
5
use Cake\Core\App;
6
use React\EventLoop\LoopInterface;
7
use WyriHaximus\React\ChildProcess\Pool\PoolUtilizerInterface;
8
9
class AsyncTableRegistry implements PoolUtilizerInterface
10
{
11
    /**
12
     * @var AsyncTable[]
13
     */
14
    protected static $tables = [];
15
16
    /**
17
     * @var AsyncTableRegistry
18
     */
19
    protected static $instance = null;
20
21
    /**
22
     * @var boolean
23
     */
24
    protected static $reset = false;
25
26
    /**
27
     * @param LoopInterface $loop
28
     */
29 2
    public static function init(LoopInterface $loop)
30
    {
31 2
        Pool::getInstance($loop);
32 2
    }
33
34
    /**
35
     * @param $tableName
36
     *
37
     * @return AsyncTable
38
     */
39 1
    public static function get($tableName)
40
    {
41 1
        if (isset(static::$tables[$tableName])) {
42 1
            return static::$tables[$tableName];
43
        }
44
45 1
        static::$tables[$tableName] = new AsyncTable(
46 1
            Pool::getInstance(),
47 1
            $tableName,
48 1
            App::className($tableName, 'Model/Table', 'Table')
49 1
        );
50 1
        return static::$tables[$tableName];
51
    }
52
53 4
    public static function getInstance()
54
    {
55 4
        if (null === self::$instance || self::$reset) {
56 4
            self::$instance = new static();
57 4
            self::$reset = false;
58 4
        }
59
60 4
        return self::$instance;
61
    }
62
63 23
    public static function reset()
64
    {
65 23
        self::$reset = true;
66 23
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 1
    public function info()
72
    {
73 1
        return Pool::getInstance()->info();
74
    }
75
}
76