File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 20
20
use PHPStan \Type \StringType ;
21
21
use PHPStan \Type \Type ;
22
22
use PHPStan \Type \TypeCombinator ;
23
+ use function array_key_exists ;
23
24
use function array_values ;
24
25
use function count ;
25
26
use function in_array ;
@@ -42,6 +43,8 @@ final class RegexGroupParser
42
43
43
44
private static ?Parser $ parser = null ;
44
45
46
+ private static array $ resultCache = [];
47
+
45
48
public function __construct (
46
49
private PhpVersion $ phpVersion ,
47
50
private RegexExpressionHelper $ regexExpressionHelper ,
@@ -53,6 +56,18 @@ public function __construct(
53
56
* @return array{array<int, RegexCapturingGroup>, list<string>}|null
54
57
*/
55
58
public function parseGroups (string $ regex ): ?array
59
+ {
60
+ if (array_key_exists ($ regex , self ::$ resultCache )) {
61
+ return self ::$ resultCache [$ regex ];
62
+ }
63
+
64
+ return self ::$ resultCache [$ regex ] = $ this ->parse ($ regex );
65
+ }
66
+
67
+ /**
68
+ * @return array{array<int, RegexCapturingGroup>, list<string>}|null
69
+ */
70
+ private function parse (string $ regex ): ?array
56
71
{
57
72
if (self ::$ parser === null ) {
58
73
/** @throws void */
You can’t perform that action at this time.
0 commit comments