Skip to content

Commit 20bf04d

Browse files
committed
Removed facade state
1 parent 46d66d1 commit 20bf04d

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ composer require --dev "coduo/php-matcher"
2626

2727
use Coduo\PHPMatcher\PHPMatcher;
2828

29-
if (!PHPMatcher::match("lorem ipsum dolor", "@string@")) {
30-
echo PHPMatcher::getError(); // reason why value does not match pattern.
29+
if (!PHPMatcher::match("lorem ipsum dolor", "@string@", $error)) {
30+
echo $error; // in case of error message is set on $error message via reference
3131
}
32+
3233
```
3334

3435

src/Coduo/PHPMatcher/PHPMatcher.php

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,21 @@
66

77
final class PHPMatcher
88
{
9-
/**
10-
* @var Matcher|null
11-
*/
12-
private static $matcher;
13-
149
/**
1510
* @param $value
1611
* @param $pattern
12+
* @param null $error
1713
* @return bool
1814
*/
19-
public static function match($value, $pattern)
15+
public static function match($value, $pattern, &$error = null)
2016
{
21-
$matcher = self::createMatcher();
17+
$matcher = (new SimpleFactory())->createMatcher();
2218

23-
return $matcher->match($value, $pattern);
24-
}
25-
26-
/**
27-
* @return null|string
28-
*/
29-
public static function getError()
30-
{
31-
$matcher = self::createMatcher();
32-
33-
return $matcher->getError();
34-
}
35-
36-
private static function createMatcher()
37-
{
38-
if (self::$matcher instanceof Matcher) {
39-
return self::$matcher;
19+
if (!$matcher->match($value, $pattern)) {
20+
$error = $matcher->getError();
21+
return false;
4022
}
4123

42-
$factory = new SimpleFactory();
43-
self::$matcher = $factory->createMatcher();
44-
45-
return self::$matcher;
24+
return true;
4625
}
4726
}

0 commit comments

Comments
 (0)