Passed
Push — master ( 8005df...2d92e4 )
by Darío
03:27
created

Errno::getErrorNameByCode()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 17
rs 10
c 0
b 0
f 0
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
    public static function getErrorNameByCode($code)
55
    {
56
        $currentClass = new \ReflectionClass('\Drone\Error\Errno');
57
        $constants = $currentClass->getConstants();
58
59
        $constName = null;
60
61
        foreach ($constants as $name => $value)
62
        {
63
            if ($value == $code)
64
            {
65
                $constName = $name;
66
                break;
67
            }
68
        }
69
70
        return $constName;
71
    }
72
}