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

AsyncTableRegistry   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 2 Features 2
Metric Value
wmc 8
c 6
b 2
f 2
lcom 2
cbo 3
dl 0
loc 67
ccs 23
cts 23
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A get() 0 13 2
A getInstance() 0 9 3
A reset() 0 4 1
A info() 0 4 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