Repository navigation
feat(compat-scanner): scan all of app/ and judge every WordPress install by its version #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mrrobot47
merged 92 commits into
EasyEngine:develop
from
mrrobot47:refactor/compat-scanner-scan-app
Dec 1, 2026
Merged
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
d4fac42
refactor(compat-scanner): drop the walk budgets and size caps
mrrobot47 32aed79
feat(compat-scanner): scan all of app/ and judge every WordPress by i…
mrrobot47 a25bebe
feat(compat-scanner): lint for PHP 8 parse errors and count every fil…
mrrobot47 6465a9d
ci: assert that every php image loads redis
mrrobot47 7b563ed
fix(compat-scanner): never leave out the release that holds the scan …
mrrobot47 14046cc
test(compat-scanner): name the v3.11.1-style runs after what they do
mrrobot47 dbe6a78
fix(compat-scanner): read a double-quoted $wp_version too
mrrobot47 e3f9118
fix(compat-scanner): leave the run-again hint of a timeout to EE
mrrobot47 a5fd8e6
fix(compat-scanner): read a WordPress version over 64 characters as u…
mrrobot47 ce42b7c
refactor(compat-scanner): read the contract env in its own function
mrrobot47 7c1ba08
test(compat-scanner): pin the report key order
mrrobot47 3cecfd8
fix(compat-scanner): read .user.ini and version.php lines with a leng…
mrrobot47 b34b311
fix(compat-scanner): read a .user.ini the way PHP does
mrrobot47 fb44320
fix(compat-scanner): read .user.ini files in core and old releases
mrrobot47 2084908
fix(compat-scanner): check a wp-config.php linked into a mount
mrrobot47 49127be
fix(compat-scanner): keep checking a php site whose htdocs is missing…
mrrobot47 0245d7e
fix(compat-scanner): lint only files that start as PHP
mrrobot47 e24f620
fix(compat-scanner): judge redeclared PHP functions by the target ver…
mrrobot47 8258722
fix(compat-scanner): leave out only release siblings that look like a…
mrrobot47 083658f
fix(compat-scanner): raise the entrypoint memory limit to 2G
mrrobot47 242107a
fix(compat-scanner): lint for fatal errors only
mrrobot47 864e0fc
fix(compat-scanner): leave .user.ini files in old releases unread
mrrobot47 e87f7e6
fix(compat-scanner): walk the code beside a wp-content linked out of …
mrrobot47 1949a88
fix(compat-scanner): keep linting past a function PHP adds after the …
mrrobot47 c30c8bf
fix(compat-scanner): count only a function_exists() check on the name…
mrrobot47 6250542
fix(compat-scanner): leave out an old release only when it holds the …
mrrobot47 5f2e9bb
fix(compat-scanner): read every .user.ini, and report a core one that…
mrrobot47 1c8e19d
fix(compat-scanner): bound the reads of data-only candidates, the pha…
mrrobot47 8ae627d
test(compat-scanner): keep the harness exact on odd input
mrrobot47 39606fd
fix(compat-scanner): set the entrypoint memory limit to 1536M
mrrobot47 8fee2fd
fix(compat-scanner): lint templates with text before their PHP tag
mrrobot47 97fe322
feat(compat-scanner): report a class PHP has natively in the target d…
mrrobot47 c7b250b
fix(compat-scanner): count a PHP_VERSION_ID bound as a guard for nati…
mrrobot47 bb62736
fix(compat-scanner): keep the scanner and a child below the 2g contai…
mrrobot47 a663f03
fix(compat-scanner): time PHPCS and lint runs in the scanner itself
mrrobot47 7df0f2d
fix(compat-scanner): check code that the walk dropped or left out by …
mrrobot47 37de1da
fix(compat-scanner): give "can't confirm" for lint failures that may …
mrrobot47 43736ba
feat(compat-scanner): follow the site's short_open_tag setting
mrrobot47 08f6c14
fix(compat-scanner): accept only guards that keep a native's declarat…
mrrobot47 2cb69ca
feat(compat-scanner): know the names PHP 8.0 and its date extension a…
mrrobot47 c4bf1a6
fix(compat-scanner): no errors for polyfill files PHP never runs on t…
mrrobot47 29f771b
style(compat-scanner): put each comment on one line
mrrobot47 d2d3bd9
test(compat-scanner): pull the PHP 8.5.0 image before the guard table…
mrrobot47 4364daa
fix(compat-scanner): an XML file isn't PHP code where short tags are on
mrrobot47 bacd6fb
perf(compat-scanner): read a directory once for the bootstrap check
mrrobot47 6bf18cb
fix(compat-scanner): find every string naming a file in the bootstrap…
mrrobot47 28af03c
fix(compat-scanner): lint with each target's PHP and honour guards ar…
mrrobot47 69a1e04
fix(compat-scanner): a sniffed file with no PHP code isn't a php_tag …
mrrobot47 29e1aa4
fix(compat-scanner): count a lint run per file in the estimate below …
mrrobot47 a458768
test(compat-scanner): compare the estimate's lint time as a number
mrrobot47 6caebde
fix(compat-scanner): match namespaced new classes the site declares i…
mrrobot47 abab5df
test(compat-scanner): cover a version_compare() guard with named argu…
mrrobot47 57f272f
refactor(compat-scanner): share the guard operand test
mrrobot47 a817b57
fix(compat-scanner): count a guard only inside the code's own functio…
mrrobot47 577a96e
fix(compat-scanner): keep deprecation warnings under an exists-check
mrrobot47 0af602a
fix(compat-scanner): match a new class's guard on its full name
mrrobot47 ce9f838
fix(compat-scanner): a site's trait or interface doesn't stand in for…
mrrobot47 3a546a9
fix(compat-scanner): check short tags on where any .user.ini down to …
mrrobot47 b75cb47
style(compat-scanner): put the phar-name docblock back on its function
mrrobot47 3dc4ad0
test(compat-scanner): read the use-guard table once
mrrobot47 24d4105
test(compat-scanner): pin the shapes that aren't guards
mrrobot47 ae61aba
fix(compat-scanner): let defined() guard the constant it names
mrrobot47 33bfa7c
fix(compat-scanner): skip a constant default of a function declared o…
mrrobot47 acb699a
fix(compat-scanner): leave out package files their package loads only…
mrrobot47 b4b5e92
fix(compat-scanner): let the doc root's .user.ini Off hold over a sho…
mrrobot47 8a800ce
fix(compat-scanner): keep the kind of a new interface finding
mrrobot47 3f5c97d
fix(compat-scanner): check every file with short tags on when any .us…
mrrobot47 38733e6
fix(compat-scanner): read .user.ini directive names case-sensitively
mrrobot47 b323539
fix(compat-scanner): match .user.ini directories to the doc root by r…
mrrobot47 3e9976f
fix(compat-scanner): ignore the scan path's .user.ini Off when the do…
mrrobot47 caabc54
fix(compat-scanner): check package files Composer's autoloader loads
mrrobot47 17e5cc1
fix(compat-scanner): apply a linked .user.ini to every directory that…
mrrobot47 40219f3
fix(compat-scanner): flag a .user.ini include_path into a left-out ol…
mrrobot47 aafa13a
test(compat-scanner): pin the short-tag hiding case as a known limit
mrrobot47 a1d95e8
fix(compat-scanner): never let a .user.ini turn short tags off
mrrobot47 c43805f
fix(compat-scanner): count a .user.ini On reached through a link to a…
mrrobot47 4d9cda5
fix(compat-scanner): ignore the include_path of a .user.ini above the…
mrrobot47 0ef9e66
fix(compat-scanner): flag a link to releases/ or an ancestor of it
mrrobot47 901d26f
perf(compat-scanner): skip the doc root's link names when no .user.in…
mrrobot47 b093f76
test(compat-scanner): run each truth row from its own checked fixture…
mrrobot47 1bd0312
fix(compat-scanner): list a .user.ini linked into a left-out old rele…
mrrobot47 3a2d678
fix(compat-scanner): take no version_compare() literal with a part ov…
mrrobot47 ad8773c
fix(compat-scanner): split guard conditions only on their own && and ||
mrrobot47 1269628
fix(compat-scanner): drop a declared-class list too long for the repo…
mrrobot47 fe95702
fix(compat-scanner): judge native declaration version guards against …
mrrobot47 e32335f
test(compat-scanner): check each source the mcrypt use-guard row reports
mrrobot47 0ee9bec
test(compat-scanner): match templates through every vendor dir in the…
mrrobot47 9cf8384
test(compat-scanner): name the component the oversized declared-class…
mrrobot47 3157534
test(compat-scanner): pull each guard table's PHP image before its tr…
mrrobot47 47b8873
test(compat-scanner): match each fatal guard row against the error it…
mrrobot47 b4caa86
fix(compat-scanner): find a Composer vendor dir right inside a package
mrrobot47 abac3b3
fix(compat-scanner): keep a package's lint errors when its autoload l…
mrrobot47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,274 @@ | ||
| <?php | ||
| /** | ||
| * The strict guard grammar the scanner's sniffs and its report share: which if/elseif/else blocks run only where a name exists or is missing, or only on some PHP versions. Anything the grammar doesn't name is no guard. | ||
| */ | ||
|
|
||
| namespace CompatScanner; | ||
|
|
||
| use PHP_CodeSniffer\Files\File; | ||
| use PHP_CodeSniffer\Util\Tokens; | ||
| use PHPCSUtils\Utils\Namespaces; | ||
| use PHPCSUtils\Utils\PassedParameters; | ||
|
|
||
| final class Guard { | ||
|
|
||
| /** The PHP_VERSION_ID above every version. */ | ||
| const TOP = PHP_INT_MAX; | ||
|
|
||
| /** | ||
| * The PHP_VERSION_ID range [from, to) where a version test holds, from the text of its tokens (no whitespace or comments): `PHP_VERSION_ID <op> N` either way round with N a plain decimal, or `version_compare( PHP_VERSION, 'X.Y[.Z]', '<' | 'lt' | '>=' | 'ge' )`. | ||
| * | ||
| * @return int[]|null | ||
| */ | ||
| public static function range( array $words ): ?array { | ||
| $w = array_map( 'ltrim', $words, array_fill( 0, count( $words ), '\\' ) ); | ||
| $flip = [ '<' => '>', '<=' => '>=', '>' => '<', '>=' => '<=' ]; | ||
| if ( 3 === count( $w ) && 'PHP_VERSION_ID' === $w[2] && isset( $flip[ $w[1] ] ) ) { | ||
| $w = [ $w[2], $flip[ $w[1] ], $w[0] ]; | ||
| } | ||
| if ( 3 === count( $w ) && 'PHP_VERSION_ID' === $w[0] && isset( $flip[ $w[1] ] ) && preg_match( '/^[1-9][0-9]*$/', $w[2] ) ) { | ||
| $n = (int) $w[2]; | ||
| return [ '<' => [ 0, $n ], '<=' => [ 0, $n + 1 ], '>' => [ $n + 1, self::TOP ], '>=' => [ $n, self::TOP ] ][ $w[1] ]; | ||
| } | ||
| // Positional arguments only: a named one can reorder them. | ||
| if ( 8 !== count( $w ) || 'version_compare' !== strtolower( $w[0] ) || [ '(', 'PHP_VERSION', ',', ',', ')' ] !== [ $w[1], $w[2], $w[3], $w[5], $w[7] ] ) { | ||
| return null; | ||
| } | ||
| if ( ! preg_match( '/^([\'"])(\d+)(?:\.(\d+))?(?:\.(\d+))?\1$/', $w[4], $v ) || ! preg_match( '/^([\'"])(<|lt|>=|ge)\1$/', $w[6], $c ) ) { | ||
| return null; | ||
| } | ||
| // PHP_VERSION_ID has two digits each for the minor and the patch version; '8.3.200' would read as 8.5. | ||
| if ( (int) ( $v[3] ?? 0 ) > 99 || (int) ( $v[4] ?? 0 ) > 99 ) { | ||
| return null; | ||
| } | ||
| $id = $v[2] * 10000 + (int) ( $v[3] ?? 0 ) * 100 + (int) ( $v[4] ?? 0 ); | ||
| return in_array( $c[2], [ '<', 'lt' ], true ) ? [ 0, $id ] : [ $id, self::TOP ]; | ||
| } | ||
|
|
||
| /** The PHP_VERSION_ID range of a target `X.Y`: every X.Y.Z. */ | ||
| public static function target( string $version ): array { | ||
| list( $major, $minor ) = explode( '.', $version ); | ||
| $id = $major * 10000 + $minor * 100; | ||
| return [ $id, $id + 100 ]; | ||
| } | ||
|
|
||
| /** Whether a block that runs where the range holds never runs on the target. */ | ||
| public static function misses( array $range, array $target ): bool { | ||
| return $range[1] <= $target[0] || $range[0] >= $target[1]; | ||
| } | ||
|
|
||
| /** Whether the range holds on every version of the target. */ | ||
| public static function covers( array $range, array $target ): bool { | ||
| return $range[0] <= $target[0] && $range[1] >= $target[1]; | ||
| } | ||
|
|
||
| /** | ||
| * Whether a block enclosing $ptr, within its innermost function or class and with no goto label in it, runs only where $inIf accepts an `&&` operand of its if or elseif, or is the else of an if with a `||` operand $inElse accepts. | ||
| */ | ||
| public static function encloses( File $file, int $ptr, callable $inIf, callable $inElse ): bool { | ||
| $tokens = $file->getTokens(); | ||
| if ( ! $tokens[ $ptr ]['conditions'] ) { | ||
| return false; | ||
| } | ||
| $scope = self::scope( $file, $ptr ); | ||
| foreach ( array_keys( $tokens[ $ptr ]['conditions'] ) as $block ) { | ||
| // A guard around a function or class decides only whether it is declared; code outside the guard can call it. | ||
| if ( $block < $scope || self::jumpedInto( $file, $block ) ) { | ||
| continue; | ||
| } | ||
| if ( T_ELSE === $tokens[ $block ]['code'] ) { | ||
| // The closing brace before `else` belongs to the if or elseif it is the else of. | ||
| $prev = $file->findPrevious( Tokens::EMPTY_TOKENS, $block - 1, null, true ); | ||
| $if = T_CLOSE_CURLY_BRACKET === $tokens[ $prev ]['code'] ? ( $tokens[ $prev ]['scope_condition'] ?? null ) : null; | ||
| if ( null !== $if && self::any( $file, $if, true, $inElse ) ) { | ||
| return true; | ||
| } | ||
| } elseif ( self::any( $file, $block, false, $inIf ) ) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** The innermost function, closure, arrow function or class around $ptr, or -1. */ | ||
| private static function scope( File $file, int $ptr ): int { | ||
| $tokens = $file->getTokens(); | ||
| $scope = -1; | ||
| foreach ( $tokens[ $ptr ]['conditions'] as $block => $code ) { | ||
| if ( T_FUNCTION === $code || T_CLOSURE === $code || isset( Tokens::OO_SCOPE_TOKENS[ $code ] ) ) { | ||
| $scope = $block; | ||
| } | ||
| } | ||
| // A parameter list belongs to its function, though it isn't one of the function's conditions. | ||
| foreach ( $tokens[ $ptr ]['nested_parenthesis'] ?? [] as $open => $close ) { | ||
| $owner = $tokens[ $open ]['parenthesis_owner'] ?? -1; | ||
| if ( $owner > $scope && in_array( $tokens[ $owner ]['code'] ?? null, [ T_FUNCTION, T_CLOSURE, T_FN ], true ) ) { | ||
| $scope = $owner; | ||
| } | ||
| } | ||
| // Arrow functions aren't conditions; only one inside the outermost block matters. | ||
| $from = max( $scope, array_key_first( $tokens[ $ptr ]['conditions'] ) ); | ||
| for ( $fn = $ptr; false !== ( $fn = $file->findPrevious( T_FN, $fn - 1, $from + 1 ) ); ) { | ||
| if ( ( $tokens[ $fn ]['scope_closer'] ?? -1 ) >= $ptr ) { | ||
| return $fn; | ||
| } | ||
| } | ||
| return $scope; | ||
| } | ||
|
|
||
| /** Whether a goto can enter the block: a label inside it. */ | ||
| private static function jumpedInto( File $file, int $block ): bool { | ||
| $tokens = $file->getTokens(); | ||
| return isset( $tokens[ $block ]['scope_closer'] ) && false !== $file->findNext( T_GOTO_LABEL, $block, $tokens[ $block ]['scope_closer'] ); | ||
| } | ||
|
|
||
| /** Whether the operand is `check( 'name' )` with that polarity (false: negated), or a version test whose range $fits accepts. */ | ||
| public static function tests( File $file, array $op, array $checks, string $name, bool $polarity, callable $fits ): bool { | ||
| $range = self::versions( $file, $op ); | ||
| return $polarity === self::checks( $file, $op, $checks, $name ) || ( null !== $range && $fits( $range ) ); | ||
| } | ||
|
|
||
| /** Whether $test accepts an operand of the condition of the if or elseif at $ptr, split at its top-level `||` ($or) or `&&`. */ | ||
| public static function any( File $file, int $ptr, bool $or, callable $test ): bool { | ||
| foreach ( (array) self::operands( $file, $ptr, $or ) as $op ) { | ||
| if ( $test( $op ) ) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * The top-level operands of the condition of the if or elseif at $ptr, each without parentheses around it; null when it isn't one or another top-level logical operator joins them. | ||
| * | ||
| * @return array<int,int[]>|null | ||
| */ | ||
| public static function operands( File $file, int $ptr, bool $or ): ?array { | ||
| $tokens = $file->getTokens(); | ||
| if ( ! in_array( $tokens[ $ptr ]['code'], [ T_IF, T_ELSEIF ], true ) || ! isset( $tokens[ $ptr ]['parenthesis_closer'] ) ) { | ||
| return null; | ||
| } | ||
| $open = $tokens[ $ptr ]['parenthesis_opener']; | ||
| $depth = count( $tokens[ $open ]['nested_parenthesis'] ?? [] ) + 1; | ||
| $join = $or ? [ T_BOOLEAN_OR, T_LOGICAL_OR ] : [ T_BOOLEAN_AND, T_LOGICAL_AND ]; | ||
| $other = $or ? [ T_BOOLEAN_AND, T_LOGICAL_AND ] : [ T_BOOLEAN_OR, T_LOGICAL_OR ]; | ||
| // These bind looser than `&&` and `||` and take in the operators after them: `! $x = a && b` is `! ( $x = ( a && b ) )`. | ||
| $looser = [ T_FN, T_PRINT, T_YIELD, T_YIELD_FROM, T_THROW, T_INCLUDE, T_INCLUDE_ONCE, T_REQUIRE, T_REQUIRE_ONCE ]; | ||
| $other = array_merge( $other, [ T_LOGICAL_XOR, T_INLINE_THEN, T_COALESCE ], $looser, array_keys( Tokens::ASSIGNMENT_TOKENS ) ); | ||
|
|
||
| $operands = [ [] ]; | ||
| $inside = -1; | ||
| for ( $i = $open + 1; $i < $tokens[ $ptr ]['parenthesis_closer']; $i++ ) { | ||
| $code = $tokens[ $i ]['code']; | ||
| if ( isset( Tokens::EMPTY_TOKENS[ $code ] ) ) { | ||
| continue; | ||
| } | ||
| // Operators in brackets or braces belong to what they hold: `[ a && b ]`, `$m[ a && b ]`, a closure's body. | ||
| $top = $i > $inside && count( $tokens[ $i ]['nested_parenthesis'] ?? [] ) === $depth; | ||
| if ( $top && ( $tokens[ $i ]['bracket_opener'] ?? null ) === $i ) { | ||
| $inside = $tokens[ $i ]['bracket_closer']; | ||
| } | ||
| if ( $top && in_array( $code, $other, true ) ) { | ||
| return null; | ||
| } | ||
| if ( $top && in_array( $code, $join, true ) ) { | ||
| $operands[] = []; | ||
| continue; | ||
| } | ||
| $operands[ count( $operands ) - 1 ][] = $i; | ||
| } | ||
| return array_map( | ||
| static function ( $op ) use ( $tokens ) { | ||
| return self::unwrap( $tokens, $op ); | ||
| }, | ||
| $operands | ||
| ); | ||
| } | ||
|
|
||
| /** The version range an operand tests, or null when it is no version test. */ | ||
| public static function versions( File $file, array $op ): ?array { | ||
| $tokens = $file->getTokens(); | ||
| return self::range( | ||
| array_map( | ||
| static function ( $ptr ) use ( $tokens ) { | ||
| return $tokens[ $ptr ]['content']; | ||
| }, | ||
| $op | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Whether an operand checks for the name with one of $checks: true for exactly `check( 'name' )`, false for its negation (`! check()`, `false === check()`, `check() === false`), null otherwise. | ||
| */ | ||
| private static function checks( File $file, array $op, array $checks, string $name ): ?bool { | ||
| $tokens = $file->getTokens(); | ||
| $n = count( $op ); | ||
| $inner = null; | ||
| if ( $n > 1 && T_BOOLEAN_NOT === $tokens[ $op[0] ]['code'] ) { | ||
| $inner = self::unwrap( $tokens, array_slice( $op, 1 ) ); | ||
| } elseif ( $n > 2 && T_IS_IDENTICAL === $tokens[ $op[1] ]['code'] && T_FALSE === $tokens[ $op[0] ]['code'] ) { | ||
| $inner = array_slice( $op, 2 ); | ||
| } elseif ( $n > 2 && T_IS_IDENTICAL === $tokens[ $op[ $n - 2 ] ]['code'] && T_FALSE === $tokens[ $op[ $n - 1 ] ]['code'] ) { | ||
| $inner = array_slice( $op, 0, $n - 2 ); | ||
| } | ||
| if ( null !== $inner ) { | ||
| return self::named( $file, $inner, $checks, $name ) ? false : null; | ||
| } | ||
| return self::named( $file, $op, $checks, $name ) ? true : null; | ||
| } | ||
|
|
||
| /** Whether the tokens are exactly one call of $checks with the name as its first argument. */ | ||
| private static function named( File $file, array $op, array $checks, string $name ): bool { | ||
| $tokens = $file->getTokens(); | ||
| if ( ! self::call( $tokens, $op, $checks ) ) { | ||
| return false; | ||
| } | ||
| $arg = PassedParameters::getParameter( $file, $op[0], 1, [ 'function', 'class', 'interface', 'enum', 'constant_name' ] ); | ||
| if ( false === $arg ) { | ||
| return false; | ||
| } | ||
| $given = self::nameOf( $file, $arg['start'], $arg['clean'] ); | ||
| // A constant's name is case-sensitive, and defined() takes no X::class. | ||
| if ( [ 'defined' ] === $checks ) { | ||
| return preg_match( '/^[\'"]/', $arg['clean'] ) && $given === ltrim( $name, '\\' ); | ||
| } | ||
| return strtolower( (string) $given ) === strtolower( $name ); | ||
| } | ||
|
|
||
| /** | ||
| * The full name an argument gives: 'name' or "name" (parts joined by `\` or `\\`, an optional leading one), or name::class resolved in its namespace (PHPCompatibility reports no new class whose short name a `use` statement imports); null for anything else. | ||
| */ | ||
| private static function nameOf( File $file, int $ptr, string $arg ): ?string { | ||
| if ( preg_match( '/^([\'"])(\\\\{0,2}(?:\w+\\\\{1,2})*\w+)\1$/', $arg, $m ) ) { | ||
| // In double quotes `\n`, `\r` and the like are escapes, not separators. | ||
| $escape = '"' === $m[1] && preg_match( '/\\\\[nrtvef0-7xu]/', str_replace( '\\\\', '', $m[2] ) ); | ||
| return $escape ? null : ltrim( str_replace( '\\\\', '\\', $m[2] ), '\\' ); | ||
| } | ||
| if ( ! preg_match( '/^(\\\\?)((?:\w+\\\\)*\w+)::class$/i', $arg, $m ) ) { | ||
| return null; | ||
| } | ||
| if ( '' !== $m[1] ) { | ||
| return $m[2]; | ||
| } | ||
| $ns = Namespaces::determineNamespace( $file, $ptr ); | ||
| return '' === $ns ? $m[2] : "$ns\\$m[2]"; | ||
| } | ||
|
|
||
| /** Whether the tokens are exactly a call of one of $names, `\` allowed. */ | ||
| private static function call( array $tokens, array $op, array $names ): bool { | ||
| $fn = in_array( $tokens[ $op[0] ]['code'] ?? null, [ T_STRING, T_NAME_FULLY_QUALIFIED ], true ); | ||
| if ( ! $fn || ! in_array( strtolower( ltrim( $tokens[ $op[0] ]['content'], '\\' ) ), $names, true ) || count( $op ) < 3 ) { | ||
| return false; | ||
| } | ||
| return T_OPEN_PARENTHESIS === $tokens[ $op[1] ]['code'] && $tokens[ $op[1] ]['parenthesis_closer'] === end( $op ); | ||
| } | ||
|
|
||
| /** The pointers without parentheses around all of them. */ | ||
| private static function unwrap( array $tokens, array $op ): array { | ||
| while ( count( $op ) > 2 && T_OPEN_PARENTHESIS === $tokens[ $op[0] ]['code'] && $tokens[ $op[0] ]['parenthesis_closer'] === end( $op ) ) { | ||
| $op = array_slice( $op, 1, -1 ); | ||
| } | ||
| return $op; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.