Completed
Push — master ( ad721e...9c02d3 )
by Garveen
04:01
created

Server   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 68.75%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
dl 0
loc 33
ccs 11
cts 16
cp 0.6875
rs 10
c 7
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getWrapper() 0 4 1
A start() 0 7 1
A __construct() 0 12 3
1
<?php
2
namespace Laravoole;
3
4
use Exception;
5
use ReflectionClass;
6
7
use Laravoole\Wrapper\ServerInterface;
8
9
class Server
10
{
11
    protected $wrapper;
12
13
    protected $startingCallbacks = [];
14
15 20
    public function __construct($wrapper, $wrapper_file = '')
16
    {
17 20
        if (!class_exists($wrapper)) {
18
            require $wrapper_file;
19
        }
20 20
        $ref = new ReflectionClass($wrapper);
21 20
        if(!$ref->implementsInterface(ServerInterface::class)) {
22
            throw new Exception("$wrapper must be instance of Laravoole\\Wrapper\\ServerInterface", 1);
23
        }
24
25 20
        $this->wrapper = $wrapper;
26 20
    }
27
28
    public function getWrapper()
29
    {
30
        return $this->wrapper;
31
    }
32
33 20
    public function start($configs)
34
    {
35 20
        require __DIR__ . '/Mime.php';
36 20
        $wrapper = new $this->wrapper($configs['host'], $configs['port']);
37 20
        $wrapper->init($configs);
38 20
        return $wrapper->start();
39
    }
40
41
}
42