Completed
Pull Request — develop (#27)
by Chris
01:54
created

Config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 18 4
A getData() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <https://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Chrisyue\PhpM3u8;
13
14
class Config
15
{
16
    private $data;
17
18
    public function __construct(array $data)
19
    {
20
        $this->data = $data;
21
    }
22
23
    public function get($key, $default = null)
24
    {
25
        if (!is_string($key)) {
26
            throw new \InvalidArgumentException(
27
                sprintf('$key can only be string, got %s', var_export($key, true)
28
            ));
29
        }
30
31
        if (!array_key_exists($key, $this->data)) {
32
            if (null === $default) {
33
                throw new \OutOfBoundsException(sprintf('Unknown config "%s"', $key));
34
            }
35
36
            return $default;
37
        }
38
39
        return $this->data[$key];
40
    }
41
42
    protected function getData()
43
    {
44
        return $this->data;
45
    }
46
}
47