Completed
Push — master ( 0fe4ba...1092bf )
by Westin
07:30 queued 05:57
created

HandlerMapper::map()   C

Complexity

Conditions 32
Paths 32

Size

Total Lines 71
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 65
CRAP Score 32

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 65
cts 65
cp 1
rs 5.3691
c 0
b 0
f 0
cc 32
eloc 66
nc 32
nop 1
crap 32

How to fix   Long Method    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
declare(strict_types=1);
3
4
namespace WShafer\PSR11MonoLog\Handler;
5
6
use WShafer\PSR11MonoLog\MapperInterface;
7
8
/**
9
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10
 */
11
class HandlerMapper implements MapperInterface
12
{
13
    /**
14
     * @param string $type
15
     * @return null|string
16
     *
17
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
18
     */
19 32
    public function map(string $type)
20
    {
21 32
        $type = strtolower($type);
22
23
        switch ($type) {
24 32
            case 'stream':
25 1
                return StreamHandlerFactory::class;
26 31
            case 'rotating':
27 1
                return RotatingFileHandlerFactory::class;
28 30
            case 'syslog':
29 1
                return SyslogHandlerFactory::class;
30 29
            case 'errorlog':
31 1
                return ErrorLogHandlerFactory::class;
32 28
            case 'nativemailer':
33 1
                return NativeMailerHandlerFactory::class;
34 27
            case 'swiftmailer':
35 1
                return SwiftMailerHandlerFactory::class;
36 26
            case 'pushover':
37 1
                return PushoverHandlerFactory::class;
38 25
            case 'hipchat':
39 1
                return HipChatHandlerFactory::class;
40 24
            case 'flowdock':
41 1
                return FlowdockHandlerFactory::class;
42 23
            case 'slackbot':
43 1
                return SlackbotHandlerFactory::class;
44 22
            case 'slackwebhook':
45 1
                return SlackWebhookHandlerFactory::class;
46 21
            case 'slack':
47 1
                return SlackHandlerFactory::class;
48 20
            case 'mandrill':
49 1
                return MandrillHandlerFactory::class;
50 19
            case 'fleephook':
51 1
                return FleepHookHandlerFactory::class;
52 18
            case 'ifttt':
53 1
                return IFTTTHandlerFactory::class;
54 17
            case 'socket':
55 1
                return SocketHandlerFactory::class;
56 16
            case 'amqp':
57 1
                return AmqpHandlerFactory::class;
58 15
            case 'gelf':
59 1
                return GelfHandlerFactory::class;
60 14
            case 'cube':
61 1
                return CubeHandlerFactory::class;
62 13
            case 'raven':
63 1
                return RavenHandlerFactory::class;
64 12
            case 'zend':
65 1
                return ZendMonitorHandlerFactory::class;
66 11
            case 'newrelic':
67 1
                return NewRelicHandlerFactory::class;
68 10
            case 'loggly':
69 1
                return LogglyHandlerFactory::class;
70 9
            case 'syslogudp':
71 1
                return SyslogUdpHandlerFactory::class;
72 8
            case 'logentries':
73 1
                return LogEntriesHandlerFactory::class;
74 7
            case 'firephp':
75 1
                return FirePHPHandlerFactory::class;
76 6
            case 'chromephp':
77 1
                return ChromePHPHandlerFactory::class;
78 5
            case 'browserconsole':
79 1
                return BrowserConsoleHandlerFactory::class;
80 4
            case 'phpconsole':
81 1
                return PHPConsoleHandlerFactory::class;
82 3
            case 'redis':
83 1
                return RedisHandlerFactory::class;
84 2
            case 'mongo':
85 1
                return MongoDBHandlerFactory::class;
86
        }
87
88 1
        return null;
89
    }
90
}
91