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

ConfigFactory.php$0 ➔ build()   A

Complexity

Conditions 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 11
ccs 4
cts 4
cp 1
crap 3
rs 9.9
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