|
2 | 2 |
|
3 | 3 | namespace PHPStan\Analyser;
|
4 | 4 |
|
| 5 | +use Composer\Pcre\Preg; |
5 | 6 | use Countable;
|
6 | 7 | use PhpParser\Node;
|
7 | 8 | use PhpParser\Node\Expr;
|
@@ -1911,6 +1912,18 @@ public function resolveEqual(Expr\BinaryOp\Equal $expr, Scope $scope, TypeSpecif
|
1911 | 1912 | ) {
|
1912 | 1913 | return $this->specifyTypesInCondition($scope, new Expr\BinaryOp\Identical($expr->left, $expr->right), $context, $rootExpr);
|
1913 | 1914 | }
|
| 1915 | + |
| 1916 | + if ( |
| 1917 | + $context->true() |
| 1918 | + && $exprNode instanceof StaticCall |
| 1919 | + && $exprNode->class instanceof Name |
| 1920 | + && $exprNode->class->toString() === Preg::class |
| 1921 | + && $exprNode->name instanceof Node\Identifier |
| 1922 | + && $exprNode->name->toLowerString() === 'match' |
| 1923 | + && (new ConstantIntegerType(1))->isSuperTypeOf($constantType)->yes() |
| 1924 | + ) { |
| 1925 | + return $this->specifyTypesInCondition($scope, new Expr\BinaryOp\Identical($expr->left, $expr->right), $context, $rootExpr); |
| 1926 | + } |
1914 | 1927 | }
|
1915 | 1928 |
|
1916 | 1929 | $leftType = $scope->getType($expr->left);
|
@@ -2015,6 +2028,23 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
|
2015 | 2028 | );
|
2016 | 2029 | }
|
2017 | 2030 |
|
| 2031 | + if ( |
| 2032 | + $context->true() |
| 2033 | + && $unwrappedLeftExpr instanceof StaticCall |
| 2034 | + && $unwrappedLeftExpr->class instanceof Name |
| 2035 | + && $unwrappedLeftExpr->class->toString() === Preg::class |
| 2036 | + && $unwrappedLeftExpr->name instanceof Node\Identifier |
| 2037 | + && $unwrappedLeftExpr->name->toLowerString() === 'match' |
| 2038 | + && (new ConstantIntegerType(1))->isSuperTypeOf($rightType)->yes() |
| 2039 | + ) { |
| 2040 | + return $this->specifyTypesInCondition( |
| 2041 | + $scope, |
| 2042 | + $leftExpr, |
| 2043 | + $context, |
| 2044 | + $rootExpr, |
| 2045 | + ); |
| 2046 | + } |
| 2047 | + |
2018 | 2048 | if (
|
2019 | 2049 | $context->true()
|
2020 | 2050 | && $unwrappedLeftExpr instanceof FuncCall
|
|
0 commit comments