Passed
Push — master ( 6bd416...994e00 )
by Tim
05:00 queued 03:14
created

UnparseableXMLException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\Exception;
6
7
use LibXMLError;
8
use RuntimeException;
9
10
use function sprintf;
11
12
/**
13
 */
14
final class UnparseableXMLException extends RuntimeException
15
{
16
    /** @var array */
17
    private const LEVELMAP = [
18
        LIBXML_ERR_WARNING => 'WARNING',
19
        LIBXML_ERR_ERROR   => 'ERROR',
20
        LIBXML_ERR_FATAL   => 'FATAL'
21
    ];
22
23
24
    /**
25
     * Constructor for UnparseableXMLException
26
     *
27
     * @param \LibXMLError $error
28
     */
29
    public function __construct(LibXMLError $error)
30
    {
31
        $message = sprintf(
32
            'Unable to parse XML - "%s[%d]": "%s" in "%s" at line %d on column %d"',
33
            self::LEVELMAP[$error->level],
34
            $error->code,
35
            $error->message,
36
            $error->file ?: '(string)',
37
            $error->line,
38
            $error->column
39
        );
40
41
        parent::__construct($message);
42
    }
43
}
44