Completed
Push — master ( 1d14da...d37c28 )
by Arne
02:16
created

Ftp::getIdentificationString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Storeman\StorageAdapter;
4
5
use League\Flysystem\Filesystem;
6
use Storeman\Config\ConfigurationException;
7
use Storeman\Config\VaultConfiguration;
8
9
class Ftp extends FlysystemStorageAdapter
10
{
11
    public function __construct(VaultConfiguration $vaultConfiguration)
12
    {
13
        $requiredSettings = [
14
            'host',
15
            'username',
16
            'password',
17
        ];
18
19
        $defaults = [
20
            'port' => 21,
21
        ];
22
23
        if ($missingSettings = array_diff($requiredSettings, array_keys($vaultConfiguration->getSettings())))
24
        {
25
            throw new ConfigurationException("Missing mandatory setting(s): " . implode(',', $missingSettings));
26
        }
27
28
        $settings = array_merge($defaults, $vaultConfiguration->getSettings());
29
30
        // atm unknown settings
31
        $adapter = new \League\Flysystem\Adapter\Ftp($settings);
32
        $filesystem = new Filesystem($adapter);
33
34
        parent::__construct($filesystem);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function getIdentificationString(VaultConfiguration $vaultConfiguration): string
41
    {
42
        return "{$vaultConfiguration->getSetting('username')}@{$vaultConfiguration->getSetting('host')}";
43
    }
44
}
45