FtpFactory::build()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
crap 2.032
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage\Factories;
18
19
use League\Flysystem\AdapterInterface;
20
use League\Flysystem\Adapter\Ftp;
21
22
/**
23
 * FtpFactory
24
 */
25
class FtpFactory extends AbstractFactory
26
{
27
    protected string $alias = 'ftp';
28
    protected ?string $package = 'league/flysystem';
29
    protected string $className = Ftp::class;
30
    protected array $defaults = [
31
        'host' => '',
32
        'username' => '',
33
        'password' => '',
34
        // Optional settings
35
        'port' => 21,
36
        'root' => '/',
37
        'passive' => true,
38
        'ssl' => true,
39
        'timeout' => 30,
40
        'ignorePassiveAddress' => false,
41
    ];
42
43
    /**
44
     * @inheritDoc
45
     */
46 1
    public function build(array $config): AdapterInterface
47
    {
48 1
        if (!defined('FTP_BINARY')) {
49
            define('FTP_BINARY', 'ftp.exe');
50
        }
51
52 1
        $config += $this->defaults;
53
54 1
        return new Ftp($config);
55
    }
56
}
57