Ftp::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 4
Ratio 16 %

Importance

Changes 0
Metric Value
dl 4
loc 25
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
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 View Code Duplication
        if ($missingSettings = array_diff($requiredSettings, array_keys($vaultConfiguration->getSettings())))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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