Completed
Push — master ( ee9a51...a02f02 )
by Tobias
21:27 queued 19:30
created

DoctrineMemcachedFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 30
loc 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptionResolver() 10 10 1
A getAdapter() 10 10 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
/*
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\MemcachedCache;
16
use Memcached;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22 View Code Duplication
final class DoctrineMemcachedFactory extends AbstractDoctrineAdapterFactory
0 ignored issues
show
Duplication introduced by
This class 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...
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function getAdapter(array $config)
28
    {
29 3
        $memcached = new Memcached();
30 3
        $memcached->addServer($config['host'], $config['port']);
31
32 3
        $client = new MemcachedCache();
33 3
        $client->setMemcached($memcached);
34
35 3
        return new DoctrineCachePool($client);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 3
    protected static function configureOptionResolver(OptionsResolver $resolver)
42
    {
43 3
        $resolver->setDefaults([
44 3
            'host' => '127.0.0.1',
45
            'port' => '11211',
46
        ]);
47
48 3
        $resolver->setAllowedTypes('host', ['string']);
49 3
        $resolver->setAllowedTypes('port', ['string', 'int']);
50 3
    }
51
}
52