Completed
Pull Request — master (#1)
by Westin
16:17 queued 06:16
created

FileSystemConfig::isManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11FlySystem\Config;
5
6
use WShafer\PSR11FlySystem\Exception\MissingConfigException;
7
8
class FileSystemConfig
9
{
10
    /** @var array  */
11
    protected $fileSystems = [];
12
13
    /** @var array  */
14
    protected $config = [];
15
16
    /**
17
     * FileSystemConfig constructor.
18
     *
19
     * @param array $config
20
     */
21 14
    public function __construct(array $config)
22
    {
23 14
        $this->config = $config;
24 13
25
        if ($this->isManager()) {
26 13
            $this->buildManagerFileSystemConfigs();
27 3
        }
28
    }
29 12
30
    /**
31
     * Get the adaptor
32
     *
33
     * @return string
34
     */
35
    public function getAdaptor()
36 14
    {
37
        return $this->config['adaptor'] ?? 'default';
38 14
    }
39 1
40 1
    /**
41
     * Get the cache
42
     *
43
     * @return string
44 13
     */
45 1
    public function getCache()
46 1
    {
47
        return $this->config['cache'] ?? 'default';
48
    }
49 13
50
    /**
51
     * Get the plugins
52
     *
53
     * @return array
54
     */
55
    public function getPlugins()
56 13
    {
57
        return $this->config['plugins'] ?? [];
58 13
    }
59
60
    /**
61
     * Is this defined as a file manager?
62
     *
63
     * @return bool
64
     */
65
    public function isManager()
66 1
    {
67
        if ($this->getAdaptor() == 'manager') {
68 1
            return true;
69
        }
70
71
        return false;
72
    }
73
74
    /**
75
     * Get the configured File Systems.
76 1
     * Used for manager configuration
77
     *
78 1
     * @return FileSystemConfig[]
79
     */
80
    public function getFileSystems()
81
    {
82
        return $this->fileSystems;
83
    }
84
85
    /**
86 13
     * Build out the file system configs for use
87
     * by the manager.
88 13
     */
89 3
    protected function buildManagerFileSystemConfigs()
90
    {
91
        if (empty($this->config['fileSystems'])) {
92 12
            throw new MissingConfigException(
93
                'Missing file systems for manager'
94
            );
95
        }
96
97
        foreach ($this->config['fileSystems'] as $name => $fileSystem) {
98
            $this->fileSystems[$name] = new self($fileSystem);
99
        }
100
    }
101
}
102