Server::start()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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