WorkermanFastCGIWrapper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A start() 0 5 1
A onWorkerStart() 0 8 1
A onReceive() 0 5 1
A requestCallback() 0 4 1
A sendCallback() 0 4 1
A closeCallback() 0 4 1
1
<?php
2
namespace Laravoole\Wrapper;
3
4
use Laravoole\Workerman\Worker;
5
use Garveen\FastCgi\FastCgi;
6
7
class WorkermanFastCGIWrapper extends Workerman implements ServerInterface
8
{
9 4
    public function __construct($host, $port)
10
    {
11 4
        parent::__construct($host, $port);
12 4
        $this->server = new Worker("tcp://{$host}:{$port}");
13 4
    }
14
15 4
    public function start()
16
    {
17 4
        $this->on('Receive', [$this, 'onReceive']);
18 4
        return parent::start();
19
    }
20
21 4
    public function onWorkerStart($worker)
22
    {
23 4
        $worker->log("Workerman worker {$worker->id} starting\n");
24 4
        parent::onWorkerStart($worker);
25 4
        $this->fastcgi = new FastCgi([$this, 'requestCallback'], [$this, 'sendCallback'], [$this, 'closeCallback'], function($level, $info) use ($worker) {
0 ignored issues
show
Bug introduced by
The property fastcgi does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26 4
            $worker->log("$level $info");
27 4
        });
28 4
    }
29
30 4
    public function onReceive($connection, $data)
31
    {
32 4
        $this->connections[$connection->id]['connection'] = $connection;
0 ignored issues
show
Bug introduced by
The property connections does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33 4
        return $this->fastcgi->receive($connection->id, $data);
34
    }
35
36 4
    public function requestCallback($psrRequest)
37
    {
38 4
        return $this->onPsrRequest($psrRequest);
39
    }
40
41 4
    public function sendCallback($fd, $payload)
42
    {
43 4
        $this->send($fd, $payload);
44 4
    }
45
46 4
    public function closeCallback($fd)
47
    {
48 4
        $this->close($fd);
49 4
    }
50
51
}
52