XsdError::getCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 1
c 1
b 1
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Validator\Model\Xsd;
13
14
class XsdError
15
{
16
    const WARNING = 'Warning';
17
    const ERROR = 'Error';
18
    const FATAL = 'Fatal';
19
20
    private static $levelMap = [
21
        LIBXML_ERR_WARNING => self::WARNING,
22
        LIBXML_ERR_ERROR => self::ERROR,
23
        LIBXML_ERR_FATAL => self::FATAL,
24
    ];
25
26
    /** @var string */
27
    private $level;
28
29
    /** @var string */
30
    private $code;
31
32
    /** @var string */
33
    private $message;
34
35
    /** @var string */
36
    private $line;
37
38
    /** @var string */
39
    private $column;
40
41
    /**
42
     * @return XsdError
43
     */
44
    public static function fromLibXMLError(\LibXMLError $error)
45
    {
46
        return new self(
47
            isset(self::$levelMap[$error->level]) ? self::$levelMap[$error->level] : 'Unknown',
48
            $error->code,
49
            $error->message,
50
            $error->line,
51
            $error->column
52
        );
53
    }
54
55
    /**
56
     * @param string $level
57
     * @param string $code
58
     * @param string $message
59
     * @param string $line
60
     * @param string $column
61
     */
62
    public function __construct($level, $code, $message, $line, $column)
63
    {
64
        $this->level = $level;
65
        $this->code = $code;
66
        $this->message = $message;
67
        $this->line = $line;
68
        $this->column = $column;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getLevel()
75
    {
76
        return $this->level;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getCode()
83
    {
84
        return $this->code;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getMessage()
91
    {
92
        return $this->message;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getLine()
99
    {
100
        return $this->line;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getColumn()
107
    {
108
        return $this->column;
109
    }
110
111
    public function __toString()
112
    {
113
        return sprintf(
114
            '%s %s: %s on line %s column %s',
115
            $this->level,
116
            $this->code,
117
            trim($this->message),
118
            $this->line,
119
            $this->column
120
        );
121
    }
122
}
123