ConfigAwareTrait::prepareConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace League\Flysystem;
4
5
/**
6
 * @internal
7
 */
8
trait ConfigAwareTrait
9
{
10
    /**
11
     * @var Config
12
     */
13
    protected $config;
14
15
    /**
16
     * Set the config.
17
     *
18
     * @param Config|array|null $config
19
     */
20
    protected function setConfig($config)
21
    {
22
        $this->config = $config ? Util::ensureConfig($config) : null;
23
    }
24
25
    /**
26
     * Get the Config.
27
     *
28
     * @return Config config object
29
     */
30
    public function getConfig()
31
    {
32
        if ($this->config === null) {
33
            return $this->config = new Config;
34
        }
35
36
        return $this->config;
37
    }
38
39
    /**
40
     * Convert a config array to a Config object with the correct fallback.
41
     *
42
     * @param array $config
43
     *
44
     * @return Config
45
     */
46
    protected function prepareConfig(array $config)
47
    {
48
        $config = new Config($config);
49
        $config->setFallback($this->getConfig());
50
51
        return $config;
52
    }
53
}
54