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
|
|||
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 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.