Completed
Push — master ( a8c5d7...b64b96 )
by Arne
02:19
created

LocalStorageAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 4
A getIdentificationString() 0 4 1
1
<?php
2
3
namespace Storeman\StorageAdapter;
4
5
use Storeman\Config\ConfigurationException;
6
use Storeman\PathUtils;
7
use Storeman\Config\VaultConfiguration;
8
use League\Flysystem\Adapter\Local;
9
use League\Flysystem\Filesystem;
10
11
class LocalStorageAdapter extends FlysystemStorageAdapter
12
{
13
    public function __construct(VaultConfiguration $vaultConfiguration)
14
    {
15
        if (!($path = $vaultConfiguration->getSetting('path')))
16
        {
17
            throw new ConfigurationException("Missing vault config setting 'path' for vault '{$vaultConfiguration->getTitle()}'.'");
18
        }
19
20
        $path = PathUtils::getAbsolutePath($path);
21
22
        if (!is_dir($path) || !is_writable($path))
23
        {
24
            throw new ConfigurationException(sprintf('Path "%s" does not exist or is not writable.', $path));
25
        }
26
27
        $adapter = new Local($path);
28
        $filesystem = new Filesystem($adapter);
29
30
        parent::__construct($filesystem);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public static function getIdentificationString(VaultConfiguration $vaultConfiguration): string
37
    {
38
        return $vaultConfiguration->getSetting('path');
39
    }
40
}
41