Updated Rector to commit 52aa64ffe2cc0add4cbffede6ce36cbec576ef2f

52aa64ffe2 [DeadCode] Clean up TypeHasher on Union Type (#5792)
This commit is contained in:
Tomas Votruba 2024-04-03 06:21:54 +00:00
parent dc2feca4d5
commit 3fdaba944f
20 changed files with 59 additions and 70 deletions

View File

@ -123,7 +123,7 @@ CODE_SAMPLE
}
/**
* @param int|float $rangeLine
* @return int|float
* @return float|int
*/
private function resolveRangeLineFromComment($rangeLine, int $line, int $endLine, Stmt $nextStmt)
{

View File

@ -3,8 +3,10 @@
declare (strict_types=1);
namespace Rector\DeadCode\PhpDoc;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
@ -68,6 +70,9 @@ final class DeadParamTagValueNodeAnalyzer
if ($paramTagValueNode->description !== '') {
return \false;
}
if ($paramTagValueNode->type instanceof UnionTypeNode && $param->type instanceof FullyQualified) {
return \false;
}
if ($param->type instanceof Name && $this->nodeNameResolver->isName($param->type, 'object')) {
return $paramTagValueNode->type instanceof IdentifierTypeNode && (string) $paramTagValueNode->type === 'object';
}
@ -80,9 +85,13 @@ final class DeadParamTagValueNodeAnalyzer
if (!$paramTagValueNode->type instanceof BracketsAwareUnionTypeNode) {
return \true;
}
if ($this->mixedArrayTypeNodeAnalyzer->hasMixedArrayType($paramTagValueNode->type)) {
return $this->isAllowedBracketAwareUnion($paramTagValueNode->type);
}
private function isAllowedBracketAwareUnion(BracketsAwareUnionTypeNode $bracketsAwareUnionTypeNode) : bool
{
if ($this->mixedArrayTypeNodeAnalyzer->hasMixedArrayType($bracketsAwareUnionTypeNode)) {
return \false;
}
return !$this->genericTypeNodeAnalyzer->hasGenericType($paramTagValueNode->type);
return !$this->genericTypeNodeAnalyzer->hasGenericType($bracketsAwareUnionTypeNode);
}
}

View File

@ -7,7 +7,6 @@ use PhpParser\Node\FunctionLike;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\DeadCode\PhpDoc\DeadParamTagValueNodeAnalyzer;

View File

