Updated Rector to commit 8371040f72445fda4e96f29783b5de5351524c8a

8371040f72 [TypeDeclaration] Handle array with index assigned on TypedPropertyFromAssignsRector (#5861)
This commit is contained in:
Tomas Votruba 2024-05-08 13:00:27 +00:00
parent 582a864f33
commit dcdff77130
10 changed files with 50 additions and 30 deletions

View File

@ -5,8 +5,10 @@ namespace Rector\TypeDeclaration\Rector\Property;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\UnionType as NodeUnionType;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
@ -174,7 +176,7 @@ CODE_SAMPLE
}
$hasChanged = \true;
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
if ($inferredType instanceof UnionType) {
if ($inferredType instanceof UnionType && ($typeNode instanceof NodeUnionType || $typeNode instanceof NullableType)) {
$this->propertyTypeDecorator->decoratePropertyUnionType($inferredType, $typeNode, $property, $phpDocInfo, \false);
} else {
$property->type = $typeNode;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '650dcc6394c6df206772350e525311f8080e5077';
public const PACKAGE_VERSION = '8371040f72445fda4e96f29783b5de5351524c8a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-05-05 00:28:04';
public const RELEASE_DATE = '2024-05-08 19:56:34';
/**
* @var int
*/

View File

@ -248,6 +248,9 @@ final class UnionTypeMapper implements TypeMapperInterface
if ($phpParserUnionType instanceof PhpParserUnionType) {
return $this->resolveUnionTypeNode($unionType, $phpParserUnionType, $typeKind);
}
if ($phpParserUnionType instanceof Node) {
return $phpParserUnionType;
}
$type = $this->typeFactory->createMixedPassedOrUnionType($unionType->getTypes());
if (!$type instanceof UnionType) {
return $this->phpStanStaticTypeMapper->mapToPhpParserNode($type, $typeKind);
@ -271,9 +274,9 @@ final class UnionTypeMapper implements TypeMapperInterface
}
/**
* @param TypeKind::* $typeKind
* @return PhpParserUnionType|\PhpParser\Node\NullableType|null
* @return Name|FullyQualified|ComplexType|Identifier|null
*/
private function matchPhpParserUnionType(UnionType $unionType, string $typeKind)
private function matchPhpParserUnionType(UnionType $unionType, string $typeKind) : ?Node
{
$phpParserUnionedTypes = [];
foreach ($unionType->getTypes() as $unionedType) {
@ -296,7 +299,10 @@ final class UnionTypeMapper implements TypeMapperInterface
/** @var Identifier[]|Name[] $phpParserUnionedTypes */
$phpParserUnionedTypes = \array_unique($phpParserUnionedTypes);
$countPhpParserUnionedTypes = \count($phpParserUnionedTypes);
if ($countPhpParserUnionedTypes < 2) {
if ($countPhpParserUnionedTypes === 1) {
return $phpParserUnionedTypes[0];
}
if ($countPhpParserUnionedTypes === 0) {
return null;
}
return $this->resolveTypeWithNullablePHPParserUnionType(new PhpParserUnionType($phpParserUnionedTypes));

View File

@ -227,17 +227,17 @@
},
{
"name": "composer\/xdebug-handler",
"version": "3.0.4",
"version_normalized": "3.0.4.0",
"version": "3.0.5",
"version_normalized": "3.0.5.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/composer\/xdebug-handler.git",
"reference": "4f988f8fdf580d53bdb2d1278fe93d1ed5462255"
"reference": "6c1925561632e83d60a44492e0b344cf48ab85ef"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/composer\/xdebug-handler\/zipball\/4f988f8fdf580d53bdb2d1278fe93d1ed5462255",
"reference": "4f988f8fdf580d53bdb2d1278fe93d1ed5462255",
"url": "https:\/\/api.github.com\/repos\/composer\/xdebug-handler\/zipball\/6c1925561632e83d60a44492e0b344cf48ab85ef",
"reference": "6c1925561632e83d60a44492e0b344cf48ab85ef",
"shasum": ""
},
"require": {
@ -250,7 +250,7 @@
"phpstan\/phpstan-strict-rules": "^1.1",
"phpunit\/phpunit": "^8.5 || ^9.6 || ^10.5"
},
"time": "2024-03-26T18:29:49+00:00",
"time": "2024-05-06T16:37:16+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -276,7 +276,7 @@
"support": {
"irc": "ircs:\/\/irc.libera.chat:6697\/composer",
"issues": "https:\/\/github.com\/composer\/xdebug-handler\/issues",
"source": "https:\/\/github.com\/composer\/xdebug-handler\/tree\/3.0.4"
"source": "https:\/\/github.com\/composer\/xdebug-handler\/tree\/3.0.5"
},
"funding": [
{
@ -858,17 +858,17 @@
},
{
"name": "phpstan\/phpdoc-parser",
"version": "1.28.0",
"version_normalized": "1.28.0.0",
"version": "1.29.0",
"version_normalized": "1.29.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
"reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb"
"reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb",
"reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/536889f2b340489d328f5ffb7b02bb6b183ddedc",
"reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc",
"shasum": ""
},
"require": {
@ -885,7 +885,7 @@
"phpunit\/phpunit": "^9.5",
"symfony\/process": "^5.2"
},
"time": "2024-04-03T18:51:33+00:00",
"time": "2024-05-06T12:04:23+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -902,7 +902,7 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.28.0"
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.29.0"
},
"install-path": "..\/phpstan\/phpdoc-parser"
},

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,8 @@
## [Unreleased]
## [3.0.5] - 2024-05-06
* Fixed: fail restart if PHP_BINARY is not available
## [3.0.4] - 2024-03-26
* Added: Functional tests.
* Fixed: Incompatibility with PHPUnit 10.
@ -112,9 +115,10 @@
* Break: the following class was renamed:
- `Composer\XdebugHandler` -> `Composer\XdebugHandler\XdebugHandler`
[Unreleased]: https://github.com/composer/xdebug-handler/compare/3.0.4...HEAD
[3.0.3]: https://github.com/composer/xdebug-handler/compare/3.0.3...3.0.4
[3.0.2]: https://github.com/composer/xdebug-handler/compare/3.0.2...3.0.3
[Unreleased]: https://github.com/composer/xdebug-handler/compare/3.0.5...HEAD
[3.0.5]: https://github.com/composer/xdebug-handler/compare/3.0.4...3.0.5
[3.0.4]: https://github.com/composer/xdebug-handler/compare/3.0.3...3.0.4
[3.0.3]: https://github.com/composer/xdebug-handler/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/composer/xdebug-handler/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/composer/xdebug-handler/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/composer/xdebug-handler/compare/2.0.3...3.0.0

View File

@ -471,6 +471,10 @@ class XdebugHandler
$info = 'proc_open function is disabled';
return \false;
}
if (!\file_exists(\PHP_BINARY)) {
$info = 'PHP_BINARY is not available';
return \false;
}
if (\extension_loaded('uopz') && !(bool) \ini_get('uopz.disable')) {
// uopz works at opcode level and disables exit calls
if (\function_exists('uopz_allow_exit')) {

View File

@ -18,7 +18,7 @@ class OffsetAccessTypeNode implements \PHPStan\PhpDocParser\Ast\Type\TypeNode
}
public function __toString() : string
{
if ($this->type instanceof \PHPStan\PhpDocParser\Ast\Type\CallableTypeNode || $this->type instanceof \PHPStan\PhpDocParser\Ast\Type\ConstTypeNode || $this->type instanceof \PHPStan\PhpDocParser\Ast\Type\NullableTypeNode) {
if ($this->type instanceof \PHPStan\PhpDocParser\Ast\Type\CallableTypeNode || $this->type instanceof \PHPStan\PhpDocParser\Ast\Type\NullableTypeNode) {
return '(' . $this->type . ')[' . $this->offset . ']';
}
return $this->type . '[' . $this->offset . ']';

View File

@ -172,7 +172,11 @@ class TypeParser
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
throw new \PHPStan\PhpDocParser\Parser\ParserException($currentTokenValue, $currentTokenType, $currentTokenOffset, Lexer::TOKEN_IDENTIFIER, null, $currentTokenLine);
}
return $this->enrichWithAttributes($tokens, new Ast\Type\ConstTypeNode($constExpr), $startLine, $startIndex);
$type = $this->enrichWithAttributes($tokens, new Ast\Type\ConstTypeNode($constExpr), $startLine, $startIndex);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
}
return $type;
} catch (LogicException $e) {
throw new \PHPStan\PhpDocParser\Parser\ParserException($currentTokenValue, $currentTokenType, $currentTokenOffset, Lexer::TOKEN_IDENTIFIER, null, $currentTokenLine);
}
@ -497,9 +501,9 @@ class TypeParser
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
throw new \PHPStan\PhpDocParser\Parser\ParserException($currentTokenValue, $currentTokenType, $currentTokenOffset, Lexer::TOKEN_IDENTIFIER, null, $currentTokenLine);
}
$type = new Ast\Type\ConstTypeNode($constExpr);
$type = $this->enrichWithAttributes($tokens, new Ast\Type\ConstTypeNode($constExpr), $startLine, $startIndex);
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
$type = $this->tryParseArrayOrOffsetAccess($tokens, $this->enrichWithAttributes($tokens, $type, $startLine, $startIndex));
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
}
return $type;
} catch (LogicException $e) {

View File

@ -101,7 +101,7 @@ final class Printer
*/
private $emptyListInsertionMap = [CallableTypeNode::class . '->parameters' => ['(', '', ''], ArrayShapeNode::class . '->items' => ['{', '', ''], ObjectShapeNode::class . '->items' => ['{', '', ''], DoctrineArray::class . '->items' => ['{', '', ''], DoctrineAnnotation::class . '->arguments' => ['(', '', '']];
/** @var array<string, list<class-string<TypeNode>>> */
private $parenthesesMap = [CallableTypeNode::class . '->returnType' => [CallableTypeNode::class, UnionTypeNode::class, IntersectionTypeNode::class], ArrayTypeNode::class . '->type' => [CallableTypeNode::class, UnionTypeNode::class, IntersectionTypeNode::class, ConstTypeNode::class, NullableTypeNode::class], OffsetAccessTypeNode::class . '->type' => [CallableTypeNode::class, UnionTypeNode::class, IntersectionTypeNode::class, ConstTypeNode::class, NullableTypeNode::class]];
private $parenthesesMap = [CallableTypeNode::class . '->returnType' => [CallableTypeNode::class, UnionTypeNode::class, IntersectionTypeNode::class], ArrayTypeNode::class . '->type' => [CallableTypeNode::class, UnionTypeNode::class, IntersectionTypeNode::class, ConstTypeNode::class, NullableTypeNode::class], OffsetAccessTypeNode::class . '->type' => [CallableTypeNode::class, UnionTypeNode::class, IntersectionTypeNode::class, NullableTypeNode::class]];
/** @var array<string, list<class-string<TypeNode>>> */
private $parenthesesListMap = [IntersectionTypeNode::class . '->types' => [IntersectionTypeNode::class, UnionTypeNode::class, NullableTypeNode::class], UnionTypeNode::class . '->types' => [IntersectionTypeNode::class, UnionTypeNode::class, NullableTypeNode::class]];
public function printFormatPreserving(PhpDocNode $node, PhpDocNode $originalNode, TokenIterator $originalTokens) : string
@ -386,7 +386,7 @@ final class Printer
}
private function printOffsetAccessType(TypeNode $type) : string
{
if ($type instanceof CallableTypeNode || $type instanceof UnionTypeNode || $type instanceof IntersectionTypeNode || $type instanceof ConstTypeNode || $type instanceof NullableTypeNode) {
if ($type instanceof CallableTypeNode || $type instanceof UnionTypeNode || $type instanceof IntersectionTypeNode || $type instanceof NullableTypeNode) {
return $this->wrapInParentheses($type);
}
return $this->printType($type);