AbstractDsnAdapterFactory::createAdapter()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 4.679

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
ccs 3
cts 7
cp 0.4286
cc 3
nc 3
nop 1
crap 4.679
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