DoctrineRiakFactory::getAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 0
cts 6
cp 0
cc 1
nc 1
nop 1
crap 2
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\Adapter\Doctrine\DoctrineCachePool;
15
use Doctrine\Common\Cache\RiakCache;
16
use Riak\Bucket;
17
use Riak\Connection;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
/**
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
final class DoctrineRiakFactory extends AbstractDoctrineAdapterFactory
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getAdapter(array $config)
29
    {
30
        $connection = new Connection($config['host'], $config['port']);
31
        $bucket = new Bucket($connection, $config['type']);
32
33
        return new DoctrineCachePool(new RiakCache($bucket));
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\Cache\RiakCache has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 View Code Duplication
    protected static function configureOptionResolver(OptionsResolver $resolver)
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...
40
    {
41
        $resolver->setDefaults([
42
            'host' => '127.0.0.1',
43
            'port' => '8087',
44
            'type' => null,
45
        ]);
46
47
        $resolver->setAllowedTypes('host', ['string']);
48
        $resolver->setAllowedTypes('port', ['string', 'int']);
49
        $resolver->setAllowedTypes('type', ['string', 'null']);
50
    }
51
}
52