FtpAdapterFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 26
loc 26
ccs 7
cts 7
cp 1
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 1
 *
15
 * @package   bushbaby/flysystem
16 1
 */
17
18 1
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21 6
22
use BsbFlysystem\Exception\UnexpectedValueException;
23 6
use League\Flysystem\Adapter\Ftp as Adapter;
24 1
use League\Flysystem\AdapterInterface;
25
use Psr\Container\ContainerInterface;
26
27 5 View Code Duplication
class FtpAdapterFactory extends AbstractAdapterFactory
28 1
{
29
    public function doCreateService(ContainerInterface $container): AdapterInterface
30
    {
31 4
        return new Adapter($this->options);
32 1
    }
33
34
    protected function validateConfig(): void
35 3
    {
36 1
        if (! isset($this->options['host'])) {
37
            throw new UnexpectedValueException("Missing 'host' as option");
38 2
        }
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