UnparseableXMLException   A
last analyzed

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
9
use function sprintf;
10
11
/**
12
 */
13
final class UnparseableXMLException extends RuntimeException
14
{
15
    /** @var string[] */
16
    private const LEVELMAP = [
17
        LIBXML_ERR_WARNING => 'WARNING',
18
        LIBXML_ERR_ERROR   => 'ERROR',
19
        LIBXML_ERR_FATAL   => 'FATAL',
20
    ];
21
22
23
    /**
24
     * Constructor for UnparseableXMLException
25
     *
26
     * @param \LibXMLError $error
27
     */
28
    public function __construct(LibXMLError $error)
29
    {
30
        $message = sprintf(
31
            'Unable to parse XML - "%s[%d]": "%s" in "%s" at line %d on column %d"',
32
            self::LEVELMAP[$error->level],
33
            $error->code,
34
            $error->message,
35
            $error->file ?: '(string)',
36
            $error->line,
37
            $error->column,
38
        );
39
40
        parent::__construct($message);
41
    }
42
}
43