Updated Rector to commit 7f49261e293df93ac9a81dd49e59ad4abed9ed41

7f49261e29 Make ReturnNeverTypeRector work with type declaration, add it to PHP 8.1 set (#3852)
This commit is contained in:
Tomas Votruba 2023-05-14 22:40:25 +00:00
parent 9496663b9b
commit 281f59d306
8 changed files with 24 additions and 60 deletions

View File

@ -17,16 +17,5 @@ use Rector\Php81\Rector\MethodCall\SpatieEnumMethodCallToEnumConstRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(ReturnNeverTypeRector::class);
$rectorConfig->rule(MyCLabsClassToEnumRector::class);
$rectorConfig->rule(MyCLabsMethodCallToEnumConstRector::class);
$rectorConfig->rule(FinalizePublicClassConstantRector::class);
$rectorConfig->rule(ReadOnlyPropertyRector::class);
$rectorConfig->rule(SpatieEnumClassToEnumRector::class);
$rectorConfig->rule(SpatieEnumMethodCallToEnumConstRector::class);
$rectorConfig->rule(Php81ResourceReturnToObjectRector::class);
$rectorConfig->rule(NewInInitializerRector::class);
$rectorConfig->rule(IntersectionTypesRector::class);
$rectorConfig->rule(NullToStrictStringFuncCallArgRector::class);
$rectorConfig->rule(FirstClassCallableRector::class);
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, FinalizePublicClassConstantRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, Php81ResourceReturnToObjectRector::class, NewInInitializerRector::class, IntersectionTypesRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class, ReturnNeverTypeRector::class]);
};

View File

@ -9357,10 +9357,8 @@ Add "never" return-type for methods that never return anything
```diff
final class SomeClass
{
+ /**
+ * @return never
+ */
public function run()
- public function run()
+ public function run(): never
{
throw new InvalidException();
}

View File

@ -8,7 +8,6 @@ use RectorPrefix202305\Psr\Container\ContainerInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Kernel\RectorKernel;
use Rector\Core\Util\FileHasher;
use RectorPrefix202305\Webmozart\Assert\Assert;
abstract class AbstractTestCase extends TestCase
{
/**

View File

@ -14,12 +14,11 @@ use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_;
use PHPStan\Type\NeverType;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeNestingScope\ValueObject\ControlStructure;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -27,28 +26,16 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\ReturnNeverTypeRectorTest
*/
final class ReturnNeverTypeRector extends AbstractRector
final class ReturnNeverTypeRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard
*/
private $classMethodReturnTypeOverrideGuard;
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
*/
private $phpDocTypeChanger;
/**
* @readonly
* @var \Rector\Core\Php\PhpVersionProvider
*/
private $phpVersionProvider;
public function __construct(ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, PhpDocTypeChanger $phpDocTypeChanger, PhpVersionProvider $phpVersionProvider)
public function __construct(ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard)
{
$this->classMethodReturnTypeOverrideGuard = $classMethodReturnTypeOverrideGuard;
$this->phpDocTypeChanger = $phpDocTypeChanger;
$this->phpVersionProvider = $phpVersionProvider;
}
public function getRuleDefinition() : RuleDefinition
{
@ -64,10 +51,7 @@ CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
/**
* @return never
*/
public function run()
public function run(): never
{
throw new InvalidException();
}
@ -90,19 +74,13 @@ CODE_SAMPLE
if ($this->shouldSkip($node)) {
return null;
}
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NEVER_TYPE)) {
// never-type supported natively
$node->returnType = new Identifier('never');
} else {
// static anlysis based never type
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$hasChanged = $this->phpDocTypeChanger->changeReturnType($phpDocInfo, new NeverType());
if (!$hasChanged) {
return null;
}
}
$node->returnType = new Identifier('never');
return $node;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::NEVER_TYPE;
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '7a32610a70a03adf6824fec5f055a63b6355f56b';
public const PACKAGE_VERSION = '7f49261e293df93ac9a81dd49e59ad4abed9ed41';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-15 01:20:20';
public const RELEASE_DATE = '2023-05-14 22:36:31';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderIniteaf94c22f71b40339fbb1a8a62dc1b53::getLoader();
return ComposerAutoloaderInit5cef115987814bd1a803307fa16c1d24::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderIniteaf94c22f71b40339fbb1a8a62dc1b53
class ComposerAutoloaderInit5cef115987814bd1a803307fa16c1d24
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderIniteaf94c22f71b40339fbb1a8a62dc1b53
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderIniteaf94c22f71b40339fbb1a8a62dc1b53', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit5cef115987814bd1a803307fa16c1d24', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderIniteaf94c22f71b40339fbb1a8a62dc1b53', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit5cef115987814bd1a803307fa16c1d24', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit5cef115987814bd1a803307fa16c1d24::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit5cef115987814bd1a803307fa16c1d24::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53
class ComposerStaticInit5cef115987814bd1a803307fa16c1d24
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3106,9 +3106,9 @@ class ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53::$prefixDirsPsr4;
$loader->classMap = ComposerStaticIniteaf94c22f71b40339fbb1a8a62dc1b53::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit5cef115987814bd1a803307fa16c1d24::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5cef115987814bd1a803307fa16c1d24::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5cef115987814bd1a803307fa16c1d24::$classMap;
}, null, ClassLoader::class);
}