Codes   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
eloc 34
c 2
b 0
f 0
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C getMessage() 0 24 12
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