AdapterMapper::map()   C
last analyzed

Complexity

Conditions 14
Paths 14

Size

Total Lines 33
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 14

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 28
c 1
b 0
f 0
nc 14
nop 1
dl 0
loc 33
ccs 29
cts 29
cp 1
crap 14
rs 6.2666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11PhpCache\Adapter;
6
7
/**
8
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
9
 */
10
class AdapterMapper
11
{
12
    /**
13
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
14
     * @param string $type
15
     * @return \WShafer\PSR11PhpCache\Adapter\FactoryInterface|null
16
     */
17 14
    public function map(string $type): ?FactoryInterface
18
    {
19 14
        $type = strtolower($type);
20
21 14
        switch ($type) {
22 14
            case 'apc':
23 1
                return new ApcAdapterFactory();
24 13
            case 'apcu':
25 1
                return new ApcuAdapterFactory();
26 12
            case 'array':
27 1
                return new ArrayAdapterFactory();
28 11
            case 'chain':
29 1
                return new ChainCacheAdapterFactory();
30 10
            case 'doctrine':
31 1
                return new DoctrineCacheAdapterFactory();
32 9
            case 'filesystem':
33 1
                return new FileSystemAdapterFactory();
34 8
            case 'illuminate':
35 1
                return new IlluminateAdapterFactory();
36 7
            case 'memcached':
37 1
                return new MemcachedAdapterFactory();
38 6
            case 'mongodb':
39 5
            case 'mongo':
40 2
                return new MongoAdapterFactory();
41 4
            case 'predis':
42 1
                return new PredisAdapterFactory();
43 3
            case 'redis':
44 1
                return new RedisAdapterFactory();
45 2
            case 'void':
46 1
                return new VoidAdapterFactory();
47
        }
48
49 1
        return null;
50
    }
51
}
52