DownloadStatus::toString()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: famoser
5
 * Date: 27.05.2016
6
 * Time: 13:23
7
 */
8
9
namespace Famoser\XKCDCache\Types;
10
11
/**
12
 * any error which occurs by processing an api request
13
 *
14
 * @package Famoser\XKCDCache\Types
15
 */
16
class DownloadStatus
17
{
18
    const SUCCESSFUL = 0;
19
    const JSON_DOWNLOAD_FAILED = 1;
20
    const IMAGE_DOWNLOAD_FAILED = 2;
21
22
    const UNKNOWN_ERROR = 1000;
23
24
    /**
25
     * convert the api to a string
26
     *
27
     * @param $apiError
28
     * @return string
29
     */
30 3
    public static function toString($apiError)
31
    {
32
        switch ($apiError) {
33 3
            case self::SUCCESSFUL:
34 3
                return 'no error occurred';
35 1
            case self::JSON_DOWNLOAD_FAILED:
36 1
                return 'json download failed';
37 1
            case self::IMAGE_DOWNLOAD_FAILED:
38 1
                return 'image download failed';
39 1
            case self::UNKNOWN_ERROR:
40 1
                return 'an unknown error occurred';
41
42
            default:
43 1
                return 'unknown api error occurred with code ' . $apiError;
44
        }
45
    }
46
}
47