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

Server::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.3332

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 4
nop 2
dl 0
loc 12
ccs 6
cts 9
cp 0.6667
crap 3.3332
rs 9.4285
c 4
b 0
f 0
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