Codes::getMessage()   C
last analyzed

Complexity

Conditions 12
Paths 12

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 24
rs 6.9666
cc 12
nc 12
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
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Files\Upload;
6
7
final class Codes
8
{
9
    public const OK = 0;
10
    public const INI_SIZE = 1;
11
    public const FORM_SIZE = 2;
12
    public const PARTIAL = 3;
13
    public const NO_FILE = 4;
14
    public const NO_TMP_DIR = 6;
15
    public const CANT_WRITE = 7;
16
    public const EXTENSION = 8;
17
18
    /* custom codes */
19
    public const TYPE_NOT_ALLOWED = 91;
20
    public const IMAGE_TOO_SMALL = 101;
21
    public const IMAGE_WRONG_ASPECT_RATIO = 102;
22
23
    public static function getMessage(int $errorCode): string
24
    {
25
        switch ($errorCode) {
26
            case self::OK:
27
                return '';
28
            case self::INI_SIZE:
29
            case self::FORM_SIZE:
30
                return \__('Uploaded file size exceeds maximum file size allowed.');
31
            case self::PARTIAL:
32
                return \__('The uploaded file was only partially uploaded.');
33
            case self::NO_FILE:
34
                return \__('No file was uploaded.');
35
            case self::TYPE_NOT_ALLOWED:
36
                return \__('File type not allowed.');
37
            case self::CANT_WRITE:
38
                return \__('Error saving uploaded file.');
39
            case self::IMAGE_TOO_SMALL:
40
                return \__('Image is too small.');
41
            case self::IMAGE_WRONG_ASPECT_RATIO:
42
                return \__('Image has wrong aspect ratio.');
43
            case self::NO_TMP_DIR:
44
            case self::EXTENSION:
45
            default:
46
                return \__('Upload error.');
47
        }
48
    }
49
}
50