Errno   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 51
ccs 9
cts 9
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getErrorNameByCode() 0 15 3
1
<?php
2
/**
3
 * DronePHP (http://www.dronephp.com)
4
 *
5
 * @link      http://github.com/Pleets/DronePHP
6
 * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org)
7
 * @license   http://www.dronephp.com/license
8
 * @author    Darío Rivera <[email protected]>
9
 */
10
11
namespace Drone\Error;
12
13
/**
14
 * Errno class
15
 *
16
 * This class defines some constant names to ErrorTrait class
17
 */
18
class Errno
19
{
20
    /**
21
     * Common file errors
22
     *
23
     * @var integer
24
     */
25
    const FILE_PERMISSION_DENIED = 1;
26
    const FILE_NOT_FOUND         = 2;
27
    const FILE_EXISTS            = 3;
28
    const NOT_DIRECTORY          = 4;
29
30
    /**
31
     * Common JSON errors
32
     *
33
     * @var integer
34
     */
35
    const JSON_DECODE_ERROR = 10;
36
    const JSON_ENCODE_ERROR = 11;
37
38
    /**
39
     * Common database errors
40
     *
41
     * @var integer
42
     */
43
    const DB_TRANSACTION_STARTED     = 20;
44
    const DB_TRANSACTION_NOT_STARTED = 21;
45
    const DB_TRANSACTION_EMPTY       = 22;
46
47
    /**
48
     * Returns the constant name from a given code
49
     *
50
     * @param integer $code
51
     *
52
     * @return string
53
     */
54 2
    public static function getErrorNameByCode($code)
55
    {
56 2
        $currentClass = new \ReflectionClass('\Drone\Error\Errno');
57 2
        $constants = $currentClass->getConstants();
58
59 2
        $constName = null;
60
61 2
        foreach ($constants as $name => $value) {
62 2
            if ($value == $code) {
63 2
                $constName = $name;
64 2
                break;
65
            }
66
        }
67
68 2
        return $constName;
69
    }
70
}
71