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

anonymous//Configuration/ConfigFactory.php$0

Complexity

Total Complexity 0

Size/Duplication

Total Lines 1
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
wmc 0
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