Completed
Branch master (9dff9d)
by Albert
05:30
created

InteractsWithSwooleTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerTables() 0 17 4
A bindSwooleTable() 0 6 1
A createTables() 0 4 1
1
<?php
2
3
namespace SwooleTW\Http\Concerns;
4
5
use Swoole\Table;
6
use SwooleTW\Http\Table\SwooleTable;
7
8
trait InteractsWithSwooleTable
9
{
10
    /**
11
     * @var \SwooleTW\Http\Server\Table
0 ignored issues
show
Bug introduced by
The type SwooleTW\Http\Server\Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
     */
13
    protected $table;
14
15
    /**
16
     * Register customized swoole talbes.
17
     */
18
    protected function createTables()
19
    {
20
        $this->table = new SwooleTable;
0 ignored issues
show
Documentation Bug introduced by
It seems like new SwooleTW\Http\Table\SwooleTable() of type SwooleTW\Http\Table\SwooleTable is incompatible with the declared type SwooleTW\Http\Server\Table of property $table.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
        $this->registerTables();
22
    }
23
24
    /**
25
     * Register user-defined swoole tables.
26
     */
27
    protected function registerTables()
28
    {
29
        $tables = $this->container['config']->get('swoole_http.tables', []);
30
31
        foreach ($tables as $key => $value) {
32
            $table = new Table($value['size']);
33
            $columns = $value['columns'] ?? [];
34
            foreach ($columns as $column) {
35
                if (isset($column['size'])) {
36
                    $table->column($column['name'], $column['type'], $column['size']);
37
                } else {
38
                    $table->column($column['name'], $column['type']);
39
                }
40
            }
41
            $table->create();
42
43
            $this->table->add($key, $table);
44
        }
45
    }
46
47
    /**
48
     * Bind swoole table to Laravel app container.
49
     */
50
    protected function bindSwooleTable()
51
    {
52
        $this->app->singleton(SwooleTable::class, function () {
53
            return $this->table;
54
        });
55
        $this->app->alias(SwooleTable::class, 'swoole.table');
56
    }
57
}
58