Passed
Push — master ( 5a87d9...5af04f )
by Mihail
03:04
created

ConfigFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
build() 0 11 ?
A hp$0 ➔ build() 0 11 3
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Caching\Configuration;
14
15
use Koded\Stdlib\{Arguments, Config};
16
use Koded\Caching\CacheException;
17
use Koded\Stdlib\Interfaces\Configuration;
18
use Throwable;
19
20
/**
21
 * Class ConfigFactory
22
 *
23
 * @property int|null $ttl Default Time-To-Live seconds for the cached items
24
 *
25
 */
26
class ConfigFactory extends Config
27
{
28 1569
    public function __construct(array $parameters = [])
29
    {
30 1569
        parent::__construct();
31 1569
        $this->import($parameters);
32 1569
    }
33
34 1569
    public function build(string $context): Configuration
35
    {
36
        try {
37 1569
            $class = join('\\', [__NAMESPACE__, ucfirst($context) . 'Configuration']);
38 1569
            return new $class($this->toArray());
39
        // @codeCoverageIgnoreStart
40
        } catch (CacheException $e) {
41
            throw $e;
42
        // @codeCoverageIgnoreEnd
43 377
        } catch (Throwable $e) {
44
            return new class($this->toArray()) extends Arguments implements Configuration {};
45
        }
46
    }
47
}
48