Completed
Pull Request — master (#42)
by Florent
12:58
created

FtpAdapterFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 64.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 18
loc 28
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

2 Methods

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

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
declare(strict_types=1);
4
5
namespace BsbFlysystem\Adapter\Factory;
6
7
use BsbFlysystem\Exception\UnexpectedValueException;
8
use League\Flysystem\Adapter\Ftp as Adapter;
9
use League\Flysystem\AdapterInterface;
10
use Psr\Container\ContainerInterface;
11
12
class FtpAdapterFactory extends AbstractAdapterFactory
13
{
14
    public function doCreateService(ContainerInterface $container): AdapterInterface
15
    {
16
        $adapter = new Adapter($this->options);
17
18
        return $adapter;
19
    }
20
21 5 View Code Duplication
    protected function validateConfig()
22
    {
23 5
        if (! isset($this->options['host'])) {
24 1
            throw new UnexpectedValueException("Missing 'host' as option");
25
        }
26
27 4
        if (! isset($this->options['port'])) {
28 1
            throw new UnexpectedValueException("Missing 'port' as option");
29
        }
30
31 3
        if (! isset($this->options['username'])) {
32 1
            throw new UnexpectedValueException("Missing 'username' as option");
33
        }
34
35 2
        if (! isset($this->options['password'])) {
36 1
            throw new UnexpectedValueException("Missing 'password' as option");
37
        }
38 1
    }
39
}
40