mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-29 14:13:30 +00:00
Updated Rector to commit 130b634b5e
130b634b5e
[PHP 8.0] Skip union types docs to code with soft vendor lock (#781)
This commit is contained in:
parent
dbe62b466e
commit
681b789419
|
@ -30,6 +30,22 @@ final class ClassMethodParamVendorLockResolver
|
|||
$this->pathNormalizer = $pathNormalizer;
|
||||
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
|
||||
}
|
||||
/**
|
||||
* Includes non-vendor classes
|
||||
*/
|
||||
public function isSoftLocked(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
|
||||
{
|
||||
if ($this->isVendorLocked($classMethod)) {
|
||||
return \true;
|
||||
}
|
||||
$classReflection = $this->resolveClassReflection($classMethod);
|
||||
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
|
||||
return \false;
|
||||
}
|
||||
/** @var string $methodName */
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
return $this->hasClassMethodLockMatchingFileName($classReflection, $methodName, '');
|
||||
}
|
||||
public function isVendorLocked(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
|
||||
{
|
||||
if ($classMethod->isMagic()) {
|
||||
|
@ -48,26 +64,9 @@ final class ClassMethodParamVendorLockResolver
|
|||
if ($this->hasParentInterfaceMethod($classReflection, $methodName)) {
|
||||
return \true;
|
||||
}
|
||||
/** @var string $methodName */
|
||||
$methodName = $this->nodeNameResolver->getName($classMethod);
|
||||
foreach ($classReflection->getAncestors() as $ancestorClassReflection) {
|
||||
// skip self
|
||||
if ($ancestorClassReflection === $classReflection) {
|
||||
continue;
|
||||
}
|
||||
// parent type
|
||||
if (!$ancestorClassReflection->hasNativeMethod($methodName)) {
|
||||
continue;
|
||||
}
|
||||
// is file in vendor?
|
||||
$fileName = $ancestorClassReflection->getFileName();
|
||||
// probably internal class
|
||||
if ($fileName === \false) {
|
||||
continue;
|
||||
}
|
||||
$normalizedFileName = $this->pathNormalizer->normalizePath($fileName, '/');
|
||||
return \strpos($normalizedFileName, '/vendor/') !== \false;
|
||||
}
|
||||
return \false;
|
||||
return $this->hasClassMethodLockMatchingFileName($classReflection, $methodName, '/vendor/');
|
||||
}
|
||||
private function hasTraitMethodVendorLock(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName) : bool
|
||||
{
|
||||
|
@ -107,4 +106,32 @@ final class ClassMethodParamVendorLockResolver
|
|||
}
|
||||
return \false;
|
||||
}
|
||||
private function hasClassMethodLockMatchingFileName(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName, string $filePathPartName) : bool
|
||||
{
|
||||
foreach ($classReflection->getAncestors() as $ancestorClassReflection) {
|
||||
// skip self
|
||||
if ($ancestorClassReflection === $classReflection) {
|
||||
continue;
|
||||
}
|
||||
// parent type
|
||||
if (!$ancestorClassReflection->hasNativeMethod($methodName)) {
|
||||
continue;
|
||||
}
|
||||
// is file in vendor?
|
||||
$fileName = $ancestorClassReflection->getFileName();
|
||||
// probably internal class
|
||||
if ($fileName === \false) {
|
||||
continue;
|
||||
}
|
||||
// not conditions? its a match
|
||||
if ($filePathPartName === '') {
|
||||
return \true;
|
||||
}
|
||||
$normalizedFileName = $this->pathNormalizer->normalizePath($fileName, '/');
|
||||
if (\strpos($normalizedFileName, $filePathPartName) !== \false) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*/
|
||||
final class UnionTypesRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $hasChanged = \false;
|
||||
/**
|
||||
* @var \Rector\DeadCode\PhpDoc\TagRemover\ReturnTagRemover
|
||||
*/
|
||||
|
@ -95,12 +99,19 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
$this->hasChanged = \false;
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$this->refactorParamTypes($node, $phpDocInfo);
|
||||
$this->refactorReturnType($node, $phpDocInfo);
|
||||
$this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $node);
|
||||
$this->returnTagRemover->removeReturnTagIfUseless($phpDocInfo, $node);
|
||||
return $node;
|
||||
if ($phpDocInfo->hasChanged()) {
|
||||
$this->hasChanged = \true;
|
||||
}
|
||||
if ($this->hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
|
@ -111,7 +122,8 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function refactorParamTypes($functionLike, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : void
|
||||
{
|
||||
if ($functionLike instanceof \PhpParser\Node\Stmt\ClassMethod && $this->classMethodParamVendorLockResolver->isVendorLocked($functionLike)) {
|
||||
// skip parent class lock too, just to be safe in case of different parent docs
|
||||
if ($functionLike instanceof \PhpParser\Node\Stmt\ClassMethod && $this->classMethodParamVendorLockResolver->isSoftLocked($functionLike)) {
|
||||
return;
|
||||
}
|
||||
foreach ($functionLike->getParams() as $param) {
|
||||
|
@ -137,6 +149,7 @@ CODE_SAMPLE
|
|||
continue;
|
||||
}
|
||||
$param->type = $phpParserUnionType;
|
||||
$this->hasChanged = \true;
|
||||
}
|
||||
}
|
||||
private function changeObjectWithoutClassType(\PhpParser\Node\Param $param, \PHPStan\Type\UnionType $unionType) : void
|
||||
|
@ -145,6 +158,7 @@ CODE_SAMPLE
|
|||
return;
|
||||
}
|
||||
$param->type = new \PhpParser\Node\Name('object');
|
||||
$this->hasChanged = \true;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike
|
||||
|
@ -168,6 +182,7 @@ CODE_SAMPLE
|
|||
return;
|
||||
}
|
||||
$functionLike->returnType = $phpParserUnionType;
|
||||
$this->hasChanged = \true;
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\UnionType|\PHPStan\Type\Type
|
||||
|
|
|
@ -32,6 +32,10 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*/
|
||||
final class ParamTypeDeclarationRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $hasChanged = \false;
|
||||
/**
|
||||
* @var \Rector\VendorLocker\VendorLockResolver
|
||||
*/
|
||||
|
@ -125,12 +129,16 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
$this->hasChanged = \false;
|
||||
if ($node->params === []) {
|
||||
return null;
|
||||
}
|
||||
foreach ($node->params as $param) {
|
||||
$this->refactorParam($param, $node);
|
||||
}
|
||||
if ($this->hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
|
@ -166,6 +174,7 @@ CODE_SAMPLE
|
|||
$param->type = $paramTypeNode;
|
||||
$functionLikePhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
|
||||
$this->paramTagRemover->removeParamTagsIfUseless($functionLikePhpDocInfo, $functionLike);
|
||||
$this->hasChanged = \true;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'd8b3be9bfbd9b8b48f6d1fa8338ebdf7a9c53260';
|
||||
public const PACKAGE_VERSION = '130b634b5e348554c3349ed3b3f52fa3d08bfb6e';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-08-27 12:03:17';
|
||||
public const RELEASE_DATE = '2021-08-27 12:45:35';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210827\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4::getLoader();
|
||||
return ComposerAutoloaderInit7f860eba502439834b88cb7979fce466::getLoader();
|
||||
|
|
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 ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4
|
||||
class ComposerAutoloaderInit7f860eba502439834b88cb7979fce466
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit7f860eba502439834b88cb7979fce466', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit7f860eba502439834b88cb7979fce466', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7f860eba502439834b88cb7979fce466::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit7f860eba502439834b88cb7979fce466::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire2ba3ef93ce8b2ef845adfd29d592def4($fileIdentifier, $file);
|
||||
composerRequire7f860eba502439834b88cb7979fce466($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire2ba3ef93ce8b2ef845adfd29d592def4($fileIdentifier, $file)
|
||||
function composerRequire7f860eba502439834b88cb7979fce466($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4
|
||||
class ComposerStaticInit7f860eba502439834b88cb7979fce466
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3860,9 +3860,9 @@ class ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit2ba3ef93ce8b2ef845adfd29d592def4::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7f860eba502439834b88cb7979fce466::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit7f860eba502439834b88cb7979fce466::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit7f860eba502439834b88cb7979fce466::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4', false) && !interface_exists('ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4', false) && !trait_exists('ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\ComposerAutoloaderInit2ba3ef93ce8b2ef845adfd29d592def4');
|
||||
if (!class_exists('ComposerAutoloaderInit7f860eba502439834b88cb7979fce466', false) && !interface_exists('ComposerAutoloaderInit7f860eba502439834b88cb7979fce466', false) && !trait_exists('ComposerAutoloaderInit7f860eba502439834b88cb7979fce466', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\ComposerAutoloaderInit7f860eba502439834b88cb7979fce466');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -3311,9 +3311,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20210827\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire2ba3ef93ce8b2ef845adfd29d592def4')) {
|
||||
function composerRequire2ba3ef93ce8b2ef845adfd29d592def4() {
|
||||
return \RectorPrefix20210827\composerRequire2ba3ef93ce8b2ef845adfd29d592def4(...func_get_args());
|
||||
if (!function_exists('composerRequire7f860eba502439834b88cb7979fce466')) {
|
||||
function composerRequire7f860eba502439834b88cb7979fce466() {
|
||||
return \RectorPrefix20210827\composerRequire7f860eba502439834b88cb7979fce466(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user