mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 91ebee8f0771ec3dbfbb1108e996ecf2351e6e9a
91ebee8f07
[TypeDeclaration] Skip union mixed on TypedPropertyFromAssignsRector (#3160)
This commit is contained in:
parent
228e63ca2e
commit
80576040f6
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\BetterPhpDocParser\Guard;
|
||||
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
final class NewPhpDocFromPHPStanTypeGuard
|
||||
{
|
||||
public function isLegal(Type $type) : bool
|
||||
{
|
||||
if ($type instanceof UnionType) {
|
||||
return $this->isLegalUnionType($type);
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
private function isLegalUnionType(UnionType $type) : bool
|
||||
{
|
||||
foreach ($type->getTypes() as $unionType) {
|
||||
if ($unionType instanceof MixedType) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NeverType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\Comment\CommentsMerger;
|
||||
use Rector\BetterPhpDocParser\Guard\NewPhpDocFromPHPStanTypeGuard;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareIntersectionTypeNode;
|
||||
@ -70,7 +71,12 @@ final class PhpDocTypeChanger
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
public function __construct(StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator, ParamPhpDocNodeFactory $paramPhpDocNodeFactory, NodeNameResolver $nodeNameResolver, CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\Guard\NewPhpDocFromPHPStanTypeGuard
|
||||
*/
|
||||
private $newPhpDocFromPHPStanTypeGuard;
|
||||
public function __construct(StaticTypeMapper $staticTypeMapper, TypeComparator $typeComparator, ParamPhpDocNodeFactory $paramPhpDocNodeFactory, NodeNameResolver $nodeNameResolver, CommentsMerger $commentsMerger, PhpDocInfoFactory $phpDocInfoFactory, NewPhpDocFromPHPStanTypeGuard $newPhpDocFromPHPStanTypeGuard)
|
||||
{
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
$this->typeComparator = $typeComparator;
|
||||
@ -78,6 +84,7 @@ final class PhpDocTypeChanger
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->commentsMerger = $commentsMerger;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->newPhpDocFromPHPStanTypeGuard = $newPhpDocFromPHPStanTypeGuard;
|
||||
}
|
||||
public function changeVarType(PhpDocInfo $phpDocInfo, Type $newType) : void
|
||||
{
|
||||
@ -93,6 +100,9 @@ final class PhpDocTypeChanger
|
||||
if (!$phpDocInfo->getVarType() instanceof MixedType && $newType instanceof ConstantArrayType && $newType->getItemType() instanceof NeverType) {
|
||||
return;
|
||||
}
|
||||
if (!$this->newPhpDocFromPHPStanTypeGuard->isLegal($newType)) {
|
||||
return;
|
||||
}
|
||||
// override existing type
|
||||
$newPHPStanPhpDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($newType, TypeKind::PROPERTY);
|
||||
$currentVarTagValueNode = $phpDocInfo->getVarTagValueNode();
|
||||
@ -116,6 +126,9 @@ final class PhpDocTypeChanger
|
||||
if ($this->typeComparator->areTypesEqual($phpDocInfo->getReturnType(), $newType)) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->newPhpDocFromPHPStanTypeGuard->isLegal($newType)) {
|
||||
return \false;
|
||||
}
|
||||
// override existing type
|
||||
$newPHPStanPhpDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($newType, TypeKind::RETURN);
|
||||
$currentReturnTagValueNode = $phpDocInfo->getReturnTagValue();
|
||||
@ -136,6 +149,9 @@ final class PhpDocTypeChanger
|
||||
if ($phpDocInfo->hasInvalidTag('@param')) {
|
||||
return;
|
||||
}
|
||||
if (!$this->newPhpDocFromPHPStanTypeGuard->isLegal($newType)) {
|
||||
return;
|
||||
}
|
||||
$phpDocType = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($newType, TypeKind::PARAM);
|
||||
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($paramName);
|
||||
// override existing type
|
||||
|
@ -17,12 +17,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '001fb3fe9252b8f03705caf5bd288a513834a8a8';
|
||||
public const PACKAGE_VERSION = '91ebee8f0771ec3dbfbb1108e996ecf2351e6e9a';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-12-05 16:40:33';
|
||||
public const RELEASE_DATE = '2022-12-06 17:24:48';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit5442c2ac1f5d4a84208fc38da4ce6513::getLoader();
|
||||
return ComposerAutoloaderInit18e07a90b8778f48b3b664108320cf95::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1071,6 +1071,7 @@ return array(
|
||||
'Rector\\BetterPhpDocParser\\Contract\\BasePhpDocNodeVisitorInterface' => $baseDir . '/packages/BetterPhpDocParser/Contract/BasePhpDocNodeVisitorInterface.php',
|
||||
'Rector\\BetterPhpDocParser\\Contract\\PhpDocParser\\PhpDocNodeDecoratorInterface' => $baseDir . '/packages/BetterPhpDocParser/Contract/PhpDocParser/PhpDocNodeDecoratorInterface.php',
|
||||
'Rector\\BetterPhpDocParser\\DataProvider\\CurrentTokenIteratorProvider' => $baseDir . '/packages/BetterPhpDocParser/DataProvider/CurrentTokenIteratorProvider.php',
|
||||
'Rector\\BetterPhpDocParser\\Guard\\NewPhpDocFromPHPStanTypeGuard' => $baseDir . '/packages/BetterPhpDocParser/Guard/NewPhpDocFromPHPStanTypeGuard.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo' => $baseDir . '/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfoFactory' => $baseDir . '/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocInfo\\TokenIteratorFactory' => $baseDir . '/packages/BetterPhpDocParser/PhpDocInfo/TokenIteratorFactory.php',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit5442c2ac1f5d4a84208fc38da4ce6513
|
||||
class ComposerAutoloaderInit18e07a90b8778f48b3b664108320cf95
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,19 +22,19 @@ class ComposerAutoloaderInit5442c2ac1f5d4a84208fc38da4ce6513
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5442c2ac1f5d4a84208fc38da4ce6513', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit18e07a90b8778f48b3b664108320cf95', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5442c2ac1f5d4a84208fc38da4ce6513', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit18e07a90b8778f48b3b664108320cf95', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit18e07a90b8778f48b3b664108320cf95::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit18e07a90b8778f48b3b664108320cf95::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire5442c2ac1f5d4a84208fc38da4ce6513($fileIdentifier, $file);
|
||||
composerRequire18e07a90b8778f48b3b664108320cf95($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
@ -46,7 +46,7 @@ class ComposerAutoloaderInit5442c2ac1f5d4a84208fc38da4ce6513
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire5442c2ac1f5d4a84208fc38da4ce6513($fileIdentifier, $file)
|
||||
function composerRequire18e07a90b8778f48b3b664108320cf95($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513
|
||||
class ComposerStaticInit18e07a90b8778f48b3b664108320cf95
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -1311,6 +1311,7 @@ class ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513
|
||||
'Rector\\BetterPhpDocParser\\Contract\\BasePhpDocNodeVisitorInterface' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Contract/BasePhpDocNodeVisitorInterface.php',
|
||||
'Rector\\BetterPhpDocParser\\Contract\\PhpDocParser\\PhpDocNodeDecoratorInterface' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Contract/PhpDocParser/PhpDocNodeDecoratorInterface.php',
|
||||
'Rector\\BetterPhpDocParser\\DataProvider\\CurrentTokenIteratorProvider' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/DataProvider/CurrentTokenIteratorProvider.php',
|
||||
'Rector\\BetterPhpDocParser\\Guard\\NewPhpDocFromPHPStanTypeGuard' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Guard/NewPhpDocFromPHPStanTypeGuard.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfoFactory' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocInfo\\TokenIteratorFactory' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocInfo/TokenIteratorFactory.php',
|
||||
@ -3019,9 +3020,9 @@ class ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5442c2ac1f5d4a84208fc38da4ce6513::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit18e07a90b8778f48b3b664108320cf95::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit18e07a90b8778f48b3b664108320cf95::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit18e07a90b8778f48b3b664108320cf95::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user