Skip to content

Commit ea4ab6f

Browse files
committed
Add phpstan ext info to readme
1 parent f2af236 commit ea4ab6f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ to understand the implications.
1212

1313
It thus makes it easier to work with static analysis tools like PHPStan or Psalm as it
1414
simplifies and reduces the possible return values from all the `preg_*` functions which
15-
are quite packed with edge cases.
15+
are quite packed with edge cases. As of v2.2.0 / v3.2.0 the library also comes with a
16+
[PHPStan extension](#phpstan-extension) for parsing regular expressions and giving you even better output types.
1617

1718
This library is a thin wrapper around `preg_*` functions with [some limitations](#restrictions--limitations).
1819
If you are looking for a richer API to handle regular expressions have a look at
@@ -175,6 +176,13 @@ preg_match('/(a)(b)*(c)(d)*/', 'ac', $matches, $flags);
175176
| group 2 (any unmatched group preceding one that matched) is set to `''`. You cannot tell if it matched an empty string or did not match at all | group 2 is `null` when unmatched and a string if it matched, easy to check for |
176177
| group 4 (any optional group without a matching one following) is missing altogether. So you have to check with `isset()`, but really you want `isset($m[4]) && $m[4] !== ''` for safety unless you are very careful to check that a non-optional group follows it | group 4 is always set, and null in this case as there was no match, easy to check for with `$m[4] !== null` |
177178

179+
PHPStan Extension
180+
-----------------
181+
182+
To use the PHPStan extension if you do not use `phpstan/extension-installer` you can include `vendor/composer/pcre/extension.neon` in your PHPStan config.
183+
184+
The extension provides much better type information for $matches as well as regex validation where possible.
185+
178186
License
179187
-------
180188

0 commit comments

Comments
 (0)