FtpdAdapterFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 26
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doCreateService() 4 4 1
A validateConfig() 18 18 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * BsbFlystem
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @see       https://bushbaby.nl/
10
 *
11
 * @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl)
12
 * @author    Bas Kamer <[email protected]>
13
 * @license   MIT
14
 *
15
 * @package   bushbaby/flysystem
16
 */
17
18
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21
22
use BsbFlysystem\Exception\UnexpectedValueException;
23
use League\Flysystem\Adapter\Ftpd as Adapter;
24
use League\Flysystem\AdapterInterface;
25
use Psr\Container\ContainerInterface;
26
27 View Code Duplication
class FtpdAdapterFactory extends AbstractAdapterFactory
28
{
29
    public function doCreateService(ContainerInterface $container): AdapterInterface
30
    {
31
        return new Adapter($this->options);
32
    }
33
34
    protected function validateConfig(): void
35
    {
36
        if (! isset($this->options['host'])) {
37
            throw new UnexpectedValueException("Missing 'host' as option");
38
        }
39
40
        if (! isset($this->options['port'])) {
41
            throw new UnexpectedValueException("Missing 'port' as option");
42
        }
43
44
        if (! isset($this->options['username'])) {
45
            throw new UnexpectedValueException("Missing 'username' as option");
46
        }
47
48
        if (! isset($this->options['password'])) {
49
            throw new UnexpectedValueException("Missing 'password' as option");
50
        }
51
    }
52
}
53