PHPStan
The PHPStan extension checks the regex patterns of your code against the PHP version your project targets, and reports the patterns that PHP would refuse while the PHP running PHPStan accepts them: what PHPStan itself cannot see.
It reads the patterns passed to preg_* functions (each pattern of an array
given to preg_replace(), preg_replace_callback() or preg_filter(), and
each key of the map given to preg_replace_callback_array(), included), to
their namespaced drop-ins (Safe\preg_match() from thecodingmachine/safe),
to the static methods of the wrapper libraries regex lint reads
(Wrapper libraries), and to your own functions and
methods that mark a parameter as a pattern. Lint rules and ReDoS analysis are
there too, off until you ask for them.
Nothing matches that filter — try a shorter fragment, or press Escape to see the whole page again.
Installation
composer config minimum-stability dev
composer config prefer-stable true
composer require --dev php-regex/regex-phpstan:2.x-devThe extension runs on PHP 8.1 or later and PHPStan 2.x
(phpstan/phpstan ^2.0); reading a parameter attribute needs PHPStan
2.1.31 at least (Pattern parameters).
With phpstan/extension-installer,
there is nothing to do: installing the package enables the extension. Without
it, include the extension in your phpstan.neon:
includes:
- vendor/php-regex/regex-phpstan/extension.neon
The paths below are the files php-regex/regex-phpstan installs under its
package root.
Then run PHPStan as usual:
vendor/bin/phpstan analyse
The extension’s findings join PHPStan’s own report. For a pattern the running PHP accepts but the target refuses, it reads:
Regex pattern is invalid for PHP 8.2 with PCRE2 10.40: Invalid group modifier syntax at position 2.
🪪 regex.invalidForTarget
A pattern that compiles for the target gets no such error. What it reports by default explains the check and how the target is chosen.
What it reports by default
PHPStan already reports every pattern the PHP running it cannot compile
(identifier regexp.pattern). The extension does not report those again. It
reports a pattern the running PHP compiles but the target refuses, as this
code under phpVersion: 80200 — (?aD) is an option PCRE2 added in 10.43,
which PHP bundles from 8.4:
preg_match('/(?aD)x/', 'x');
Regex pattern is invalid for PHP 8.2 with PCRE2 10.40: Invalid group modifier syntax at position 2.
🪪 regex.invalidForTarget
The target is PHPStan’s phpVersion (the PHP running PHPStan unless your
configuration sets it; the lowest version of a range) with the PCRE2 the
order below gives it. When the target is the PHP running PHPStan’s minor
version and the PCRE2 it links, there is nothing PHPStan misses, and the
extension reports no invalid pattern.
Which PCRE2 judges a version
A PHP version does not decide the PCRE2 a build links: distributions compile against their own libpcre2, and patch releases carry whatever was current when they were cut. Each version the extension judges gets its PCRE2 in this order:
- The release
phpRegex.pcreVersionnames, else the onecomposer.jsonpins inconfig.platform.lib-pcre("10.42", or"10.42.0"as Composer spells it). A pin is used as is, older or newer than the one that PHP bundles:pcreVersion: '10.49'judges PHP 8.2 with 10.49, andpcreVersion: '10.39'judges PHP 8.4 with 10.39. - The PCRE2 running PHPStan, when the version judged is the running PHP’s
minor version: on a PHP 8.4.27 that links 10.49,
phpVersion: 80400is judged with 10.49. - The PCRE2 that PHP’s sources bundle: 10.40 for 8.2, 10.42 for 8.3, 10.44 for 8.4 and 8.5.
The order holds for the target, each later version of a range, and each
version a guard or a @regex-target marker keeps. A
config.platform.lib-pcre that names no PCRE2 release stops the analysis
when it starts. regex lint, the language server, the Symfony and
Laravel bridges and the Psalm plugin follow the same order.
A range, phpVersion: {min: 80400, max: 80599}, is read whole: a pattern the
lowest version accepts is also validated at each later PHP up to max where
the PCRE2 that PHP bundles or the library’s compat rules change (8.4.25,
8.5, 8.5.10…). regex lint reads a composer.json range the same
way; the first version that refuses the pattern is reported under the same
identifier:
Regex pattern is invalid for PHP 8.5 with PCRE2 10.44: \K is not allowed in a lookaround from PHP 8.5, which compiles without PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK.
🪪 regex.invalidForTarget
A phpRegex.phpVersion naming one version judges that version alone, even
under a PHPStan range.
phpRegex.phpVersion can name a range too: a Composer constraint, or {min,
max} with each bound a quoted version or a PHP_VERSION_ID, max included
(a two-part max such as '8.6' covers the whole 8.6 series; unquoted, 8.1
is a float, which the schema refuses). Its versions are those
regex lint judges for the same range, but
only a version that refuses a pattern is reported: the lint’s warning that a
later version reads a pattern otherwise is not.
parameters:
phpRegex:
phpVersion: '>=8.1' # 8.1 up to the last version the library knows
# phpVersion: '^8.1 <8.5' # 8.1 to 8.4
# phpVersion:
# min: '8.1'
# max: '8.6'
When PHPStan’s own phpVersion is a {min, max} range as well, only the
versions both allow are judged: those PHPStan analyses the code for, so a guard
on PHP_VERSION_ID narrows them as below. phpRegex.phpVersion: '>=8.1' under
phpVersion: {min: 80100, max: 80399} judges 8.1 to 8.3. Two ranges that share
no version stop the analysis when it starts:
phpRegex.phpVersion ">=8.5" shares no version with phpVersion {min: 80100, max: 80399}, the PHP versions PHPStan analyses the code for: name a range that overlaps it.
When PHPStan names one version, or none, the range is judged as given, and a
guard on PHP_VERSION_ID narrows it all the same (see below). composer.json’s
require.php is not read for it: name the range in the extension’s settings.
A constraint the lint would refuse ('<8.4', which has no lowest version,
'*', or '>=80100') stops the analysis with the lint’s error.
A range the extension refuses stops PHPStan while it starts, before any file is analysed: PHPStan names the extension’s bootstrap file and prints the error after it, then stops with exit code 1:
PHPRegex\Parser\Exception\InvalidRegexOptionException thrown in …/TargetScope.php on line … while loading bootstrap file …/bootstrap.php: phpRegex.phpVersion ">=8.5" shares no version with phpVersion {min: 80100, max: 80399}, the PHP versions PHPStan analyses the code for: name a range that overlaps it.
Guarded calls
A call that runs on some PHP versions of the range only is judged for those,
whether the range is PHPStan’s or the one phpRegex.phpVersion names.
PHPStan narrows PHP_VERSION_ID under a guard, and the extension reads that
narrowed type at the call: the versions judged are the lowest one the guard
keeps, with the PCRE2 the order above gives it, then each later
version of the range above it. Under phpVersion: {min: 80200, max: 80599}:
if (PHP_VERSION_ID >= 80400) {
preg_match('/(?a)\d+/', $s); // judged for 8.4 and 8.5: not reported
}
preg_match('/(?a)\d+/', $s); // "(?a)" needs PCRE2 10.43: reported for 8.2
Every guard PHPStan narrows on counts: an if, an elseif chain, a ternary,
an early return, &&, a negation, guards nested inside each other.
version_compare(PHP_VERSION, '8.4', '>=') and || narrow nothing, so the
whole range is judged, as it is for a comparison with a variable. A guard that
keeps no version of the range (PHP_VERSION_ID >= 90000 under 8.2 to 8.5)
leaves the call unjudged: it never runs there. An unqualified
PHP_VERSION_ID that names a constant of its namespace is no PHP version,
and its guard is not read. With a phpRegex.phpVersion that names one version,
or one PHP version for PHPStan and no range for the extension, the guards are
not read: that version is judged at every call, under a guard that keeps it
off too. Under phpVersion: 80100,
if (PHP_VERSION_ID >= 80200) { preg_match('/(a)/n', $s); } is still reported
for PHP 8.1.
A @regex-target marker narrows the versions a call is judged for as the
lint reads it (see the CLI guide),
with a guard the versions both keep. A marker that keeps no version of the
range is reported as regex.target.empty on its line, and its calls are not
judged; one that cannot be read as regex.target.invalid, and its calls are
judged for the whole range:
The @regex-target marker "php>=9.0" keeps no version the project is judged for (PHP >=8.2 <8.6): the patterns it covers are not judged.
🪪 regex.target.empty
The marker text the message quotes is spelled in display form: a control
character or a line break in a comment is written \xHH or \n, and a <
that would open a console tag, before a letter or /, is written \x3C, so
the text can neither lay out a line of its own nor style PHPStan’s output. A
constraint operator such as <9 stays as written.
The target follows the rules of regex lint: PHP
7.2 and earlier ship PCRE1, which the library does not judge. A version below
7.3 named by phpRegex.phpVersion or by PHPStan’s phpVersion stops the
analysis when it starts, with the error the lint gives:
phpVersion names PHP 7.1: PHP 7.2 and earlier ship PCRE1, which this library does not judge. Name a PHP version of 7.3 or later to judge for.
A range that starts below 7.3 and reaches it, phpVersion: {min: 70100, max:
80499} or phpRegex.phpVersion: '>=7.1', is judged from 7.3; one that does
not reach it, phpRegex.phpVersion: '~7.1.0', is refused (phpRegex.phpVersion
allows PHP 7.1: PHP 7.2 and earlier ship PCRE1, …). When PHPStan read a PHP below 7.3 from
composer.json, the extension reads composer.json as the lint does: a
require.php that also allows 7.3 or later, or a config.platform.php below
7.3 beside one, is judged from the lowest PHP on PCRE2 it allows; one that
allows none is refused. The extension shows no note, as the Psalm plugin
shows none: the lint’s note that the range is judged from 7.3 is not printed.
Pattern parameters
A function, a method or a constructor of your own that takes a pattern says
so with the attribute PHPRegex\Parser\Attribute\RegexPattern, or with
PhpStorm’s #[Language('RegExp')]:
use PHPRegex\Parser\Attribute\RegexPattern;
final class Str
{
public function matches(string $subject, #[RegexPattern] string $regex): bool
{
return 1 === preg_match($regex, $subject);
}
}
$str->matches($input, '/(foo/');
The constant pattern passed to that parameter, by position or by name, is
checked as a preg_*() pattern is, in calls to functions, static and
instance methods (PHPStan knows the type of $str) and constructors. PHPStan
core reads only preg_*() calls, so a pattern the running PHP refuses is
reported here, in PHPStan’s words and under its identifier:
Regex pattern is invalid: missing closing parenthesis at offset 4.
🪪 regexp.pattern
A pattern the target refuses is regex.invalidForTarget, and rules.neon
lints it and checks it for ReDoS as it does in a preg_*() call. A variadic
parameter has each of its arguments read. PHPStan reads the arguments of an
attribute only when it knows its class: #[Language('RegExp')] is read when
jetbrains/phpstorm-attributes is installed, and #[RegexPattern], which
takes none, always. Parameter attributes come from PHPStan’s reflection,
which offers them from PHPStan 2.1.31 at least: on an older 2.x release that
lacks them, no parameter is read as a pattern, and nothing is reported.
Lint rules and ReDoS analysis
rules.neon turns them on:
includes:
- vendor/php-regex/regex-phpstan/rules.neon
Without extension-installer, include both extension.neon and rules.neon.
Each check can also be switched on its own (see below). Every rule — when each
fires, its message, its severity and its fix — is catalogued in
Lint rules.
ReDoS analysis in PHPStan is theoretical: it reads the pattern and never runs it inside PHPStan.
Cost
With the opt-in checks off, the extension parses and validates each distinct
constant pattern once — the parse lands in an in-memory cache, so a pattern
that appears in a hundred files is not parsed a hundred times. On the
project’s benchmark corpus, 1,645 patterns collected from real PHP projects,
the whole corpus validates in about a third of a second: an everyday pattern
validates in a few tens of microseconds once warm, a pathological one in
about 1.5 milliseconds. ReDoS analysis is the expensive check: the same
corpus judged for ReDoS takes about 4 seconds, 2.4 milliseconds per pattern
on average, and its worst real-world pattern about 230 milliseconds.
PHPStan’s result cache does the rest: a file it does not analyse again costs
the extension nothing. The characters a Unicode class matches, which the
ReDoS analysis and the lint rules read from the PCRE2 running PHPStan, are
kept under PHPStan’s tmpDir, in php-regex/, for the next run and the
other workers: a new PHP, PCRE2 or library release reads them again.
ReDoS findings
A pattern at or above checks.redos.threshold (high by default, as in
regex lint, the Symfony and Laravel bridges and the language server) is
reported under regex.redos, with one of three messages:
| message | verdict |
|---|---|
Exponential backtracking (ReDoS): <pattern> |
proven exponential |
Polynomial backtracking (ReDoS): <pattern> |
proven polynomial |
Potential backtracking (ReDoS): <pattern> |
judged by the structural heuristics |
When a rewrite of the pattern is proven to match the same subjects and proven
linear, the tip prints it: Proven repair: /(a+)$/ (same subjects, same matches, linear).
The verdicts and the character sets behind them come from the PCRE2 that runs
PHPStan. PHPStan’s result cache does not know when a distribution upgrades
libpcre2 under an unchanged PHP: clear it (vendor/bin/phpstan clear-result-cache)
after such an upgrade.
<pattern> is the pattern as the console shows it, cut after 50 characters —
never mid-character or mid-escape — with invisible characters (C1 controls,
bidirectional overrides, zero-width spaces…) written as escapes (\x{202E}
under /u, \xE2\x80\xAE otherwise) and a pattern under x on one line
without its # comments, so no output format reads it as markup.
The message holds the verdict class and the pattern only, and the text of each of the three stays the same for all of 2.x. The severity, how the verdict was reached and the attack are in the tip. Which patterns are reported is not frozen: when the analysis improves, an error may appear, disappear or change class (Exponential, Polynomial, Potential). After an upgrade that changes the analysis, regenerate the baseline:
vendor/bin/phpstan analyse --generate-baseline
A call whose subject PHPStan knows to be constant — a literal, a constant, a concatenation of them, or an array of them — is not reported: it backtracks the same way on every run, or never, so no input can turn it into an attack. The same pattern is reported wherever its subject may come from outside.
preg_match('/^(a+)+$/', 'fixed'); // not reported: the subject is constant
preg_match('/^(a+)+$/', $input); // reported
preg_match('/^(\w+\s?)+$/', $value);
preg_match('/\d*\d*\d*$/', $value);
preg_match('/^(a+)+\1$/', $value);
With the default threshold, high:
------ -----------------------------------------------------------------------
Line src/Validator.php
------ -----------------------------------------------------------------------
7 Exponential backtracking (ReDoS): /^(\w+\s?)+$/
🪪 regex.redos
💡 Severity: critical, exponential (proven).
💡 Attack: "0" x n . "!"
💡 Unbounded quantifier detected. May cause backtracking on
non-matching input. Consider making it possessive (*+) or using
atomic groups (?>...). Suggested (verify behavior): Consider using
possessive quantifiers or atomic groups to limit backtracking.
💡
💡 Read more about possessive quantifiers: …
💡 Read more about atomic groups: …
💡 Read more about catastrophic backtracking: …
12 Polynomial backtracking (ReDoS): /\d*\d*\d*$/
🪪 regex.redos
💡 Severity: high, polynomial degree 3 (proven).
💡 Attack: "0" x n . "!"
…
17 Potential backtracking (ReDoS): /^(a+)+\1$/
🪪 regex.redos
💡 Severity: critical, heuristic.
…
The tip starts with the severity and how it was reached: exponential
(proven), polynomial degree N (proven), heuristic, or heuristic (budget
exceeded). A proven verdict adds the attack, "0" x n . "!": the input
str_repeat("0", $n) . "!" that drives the worst case. The recommendations and
the documentation links follow. The ReDoS guide explains
each part of the verdict.
The attack is a PHP expression that pastes back into code. A < in it is
written \x3C, the same byte, so that no output format reads it as markup:
5 Exponential backtracking (ReDoS): /^(<b>|<b>\s?)+$/
🪪 regex.redos
💡 Severity: critical, exponential (proven).
💡 Attack: "\x3Cb>\x3Cb>" x n . "!"
A proven quadratic pattern is medium, below the default threshold; set
threshold: medium to see it.
Quadratic search
One attempt of /\s+$/ is linear, but an unanchored preg_match() may start
an attempt at each later position of the subject, and on a run of spaces each one reads
to the end of the run before it fails: PCRE2’s interpreter takes a number of
steps quadratic in the length of the run. pcre.backtrack_limit does not stop
it, as the limit counts each attempt apart, and the JIT may avoid it for some
patterns, not for all (see the ReDoS guide).
Such a pattern is reported under its own identifier, regex.redos.search,
with the message Quadratic search (ReDoS): <pattern>, frozen for 2.x like
the three others. It has no setting of its own: it follows checks.redos.enabled
and is medium, like a proven quadratic attempt, so threshold: medium or
low shows it. A constant subject is not reported.
The same identifier and message cover the calls that look for every match:
preg_match_all(), preg_replace(), preg_filter(), preg_replace_callback(),
preg_replace_callback_array() and preg_split(), their Safe\ drop-ins and the
composer/pcre methods that call them. A pattern such as /(?:a+\d)?/ stops the
search of preg_match() at an empty match, but these functions go on, and PHP’s
retry after each empty match reads to the end of the run (see the
ReDoS guide).
The tip then starts with Quadratic search after an empty match and names the
function. A preg_match() call of that pattern is not reported, and neither is
a call whose limit, as its type says, bounds the matches.
function trailing(string $value): bool
{
return 1 === preg_match('/\s+$/', $value);
}
With threshold: medium:
------ -----------------------------------------------------------------------
Line Validator.php
------ -----------------------------------------------------------------------
5 Quadratic search (ReDoS): /\s+$/
🪪 regex.redos.search
💡 Quadratic search: one attempt is linear (proven); an unanchored
search is quadratic in PCRE2's interpreter (pcre.jit=0, a build
without JIT, or (*NO_JIT)); the JIT may avoid it for some patterns.
Severity: MEDIUM.
💡 Attack: " " x n . "!". pcre.backtrack_limit does not stop it: the
limit counts each attempt apart. preg_match_all(), preg_replace() and
preg_split() retry the same way. Anchor the pattern when every match
starts at a known place (^, \A, \G or the A modifier), or bound the
length of the run.
💡
💡 Read more about catastrophic backtracking: …
------ -----------------------------------------------------------------------
Ignore it by identifier where the length of the subject is bounded:
parameters:
ignoreErrors:
- identifier: regex.redos.search
Configuration
parameters:
phpRegex:
# The PHP patterns are judged for: null for PHPStan's phpVersion,
# 'runtime' for the PHP running PHPStan, a version like '8.2', a
# PHP_VERSION_ID like 80200, or a range: a Composer constraint like
# '>=8.1', or {min, max}, kept within PHPStan's phpVersion range.
phpVersion: null
# The PCRE2 release, like '10.42', used as is; null for the one
# composer.json pins in config.platform.lib-pcre, else the running
# PCRE2 for the running PHP's minor version, else the bundled one.
pcreVersion: null
# The LC_CTYPE locale the patterns run under, like 'tr_TR.UTF-8':
# its character tables decide the size of a few classes. null for
# the locale of the PHP running PHPStan.
locale: null
# The libraries whose static methods carry a pattern:
# composer-pcre, nette-utils, spatie-regex, illuminate-support,
# phpunit, webmozart-assert, beberlei-assert, symfony-validator;
# null for every preset, [] for the native functions only.
interop: null
checks:
lint:
enabled: false
redos:
enabled: false
# The lowest severity reported: low, medium, high or critical.
threshold: high
optimizations:
enabled: false
minSavings: 1
# What the optimizer may rewrite.
options:
digits: true
word: true
ranges: true
canonicalizeCharClasses: true
possessive: false
factorize: false
minQuantifierCount: 4
verifyWithAutomata: true
complexity:
enabled: false
# The complexity score from which a pattern is reported.
threshold: 50
rules.neon leaves optimizations and complexity off. With complexity
on, a pattern whose complexity score, the complexityScore of
Regex::validate(), reaches threshold is reported as regex.lint.complexity
with the message regex lint prints, Pattern is complex (score: 56).; it
needs neither lint nor redos. A threshold below 1 stops the analysis when
it starts, even while complexity is off.
Wrapper libraries
A pattern passed to a static method of a wrapper library is judged as one
passed to preg_*(), at the argument the library takes it, as regex lint
reads it under extraction.interop (CLI guide):
Preg::match() of composer/pcre, Strings::match() of nette/utils (the
pattern second), Regex::match() of spatie/regex, Str::isMatch() of
Laravel, Assert::regex() of webmozart/assert and Assertion::regex() of
beberlei/assert (the pattern second), and PHPUnit’s assertions called as
PHPUnit\Framework\Assert::assertMatchesRegularExpression(). Every preset is
read unless interop lists some; a list reads exactly the presets it names.
The class is resolved as PHP resolves it, an aliased import included; a method
of another class with the same name is not read. The subject of such a call is
not told apart, so a constant subject does not quiet a ReDoS report as it does
in preg_match().
parameters:
phpRegex:
interop: [composer-pcre, nette-utils]
A name that is no preset stops the analysis, with the preset it most likely
means: Unknown extraction preset "phpunt" in phpRegex.interop: did you mean "phpunit"?.
The rule reads static calls only. An assertion called on the test case,
$this->assertMatchesRegularExpression() or self::…, PHPUnit’s
assertMatchesRegularExpression() function, new Regex(...) and
#[Assert\Regex(...)] of the symfony-validator preset, new RegexIterator()
and filter_var() are read by regex lint, not by the extension (see the
extraction coverage). Nette’s
utf8: true is not applied: the pattern is judged without the u it adds.
A phpVersion or pcreVersion that names no release, or a locale this
machine cannot set, stops the analysis when it starts, not on the first file.
Every version of the range, and every version a guard or a @regex-target
marker keeps, is judged under the locale; a message names it when it is not
C (Regex pattern is invalid for PHP 8.4 with PCRE2 10.44 under the locale
tr_TR.UTF-8: ...). PHPStan itself reports what the running engine refuses,
under the locale PHPStan runs with (see
Which locale judges a pattern). So does a threshold that is not low,
medium, high or critical, even while redos is off: safe and
unknown are the verdicts a pattern gets, not thresholds. The configuration
schema takes the four values in lower case; a rule built from an array, in
custom wiring, reads them in any case.
Identifiers
| identifier | reported for |
|---|---|
regex.invalidForTarget |
a pattern the target refuses and the running PHP compiles |
regexp.pattern |
a pattern passed to a parameter marked #[RegexPattern] or #[Language('RegExp')] that the running PHP refuses; PHPStan core’s identifier, which it gives such a pattern in a preg_*() call |
regex.replacement.undefinedGroup |
a constant replacement of preg_replace() or preg_filter() that refers to a group the pattern does not have, or names one (${name}, which PHP never substitutes); when the pattern and the replacement both vary, only a reference no possible pattern defines; always on |
regex.redos |
a pattern at or above the ReDoS threshold; the severity is in the tip |
regex.redos.search |
a pattern whose one attempt is proven linear and whose unanchored search is quadratic in PCRE2’s interpreter, at the ReDoS threshold medium or below |
regex.optimization |
a pattern with a shorter equivalent |
regex.trivialMatch |
a preg_match($pattern, $subject) a string function answers alike, str_starts_with() for /^https:/, proven by the automata; with optimizations on |
regex.lint.<rule> |
a lint rule, as regex.lint.flag.useless.i |
regex.lint.complexity |
a pattern whose complexity score reaches checks.complexity.threshold; with complexity on |
Use them in ignoreErrors or a baseline as with any PHPStan identifier.
PHPStan has one level of report, so every lint issue is a PHPStan error, whatever
the severity of its rule: an issue the regex lint console prints as INFO, as
regex.lint.group.quantifiedCapture on an unnamed group, is reported as well.
Its identifier lets you ignore it:
parameters:
ignoreErrors:
- identifier: regex.lint.group.quantifiedCapture
A baseline written before 2.0 holds a 1.x ReDoS message, Potential ReDoS
risk (theoretical) (severity: …, confidence: …): … or Confirmed ReDoS risk
(…): …, which no longer matches:
regenerate it with vendor/bin/phpstan analyse --generate-baseline (see
UPGRADE-2.0.md).
Regenerate it once after upgrading to 2.0.0 as well, whatever version wrote it:
lint messages were reworded (the useless m and s flags, a lazy quantifier
under U, redundant class ranges), false positives were removed, and with
redos on, the nested-quantifier, dot-star and overlapping-set issues are no
longer reported for a pattern the analysis proves linear.
Types and IDE support
The library’s own PHPDoc is written for your analyser, not just for reading:
visitors carry their return type as a generic ($ast->accept(PatternPrinter::asWritten())
is a string to PHPStan and Psalm, with no @var), and the array shapes the
results hand you are named type aliases you can import instead of restating:
/**
* @phpstan-import-type WitnessArray from PHPRegex\Redos\RedosWitness
*/
final class AttackReporter
{
/**
* @param WitnessArray $witness {prefix, pump, suffix}: the strings of the attack
*/
public function describe(array $witness): string
{
return $witness['pump'].' repeated, framed by '.$witness['prefix'];
}
}
The API reference lists the
aliases you are most likely to import, with their shapes; more exist on
internal classes, and every name is frozen for all of 2.x. Psalm
resolves the same aliases; the Laravel facade documents every method of the
service, so completion and argument types survive the Regex:: indirection.