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

MatcherException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 28
ccs 0
cts 22
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B errorToText() 0 19 5
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
}