FormatterMapper::map()   C
last analyzed

Complexity

Conditions 15
Paths 15

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 15

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 31
cts 31
cp 1
rs 5.9166
c 0
b 0
f 0
cc 15
nc 15
nop 1
crap 15

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\PSR11MonoLog\Formatter;
6
7
use WShafer\PSR11MonoLog\MapperInterface;
8
9
/**
10
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11
 */
12
class FormatterMapper implements MapperInterface
13
{
14
    /**
15
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
16
     */
17 15
    public function map(string $type)
18
    {
19 15
        switch ($type) {
20 15
            case 'line':
21 1
                return LineFormatterFactory::class;
22 14
            case 'html':
23 1
                return HtmlFormatterFactory::class;
24 13
            case 'normalizer':
25 1
                return NormalizerFormatterFactory::class;
26 12
            case 'scalar':
27 1
                return ScalarFormatterFactory::class;
28 11
            case 'json':
29 1
                return JsonFormatterFactory::class;
30 10
            case 'wildfire':
31 1
                return WildfireFormatterFactory::class;
32 9
            case 'chromePHP':
33 1
                return ChromePHPFormatterFactory::class;
34 8
            case 'gelf':
35 1
                return GelfMessageFormatterFactory::class;
36 7
            case 'logstash':
37 1
                return LogstashFormatterFactory::class;
38 6
            case 'elastica':
39 1
                return ElasticaFormatterFactory::class;
40 5
            case 'loggly':
41 1
                return LogglyFormatterFactory::class;
42 4
            case 'flowdock':
43 1
                return FlowdockFormatterFactory::class;
44 3
            case 'mongodb':
45 1
                return MongoDBFormatterFactory::class;
46 2
            case 'logmatic':
47 1
                return LogmaticFormatterFactory::class;
48
        }
49
50 1
        return null;
51
    }
52
}
53