MatcherException::errorToText()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 17
cp 0
rs 9.3222
c 0
b 0
f 0
cc 5
nc 4
nop 2
crap 30
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL, Commercial license.
5
 *
6
 * @package maslosoft/addendum
7
 * @licence AGPL, Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes)
9
 * @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes)
10
 * @copyright Copyright (c) Jan Suchal (Original version, builder, parser)
11
 * @link https://maslosoft.com/addendum/ - maslosoft addendum
12
 * @link https://code.google.com/p/addendum/ - original addendum project
13
 */
14
15
namespace Maslosoft\Addendum\Exceptions;
16
17
18
use Exception;
19
use Throwable;
20
21
class MatcherException extends Exception
22
{
23
	public function __construct($message = "", $code = 0, Throwable $previous = null)
24
	{
25
		$message .= $this->errorToText($code, $message);
26
		parent::__construct($message, $code, $previous);
27
	}
28
29
	private function errorToText($errorCode, $errorMessage)
30
	{
31
		static $messages;
32
33
		if (!isset($errorMessage))
34
		{
35
			$messages = array();
36
			$constants = get_defined_constants(true);
37
			foreach ($constants['pcre'] as $name => $code)
38
			{
39
				if (preg_match('/_ERROR$/', $name))
40
				{
41
					$messages[$code] = $name;
42
				}
43
			}
44
		}
45
46
		return array_key_exists($errorCode, $messages)? $messages[$errorCode] : NULL;
47
	}
48
}