Completed
Pull Request — master (#42)
by Hiraku
02:14
created

Config::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
/*
3
 * hirak/prestissimo
4
 * @author Hiraku NAKANO
5
 * @license MIT https://github.com/hirak/prestissimo
6
 */
7
namespace Hirak\Prestissimo;
8
9
use JsonSchema;
10
11
class Config
12
{
13
    protected $config;
14
15
    private $default = array(
16
        'maxConnections' => 6,
17
        'minConnections' => 3,
18
        'pipeline' => false,
19
        'verbose' => false,
20
        'insecure' => false,
21
        'userAgent' => '',
22
        'capath' => '',
23
        'privatePackages' => array(),
24
    );
25
26 3
    public function __construct(array $config)
27
    {
28 3
        $config += $this->default;
29 3
        $schema = file_get_contents(__DIR__ . '/../res/config-schema.json');
30 3
        $validator = new JsonSchema\Validator;
31 3
        $validator->check((object)$config, json_decode($schema));
32
33 3
        if (! $validator->isValid()) {
34 1
            throw new \InvalidArgumentException(var_export($validator->getErrors(), true));
35
        }
36
37 2
        $this->config = $config;
38 2
    }
39
40 1
    public function get()
41
    {
42 1
        return $this->config;
43
    }
44
}
45