Completed
Pull Request — develop (#27)
by Chris
05:29
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
namespace Chrisyue\PhpM3u8;
4
5
class Config
6
{
7
    private $data;
8
9
    public function __construct(array $data)
10
    {
11
        $this->data = $data;
12
    }
13
14
    public function get($key, $default = null)
15
    {
16
        if (!is_string($key)) {
17
            throw new \InvalidArgumentException(
18
                sprintf('$key can only be string, got %s', var_export($key, true)
19
            ));
20
        }
21
22
        if (!array_key_exists($key, $this->data)) {
23
            if (null === $default) {
24
                throw new \OutOfBoundsException(sprintf('Unknown config "%s"', $key));
25
            }
26
27
            return $default;
28
        }
29
30
        return $this->data[$key];
31
    }
32
33
    protected function getData()
34
    {
35
        return $this->data;
36
    }
37
}
38