AbstractDsnAdapterFactory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 44.83 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 26
loc 58
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDsn() 0 4 1
A configureOptionResolver() 0 5 1
A validate() 13 13 3
A createAdapter() 13 13 3

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
 * This file is part of php-cache organization.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\AdapterBundle\Factory;
13
14
use Cache\AdapterBundle\DSN;
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
17
/**
18
 * @author Aaron Scherer <[email protected]>
19
 */
20
abstract class AbstractDsnAdapterFactory extends AbstractAdapterFactory
21
{
22
    /**
23
     * @var DSN
24
     */
25
    private $DSN;
26
27
    /**
28
     * @return DSN
29
     */
30 2
    protected function getDsn()
31
    {
32 2
        return $this->DSN;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    protected static function configureOptionResolver(OptionsResolver $resolver)
39
    {
40 3
        $resolver->setDefaults(['dsn' => '']);
41 3
        $resolver->setAllowedTypes('dsn', ['string']);
42 3
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 3 View Code Duplication
    public static function validate(array $options, $adapterName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
48
    {
49 3
        parent::validate($options, $adapterName);
50
51 3
        if (empty($options['dsn'])) {
52 3
            return;
53
        }
54
55
        $dsn = new DSN($options['dsn']);
56
        if (!$dsn->isValid()) {
57
            throw new \InvalidArgumentException('Invalid DSN: '.$options['dsn']);
58
        }
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2 View Code Duplication
    public function createAdapter(array $options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
65
    {
66 2
        if (!empty($options['dsn'])) {
67
            $dsn = new DSN($options['dsn']);
68
            if (!$dsn->isValid()) {
69
                throw new \InvalidArgumentException('Invalid DSN: '.$options['dsn']);
70
            }
71
72
            $this->DSN = $dsn;
73
        }
74
75 2
        return parent::createAdapter($options);
76
    }
77
}
78