Completed
Pull Request — develop (#27)
by Chris
05:29
created

Config::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 2
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