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

Config   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A get() 0 4 1
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