ParseException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeFromError() 0 5 1
A __construct() 0 19 5
1
<?php
2
/**
3
 * @file
4
 * Query path parsing exception.
5
 */
6
7
namespace QueryPath;
8
9
/**
10
 * Exception indicating that a parser has failed to parse a file.
11
 *
12
 * This will report parser warnings as well as parser errors. It should only be
13
 * thrown, though, under error conditions.
14
 *
15
 * @ingroup querypath_core
16
 */
17
class ParseException extends \QueryPath\Exception
18
{
19
20
    public const ERR_MSG_FORMAT  = 'Parse error in %s on line %d column %d: %s (%d)';
21
    public const WARN_MSG_FORMAT = 'Parser warning in %s on line %d column %d: %s (%d)';
22
23
    // trigger_error
24
    public function __construct($msg = '', $code = 0, $file = NULL, $line = NULL)
25
    {
26
27
        $msgs = [];
28
        foreach (libxml_get_errors() as $err) {
29
            $format = $err->level === LIBXML_ERR_WARNING ? self::WARN_MSG_FORMAT : self::ERR_MSG_FORMAT;
30
            $msgs[] = sprintf($format, $err->file, $err->line, $err->column, $err->message, $err->code);
31
        }
32
        $msg .= implode("\n", $msgs);
33
34
        if (isset($file)) {
35
            $msg .= ' (' . $file;
36
            if (isset($line)) {
37
                $msg .= ': ' . $line;
38
            }
39
            $msg .= ')';
40
        }
41
42
        parent::__construct($msg, $code);
43
    }
44
45
    public static function initializeFromError($code, $str, $file, $line, $cxt)
0 ignored issues
show
Unused Code introduced by
The parameter $cxt is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

45
    public static function initializeFromError($code, $str, $file, $line, /** @scrutinizer ignore-unused */ $cxt)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        //printf("\n\nCODE: %s %s\n\n", $code, $str);
48
        $class = __CLASS__;
49
        throw new $class($str, $code, $file, $line);
50
    }
51
}
52