SwooleTable::getAll()   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 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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