XsdError::fromLibXMLError()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0
rs 9.9332
cc 2
nc 1
nop 1
crap 6
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
     * @param \LibXMLError $error
43
     *
44
     * @return XsdError
45
     */
46
    public static function fromLibXMLError(\LibXMLError $error)
47
    {
48
        return new self(
49
            isset(self::$levelMap[$error->level]) ? self::$levelMap[$error->level] : 'Unknown',
50
            $error->code,
51
            $error->message,
52
            $error->line,
53
            $error->column
54
        );
55
    }
56
57
    /**
58
     * @param string $level
59
     * @param string $code
60
     * @param string $message
61
     * @param string $line
62
     * @param string $column
63
     */
64 2
    public function __construct($level, $code, $message, $line, $column)
65
    {
66 2
        $this->level = $level;
67 2
        $this->code = $code;
68 2
        $this->message = $message;
69 2
        $this->line = $line;
70 2
        $this->column = $column;
71 2
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getLevel()
77
    {
78
        return $this->level;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getCode()
85
    {
86
        return $this->code;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getMessage()
93
    {
94
        return $this->message;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getLine()
101
    {
102
        return $this->line;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getColumn()
109
    {
110
        return $this->column;
111
    }
112
113
    public function __toString()
114
    {
115
        return sprintf(
116
            '%s %s: %s on line %s column %s',
117
            $this->level,
118
            $this->code,
119
            trim($this->message),
120
            $this->line,
121
            $this->column
122
        );
123
    }
124
}
125