pcre   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A recipientOfRegexMatchingAgainstStringIs() 0 3 1
1
<?php namespace norsys\score\php\string\regex;
2
3
use norsys\score\php\{
4
	string\regex,
5
	test,
6
	test\recipient\ifTrue
7
};
8
9
class pcre
10
	implements
11
		regex
12
{
13
	private
14
		$regex
15
	;
16
17
	function __construct(string $regex)
18
	{
19
		$previousErrorHandler = set_error_handler(function() {});
20
21
		(
22
			new test\isFalse\strictly
23
		)
24
			->recipientOfTestOnVariableIs(
25
				preg_match($regex, ''),
26
				new ifTrue\exception(new\invalidArgumentException('Syntax error in regular expression'))
27
			)
28
		;
29
30
		set_error_handler($previousErrorHandler);
31
32
		$this->regex = $regex;
33
	}
34
35
	function recipientOfRegexMatchingAgainstStringIs(string $string, test\recipient $recipient) :void
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
	{
37
		$recipient->booleanIs(preg_match($this->regex, $string) !== 0);
38
	}
39
}
40