@ -13,7 +13,7 @@ final class AnnotationPropertyToAttributeClass
private $attributeClass;
/**
* @readonly
* @var string|int|null
* @var int|string|null
*/
private $annotationProperty = null;
/**
@ -32,7 +32,7 @@ final class AnnotationPropertyToAttributeClass
RectorAssert::className($attributeClass);
}
/**
* @return string|int|null
* @return int|string|null
*/
public function getAnnotationProperty()
{

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'ef333de3d58a4649558971b19f4814fd92823abe';
public const PACKAGE_VERSION = '52aa64ffe2cc0add4cbffede6ce36cbec576ef2f';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-04-03 07:36:10';
public const RELEASE_DATE = '2024-04-03 13:19:32';
/**
* @var int
*/

View File

@ -4,7 +4,6 @@ declare (strict_types=1);
namespace Rector\NodeTypeResolver\PHPStan;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\ConstantType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\IterableType;
@ -13,7 +12,6 @@ use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverser;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
@ -41,9 +39,6 @@ final class TypeHasher
if ($type instanceof ConstantType) {
return \get_class($type);
}
if ($type instanceof UnionType) {
return $this->createUnionTypeHash($type);
}
$type = $this->normalizeObjectType($type);
// normalize iterable
$type = TypeTraverser::map($type, static function (Type $currentType, callable $traverseCallback) : Type {
@ -67,22 +62,6 @@ final class TypeHasher
}
return $typeWithClassName->getClassName();
}
private function createUnionTypeHash(UnionType $unionType) : string
{
$booleanType = new BooleanType();
if ($booleanType->isSuperTypeOf($unionType)->yes()) {
return $booleanType->describe(VerbosityLevel::precise());
}
$normalizedUnionType = clone $unionType;
// change alias to non-alias
TypeTraverser::map($normalizedUnionType, static function (Type $type, callable $callable) : Type {
if (!$type instanceof AliasedObjectType && !$type instanceof ShortenedObjectType) {
return $callable($type);
}
return new FullyQualifiedObjectType($type->getFullyQualifiedName());
});
return $normalizedUnionType->describe(VerbosityLevel::precise());
}
private function normalizeObjectType(Type $type) : Type
{
return TypeTraverser::map($type, static function (Type $currentType, callable $traverseCallback) : Type {

View File

@ -348,7 +348,7 @@ final class BetterStandardPrinter extends Standard
/**
* Invoke re-print even if only raw value was changed.
* That allows PHPStan to use int strict types, while changing the value with literal "_"
* @return string|int
* @return int|string
*/
protected function pScalar_LNumber(LNumber $lNumber)
{

View File

@ -1742,12 +1742,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "eadea252dae87d8703ce171ec8fb2682f455c5b9"
"reference": "1fc03517141811339be88a19bc4d2bd860c02a79"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/eadea252dae87d8703ce171ec8fb2682f455c5b9",
"reference": "eadea252dae87d8703ce171ec8fb2682f455c5b9",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/1fc03517141811339be88a19bc4d2bd860c02a79",
"reference": "1fc03517141811339be88a19bc4d2bd860c02a79",
"shasum": ""
},
"require": {
@ -1760,7 +1760,7 @@
"phpunit\/phpunit": "^10.3",
"rector\/phpstan-rules": "^0.7.4",
"rector\/rector-generator": "^0.7.3",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-clean-up-type-hasher",
"symplify\/easy-coding-standard": "^12.0",
"symplify\/phpstan-extensions": "^11.3",
"symplify\/phpstan-rules": "^12.4",
@ -1769,7 +1769,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-03-19T09:23:20+00:00",
"time": "2024-04-03T06:16:44+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1998,17 +1998,17 @@
},
{
"name": "symfony\/console",
"version": "v6.4.4",
"version_normalized": "6.4.4.0",
"version": "v6.4.6",
"version_normalized": "6.4.6.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/symfony\/console.git",
"reference": "0d9e4eb5ad413075624378f474c4167ea202de78"
"reference": "a2708a5da5c87d1d0d52937bdeac625df659e11f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symfony\/console\/zipball\/0d9e4eb5ad413075624378f474c4167ea202de78",
"reference": "0d9e4eb5ad413075624378f474c4167ea202de78",
"url": "https:\/\/api.github.com\/repos\/symfony\/console\/zipball\/a2708a5da5c87d1d0d52937bdeac625df659e11f",
"reference": "a2708a5da5c87d1d0d52937bdeac625df659e11f",
"shasum": ""
},
"require": {
@ -2041,7 +2041,7 @@
"symfony\/stopwatch": "^5.4|^6.0|^7.0",
"symfony\/var-dumper": "^5.4|^6.0|^7.0"
},
"time": "2024-02-22T20:27:10+00:00",
"time": "2024-03-29T19:07:53+00:00",
"type": "library",
"extra": {
"patches_applied": [
@ -2080,7 +2080,7 @@
"terminal"
],
"support": {
"source": "https:\/\/github.com\/symfony\/console\/tree\/v6.4.4"
"source": "https:\/\/github.com\/symfony\/console\/tree\/v6.4.6"
},
"funding": [
{
@ -2170,17 +2170,17 @@
},
{
"name": "symfony\/filesystem",
"version": "v6.4.3",
"version_normalized": "6.4.3.0",
"version": "v6.4.6",
"version_normalized": "6.4.6.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/symfony\/filesystem.git",
"reference": "7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb"
"reference": "9919b5509ada52cc7f66f9a35c86a4a29955c9d3"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symfony\/filesystem\/zipball\/7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb",
"reference": "7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb",
"url": "https:\/\/api.github.com\/repos\/symfony\/filesystem\/zipball\/9919b5509ada52cc7f66f9a35c86a4a29955c9d3",
"reference": "9919b5509ada52cc7f66f9a35c86a4a29955c9d3",
"shasum": ""
},
"require": {
@ -2188,7 +2188,7 @@
"symfony\/polyfill-ctype": "~1.8",
"symfony\/polyfill-mbstring": "~1.8"
},
"time": "2024-01-23T14:51:35+00:00",
"time": "2024-03-21T19:36:20+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -2216,7 +2216,7 @@
"description": "Provides basic utilities for the filesystem",
"homepage": "https:\/\/symfony.com",
"support": {
"source": "https:\/\/github.com\/symfony\/filesystem\/tree\/v6.4.3"
"source": "https:\/\/github.com\/symfony\/filesystem\/tree\/v6.4.6"
},
"funding": [
{

File diff suppressed because one or more lines are too long

View File

@ -95,7 +95,7 @@ final class Callback
}
/**
* Unwraps closure created by Closure::fromCallable().
* @return callable|mixed[]
* @return mixed[]|callable
*/
public static function unwrap(\Closure $closure)
{

View File

@ -50,7 +50,7 @@ class Helpers
* @param int|float $value
* @param int|float $min
* @param int|float $max
* @return int|float
* @return float|int
*/
public static function clamp($value, $min, $max)
{

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main b3da143'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main eadea25'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 6845db4'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main c8b6413'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main b3da143'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 1fc0351'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 6845db4'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main c8b6413'));
private function __construct()
{
}

View File

@ -13,7 +13,7 @@
"phpunit\/phpunit": "^10.3",
"rector\/phpstan-rules": "^0.7.4",
"rector\/rector-generator": "^0.7.3",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-clean-up-type-hasher",
"symplify\/easy-coding-standard": "^12.0",
"symplify\/phpstan-extensions": "^11.3",
"symplify\/phpstan-rules": "^12.4",

View File

@ -238,9 +238,9 @@ final class ProgressBar
{
$this->messages[$name] = $message;
}
public function getMessage(string $name = 'message') : string
public function getMessage(string $name = 'message') : ?string
{
return $this->messages[$name];
return $this->messages[$name] ?? null;
}
public function getStartTime() : int
{

View File

@ -366,7 +366,7 @@ class Table
foreach ($parts as $idx => $part) {
if ($headers && !$containsColspan) {
if (0 === $idx) {
$rows[] = [\sprintf('<comment>%s</>: %s', \str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT), $part)];
$rows[] = [\sprintf('<comment>%s%s</>: %s', \str_repeat(' ', $maxHeaderLength - Helper::width(Helper::removeDecoration($formatter, $headers[$i] ?? ''))), $headers[$i] ?? '', $part)];
} else {
$rows[] = [\sprintf('%s %s', \str_pad('', $maxHeaderLength, ' ', \STR_PAD_LEFT), $part)];
}

View File

@ -35,7 +35,7 @@ class InputArgument
*/
private $mode;
/**
* @var string|int|bool|mixed[]|null|float
* @var mixed[]|bool|float|int|string|null
*/
private $default;
/**
@ -120,7 +120,7 @@ class InputArgument
}
/**
* Returns the default value.
* @return string|bool|int|float|mixed[]|null
* @return mixed[]|bool|float|int|string|null
*/
public function getDefault()
{

View File

@ -48,7 +48,7 @@ class InputOption
*/
private $name;
/**
* @var string|mixed[]|null
* @var mixed[]|string|null
*/
private $shortcut;
/**
@ -56,7 +56,7 @@ class InputOption
*/
private $mode;
/**
* @var string|int|bool|mixed[]|null|float
* @var mixed[]|bool|float|int|string|null
*/
private $default;
/**
@ -195,7 +195,7 @@ class InputOption
}
/**
* Returns the default value.
* @return string|bool|int|float|mixed[]|null
* @return mixed[]|bool|float|int|string|null
*/
public function getDefault()
{

View File

@ -44,7 +44,7 @@ class Question
*/
private $validator;
/**
* @var string|int|bool|null|float
* @var bool|float|int|string|null
*/
private $default;
/**
@ -77,7 +77,7 @@ class Question
}
/**
* Returns the default answer.
* @return string|bool|int|float|null
* @return bool|float|int|string|null
*/
public function getDefault()
{

View File

@ -66,6 +66,8 @@ class Filesystem
if ($originIsLocal) {
// Like `cp`, preserve executable permission bits
self::box('chmod', $targetFile, \fileperms($targetFile) | \fileperms($originFile) & 0111);
// Like `cp`, preserve the file modification time
self::box('touch', $targetFile, \filemtime($originFile));
if ($bytesCopied !== ($bytesOrigin = \filesize($originFile))) {
throw new IOException(\sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
}
@ -178,7 +180,7 @@ class Filesystem
}
throw new IOException(\sprintf('Failed to remove directory "%s": ', $file) . $lastError);
}
} elseif (!self::box('unlink', $file) && (\strpos(self::$lastError, 'Permission denied') !== \false || \file_exists($file))) {
} elseif (!self::box('unlink', $file) && (self::$lastError && \strpos(self::$lastError, 'Permission denied') !== \false || \file_exists($file))) {
throw new IOException(\sprintf('Failed to remove file "%s": ', $file) . self::$lastError);
}
}

View File

@ -36,13 +36,13 @@ if (!function_exists('mb_convert_case')) {
}
if (!function_exists('mb_internal_encoding')) {
/**
* @return string|bool
* @return bool|string
*/
function mb_internal_encoding(?string $encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); }
}
if (!function_exists('mb_language')) {
/**
* @return string|bool
* @return bool|string
*/
function mb_language(?string $language = null) { return p\Mbstring::mb_language($language); }
}
@ -93,7 +93,7 @@ if (!function_exists('mb_strtoupper')) {
if (!function_exists('mb_substitute_character')) {
/**
* @param string|int|null $substitute_character
* @return string|int|bool
* @return bool|int|string
*/
function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); }
}
@ -144,13 +144,13 @@ if (!function_exists('mb_strstr')) {
}
if (!function_exists('mb_get_info')) {
/**
* @return mixed[]|string|int|false
* @return mixed[]|int|string|false
*/
function mb_get_info(?string $type = 'all') { return p\Mbstring::mb_get_info((string) $type); }
}
if (!function_exists('mb_http_output')) {
/**
* @return string|bool
* @return bool|string
*/
function mb_http_output(?string $encoding = null) { return p\Mbstring::mb_http_output($encoding); }
}