Updated Rector to commit 816c73347df4a5e4da48903af1190c131fcccb8c

816c73347d [CodeQuality] Handle crash on first class callable inside match on OptionalParametersAfterRequiredRector (#6263)
This commit is contained in:
Tomas Votruba 2024-08-28 11:50:11 +00:00
parent 6d509ddbaa
commit f9441cf43d
7 changed files with 57 additions and 15 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '8073ee7922196df0941dafa3a90542776d710f5a';
public const PACKAGE_VERSION = '816c73347df4a5e4da48903af1190c131fcccb8c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-27 21:30:17';
public const RELEASE_DATE = '2024-08-28 18:47:29';
/**
* @var int
*/

View File

@ -16,6 +16,7 @@ use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Match_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\NullsafeMethodCall;
@ -251,6 +252,10 @@ final class PHPStanNodeScopeResolver
$this->processCallike($node, $mutatingScope);
return;
}
if ($node instanceof Match_) {
$this->processMatch($node, $mutatingScope);
return;
}
};
$this->nodeScopeResolverProcessNodes($stmts, $scope, $nodeCallback);
$nodeTraverser = new NodeTraverser();
@ -261,6 +266,18 @@ final class PHPStanNodeScopeResolver
$nodeTraverser->traverse($stmts);
return $stmts;
}
private function processMatch(Match_ $match, MutatingScope $mutatingScope) : void
{
$match->cond->setAttribute(AttributeKey::SCOPE, $mutatingScope);
foreach ($match->arms as $arm) {
if ($arm->conds !== null) {
foreach ($arm->conds as $cond) {
$cond->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
}
$arm->body->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
}
/**
* @param Stmt[] $stmts
* @param callable(Node $node, MutatingScope $scope): void $nodeCallback

View File

@ -69,17 +69,17 @@
},
{
"name": "composer\/pcre",
"version": "3.3.0",
"version_normalized": "3.3.0.0",
"version": "3.3.1",
"version_normalized": "3.3.1.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/composer\/pcre.git",
"reference": "1637e067347a0c40bbb1e3cd786b20dcab556a81"
"reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/1637e067347a0c40bbb1e3cd786b20dcab556a81",
"reference": "1637e067347a0c40bbb1e3cd786b20dcab556a81",
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/63aaeac21d7e775ff9bc9d45021e1745c97521c4",
"reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4",
"shasum": ""
},
"require": {
@ -93,7 +93,7 @@
"phpstan\/phpstan-strict-rules": "^1.1",
"phpunit\/phpunit": "^8 || ^9"
},
"time": "2024-08-19T19:43:53+00:00",
"time": "2024-08-27T18:44:43+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -131,7 +131,7 @@
],
"support": {
"issues": "https:\/\/github.com\/composer\/pcre\/issues",
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.3.0"
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.3.1"
},
"funding": [
{

File diff suppressed because one or more lines are too long

View File

@ -4,11 +4,16 @@ declare (strict_types=1);
namespace RectorPrefix202408\Composer\Pcre\PHPStan;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\Type;
use PhpParser\Node\Arg;
use PHPStan\Type\Php\RegexArrayShapeMatcher;
use PHPStan\Type\TypeTraverser;
use PHPStan\Type\UnionType;
final class PregMatchFlags
{
public static function getType(?Arg $flagsArg, Scope $scope) : ?Type
@ -30,4 +35,21 @@ final class PregMatchFlags
}
return TypeCombinator::union(...$internalFlagsTypes);
}
public static function removeNullFromMatches(Type $matchesType) : Type
{
return TypeTraverser::map($matchesType, static function (Type $type, callable $traverse) : Type {
if ($type instanceof UnionType || $type instanceof IntersectionType) {
return $traverse($type);
}
if ($type instanceof ConstantArrayType) {
return new ConstantArrayType($type->getKeyTypes(), \array_map(static function (Type $valueType) use($traverse) : Type {
return $traverse($valueType);
}, $type->getValueTypes()), $type->getNextAutoIndexes(), [], $type->isList());
}
if ($type instanceof ArrayType) {
return new ArrayType($type->getKeyType(), $traverse($type->getItemType()));
}
return TypeCombinator::removeNull($type);
});
}
}

View File

@ -64,11 +64,8 @@ final class PregMatchTypeSpecifyingExtension implements StaticMethodTypeSpecifyi
if ($matchedType === null) {
return new SpecifiedTypes();
}
if (\in_array($methodReflection->getName(), ['matchStrictGroups', 'isMatchStrictGroups'], \true) && \count($matchedType->getConstantArrays()) === 1) {
$matchedType = $matchedType->getConstantArrays()[0];
$matchedType = new ConstantArrayType($matchedType->getKeyTypes(), \array_map(static function (Type $valueType) : Type {
return TypeCombinator::removeNull($valueType);
}, $matchedType->getValueTypes()), $matchedType->getNextAutoIndexes(), [], $matchedType->isList());
if (\in_array($methodReflection->getName(), ['matchStrictGroups', 'isMatchStrictGroups', 'matchAllStrictGroups', 'isMatchAllStrictGroups'], \true)) {
$matchedType = PregMatchFlags::removeNullFromMatches($matchedType);
}
$overwrite = \false;
if ($context->false()) {

View File

@ -48,6 +48,12 @@ final class PregReplaceCallbackClosureTypeExtension implements StaticMethodParam
if ($methodReflection->getName() === 'replaceCallbackStrictGroups' && \count($matchesType->getConstantArrays()) === 1) {
$matchesType = $matchesType->getConstantArrays()[0];
$matchesType = new ConstantArrayType($matchesType->getKeyTypes(), \array_map(static function (Type $valueType) : Type {
if (\count($valueType->getConstantArrays()) === 1) {
$valueTypeArray = $valueType->getConstantArrays()[0];
return new ConstantArrayType($valueTypeArray->getKeyTypes(), \array_map(static function (Type $valueType) : Type {
return TypeCombinator::removeNull($valueType);
}, $valueTypeArray->getValueTypes()), $valueTypeArray->getNextAutoIndexes(), [], $valueTypeArray->isList());
}
return TypeCombinator::removeNull($valueType);
}, $matchesType->getValueTypes()), $matchesType->getNextAutoIndexes(), [], $matchesType->isList());
}