Passed
Push — master ( 751d74...a1591c )
by Radu
01:11
created

Codes::getMessage()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 27
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 27
rs 7.6666
cc 10
nc 10
nop 1

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
namespace WebServCo\Framework\Files\Upload;
3
4
final class Codes
5
{
6
    const OK = 0;
7
    const INI_SIZE = 1;
8
    const FORM_SIZE = 2;
9
    const PARTIAL = 3;
10
    const NO_FILE = 4;
11
    const NO_TMP_DIR = 6;
12
    const CANT_WRITE = 7;
13
    const EXTENSION = 8;
14
    /* custom codes */
15
    const TYPE_NOT_ALLOWED = 91;
16
17
    public static function getMessage($errorCode)
18
    {
19
        switch ($errorCode) {
20
            case self::OK:
21
                return null;
22
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
23
            case self::INI_SIZE:
24
            case self::FORM_SIZE:
25
                return __('Uploaded file size exceeds maximum file size allowed');
26
                break;
27
            case self::PARTIAL:
28
                return __('The uploaded file was only partially uploaded');
29
                break;
30
            case self::NO_FILE:
31
                return __('No file was uploaded');
32
                break;
33
            case self::TYPE_NOT_ALLOWED:
34
                return __('File type not allowed');
35
                break;
36
            case self::CANT_WRITE:
37
                return __('Error saving uploaded file');
38
                break;
39
            case self::NO_TMP_DIR:
40
            case self::EXTENSION:
41
            default:
42
                return __('Upload error');
43
                break;
44
        }
45
    }
46
}
47