AnswerFactory::getObject()   D
last analyzed

Complexity

Conditions 19
Paths 19

Size

Total Lines 32
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 19

Importance

Changes 0
Metric Value
cc 19
eloc 29
nc 19
nop 1
dl 0
loc 32
rs 4.5166
c 0
b 0
f 0
ccs 11
cts 11
cp 1
crap 19

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
namespace kalanis\RemoteRequest\Protocols\Fsp\Answer;
4
5
6
use kalanis\RemoteRequest\Protocols\Fsp;
7
8
9
/**
10
 * Class AnswerFactory
11
 * @package RemoteRequest\Protocols\Fsp\Answer
12
 * Factory for selecting correct answer - pythonic style
13
 */
14
class AnswerFactory
15
{
16 13
    public static function getObject(Fsp\Answer $answer): AAnswer
17
    {
18 13
        switch ($answer->getCommand()) {
19
            case Fsp::CC_VERSION:
20 2
                return new Version($answer);
21
            case Fsp::CC_GET_DIR:
22 2
                return new GetDir($answer);
23
            case Fsp::CC_GET_FILE:
24
            case Fsp::CC_GRAB_FILE:
25 1
                return new GetFile($answer);
26
            case Fsp::CC_UP_LOAD:
27 1
                return new Upload($answer);
28
            case Fsp::CC_GET_PRO:
29
            case Fsp::CC_SET_PRO:
30
            case Fsp::CC_MAKE_DIR:
31 1
                return new Protection($answer);
32
            case Fsp::CC_STAT:
33 1
                return new Stats($answer);
34
            case Fsp::CC_INSTALL:
35
            case Fsp::CC_DEL_FILE:
36
            case Fsp::CC_DEL_DIR:
37
            case Fsp::CC_BYE:
38
            case Fsp::CC_GRAB_DONE:
39
            case Fsp::CC_RENAME:
40
//            case Fsp::CC_CH_PASSW: // undefined
41 1
                return new Nothing($answer);
42
            case Fsp::CC_LIMIT: // reserved
43
            case Fsp::CC_TEST: // reserved
44 1
                return new Test($answer);
45
            case Fsp::CC_ERR:
46
            default:
47 3
                return new Error($answer);
48
        }
49
    }
50
}
51