SwooleTable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 7
c 2
b 1
f 0
dl 0
loc 56
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A get() 0 3 1
A getAll() 0 3 1
A add() 0 5 1
1
<?php
2
3
namespace SwooleTW\Http\Table;
4
5
use Swoole\Table;
6
7
class SwooleTable
8
{
9
    /**
10
     * Registered swoole tables.
11
     *
12
     * @var array
13
     */
14
    protected $tables = [];
15
16
    /**
17
     * Add a swoole table to existing tables.
18
     *
19
     * @param string $name
20
     * @param \Swoole\Table $table
21
     *
22
     * @return \SwooleTW\Http\Table\SwooleTable
23
     */
24
    public function add(string $name, Table $table)
25
    {
26
        $this->tables[$name] = $table;
27
28
        return $this;
29
    }
30
31
    /**
32
     * Get a swoole table by its name from existing tables.
33
     *
34
     * @param string $name
35
     *
36
     * @return \Swoole\Table $table
37
     */
38
    public function get(string $name)
39
    {
40
        return $this->tables[$name] ?? null;
41
    }
42
43
    /**
44
     * Get all existing swoole tables.
45
     *
46
     * @return array
47
     */
48
    public function getAll()
49
    {
50
        return $this->tables;
51
    }
52
53
    /**
54
     * Dynamically access table.
55
     *
56
     * @param  string $key
57
     *
58
     * @return table
59
     */
60
    public function __get($key)
61
    {
62
        return $this->get($key);
63
    }
64
}
65