Completed
Push — master ( b7fbe3...8fe22f )
by Peter
02:11
created

MatcherException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 06.12.17
6
 * Time: 11:11
7
 */
8
9
namespace Maslosoft\Addendum\Exceptions;
10
11
12
use Exception;
13
use Throwable;
14
15
class MatcherException extends Exception
16
{
17
	public function __construct($message = "", $code = 0, Throwable $previous = null)
18
	{
19
		$message .= $this->errorToText($code);
20
		parent::__construct($message, $code, $previous);
21
	}
22
23
	private function errorToText($errcode)
24
	{
25
		static $messages;
26
27
		if (!isset($errtxt))
0 ignored issues
show
Bug introduced by
The variable $errtxt seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
28
		{
29
			$messages = array();
30
			$constants = get_defined_constants(true);
31
			foreach ($constants['pcre'] as $name => $code)
32
			{
33
				if (preg_match('/_ERROR$/', $name))
34
				{
35
					$messages[$code] = $name;
36
				}
37
			}
38
		}
39
40
		return array_key_exists($errcode, $messages)? $messages[$errcode] : NULL;
41
	}
42
}