Master   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addListener() 0 13 3
1
<?php
2
3
namespace mpyw\HyperBuiltinServer;
4
use mpyw\HyperBuiltinServer\Internal\ConnectionHandler;
5
use mpyw\HyperBuiltinServer\Internal\Queue;
6
use React\EventLoop\LoopInterface;
7
use React\Socket\Server;
8
9
class Master
10
{
11
    public $loop;
12
    public $queue;
13
14
    public function __construct(LoopInterface $loop, array $processes)
15
    {
16
        $this->loop = $loop;
17
        $this->queue = new Queue($processes);
18
    }
19
20
    public function addListener($host = '127.0.0.1', $port = 8080, $use_ssl = false, $cert = null)
21
    {
22
        $proxy = new Server($this->loop);
23
        $proxy->on('connection', new ConnectionHandler($this));
24
        $context = !$use_ssl ? [] : [
25
            'ssl' => [
26
                'local_cert' => $cert === null ? (__DIR__ . '/../certificate.pem') : $cert,
27
                'allow_self_signed' => true,
28
                'verify_peer' => false,
29
            ],
30
        ];
31
        $proxy->listen($port, $host, $context);
32
    }
33
}
34