pcre::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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