UnparseableXMLException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 1
nop 1
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
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