WorkermanFastCGIWrapper::start()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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