mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 9b46906e39ded6bbf0a48d016f7b95ae1431ec29
9b46906e39
[Strict] Add support string|null|false on BooleanInBooleanNotRuleFixerRector (#2035)
This commit is contained in:
parent
c4650c159a
commit
33ba60faee
@ -9811,8 +9811,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run(string|null $name)
|
||||
+ public function run(string $name)
|
||||
public function run(string|null $name)
|
||||
{
|
||||
- if (! $name) {
|
||||
+ if ($name === null) {
|
||||
|
@ -17,6 +17,7 @@ use PhpParser\Node\Scalar\String_;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\BooleanType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeCombinator;
|
||||
@ -51,6 +52,9 @@ final class ExactCompareFactory
|
||||
if ($exprType instanceof \PHPStan\Type\ArrayType) {
|
||||
return new \PhpParser\Node\Expr\BinaryOp\Identical($expr, new \PhpParser\Node\Expr\Array_([]));
|
||||
}
|
||||
if ($exprType instanceof \PHPStan\Type\NullType) {
|
||||
return new \PhpParser\Node\Expr\BinaryOp\Identical($expr, $this->nodeFactory->createNull());
|
||||
}
|
||||
if (!$exprType instanceof \PHPStan\Type\UnionType) {
|
||||
return null;
|
||||
}
|
||||
@ -104,7 +108,28 @@ final class ExactCompareFactory
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
$compareExprs[] = $this->createNotIdenticalFalsyCompare($unionedType, $expr, $treatAsNotEmpty);
|
||||
}
|
||||
/** @var ?Expr $truthyExpr */
|
||||
return $this->resolveTruthyExpr($compareExprs);
|
||||
}
|
||||
/**
|
||||
* @return array<Expr|null>
|
||||
*/
|
||||
private function collectCompareExprs(\PHPStan\Type\UnionType $unionType, \PhpParser\Node\Expr $expr, bool $treatAsNonEmpty) : array
|
||||
{
|
||||
$compareExprs = [];
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
$compareExprs[] = $this->createIdenticalFalsyCompare($unionedType, $expr, $treatAsNonEmpty);
|
||||
}
|
||||
return $compareExprs;
|
||||
}
|
||||
private function cleanUpPossibleNullableUnionType(\PHPStan\Type\UnionType $unionType) : \PHPStan\Type\Type
|
||||
{
|
||||
return \count($unionType->getTypes()) === 2 ? \PHPStan\Type\TypeCombinator::removeNull($unionType) : $unionType;
|
||||
}
|
||||
/**
|
||||
* @param array<Expr|null> $compareExprs
|
||||
*/
|
||||
private function resolveTruthyExpr(array $compareExprs) : ?\PhpParser\Node\Expr
|
||||
{
|
||||
$truthyExpr = \array_shift($compareExprs);
|
||||
foreach ($compareExprs as $compareExpr) {
|
||||
if (!$compareExpr instanceof \PhpParser\Node\Expr) {
|
||||
@ -113,7 +138,6 @@ final class ExactCompareFactory
|
||||
if (!$truthyExpr instanceof \PhpParser\Node\Expr) {
|
||||
return null;
|
||||
}
|
||||
/** @var Expr $compareExpr */
|
||||
$truthyExpr = new \PhpParser\Node\Expr\BinaryOp\BooleanOr($truthyExpr, $compareExpr);
|
||||
}
|
||||
return $truthyExpr;
|
||||
@ -123,19 +147,10 @@ final class ExactCompareFactory
|
||||
*/
|
||||
private function createTruthyFromUnionType(\PHPStan\Type\UnionType $unionType, \PhpParser\Node\Expr $expr, bool $treatAsNonEmpty)
|
||||
{
|
||||
$unionType = \PHPStan\Type\TypeCombinator::removeNull($unionType);
|
||||
$unionType = $this->cleanUpPossibleNullableUnionType($unionType);
|
||||
if ($unionType instanceof \PHPStan\Type\UnionType) {
|
||||
$compareExprs = [];
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
$compareExprs[] = $this->createIdenticalFalsyCompare($unionedType, $expr, $treatAsNonEmpty);
|
||||
}
|
||||
/** @var Expr $truthyExpr */
|
||||
$truthyExpr = \array_shift($compareExprs);
|
||||
foreach ($compareExprs as $compareExpr) {
|
||||
/** @var Expr $compareExpr */
|
||||
$truthyExpr = new \PhpParser\Node\Expr\BinaryOp\BooleanOr($truthyExpr, $compareExpr);
|
||||
}
|
||||
return $truthyExpr;
|
||||
$compareExprs = $this->collectCompareExprs($unionType, $expr, $treatAsNonEmpty);
|
||||
return $this->resolveTruthyExpr($compareExprs);
|
||||
}
|
||||
if ($unionType instanceof \PHPStan\Type\BooleanType) {
|
||||
return new \PhpParser\Node\Expr\BinaryOp\Identical($expr, $this->nodeFactory->createTrue());
|
||||
@ -145,14 +160,14 @@ final class ExactCompareFactory
|
||||
return new \PhpParser\Node\Expr\BooleanNot($instanceOf);
|
||||
}
|
||||
$toNullIdentical = new \PhpParser\Node\Expr\BinaryOp\Identical($expr, $this->nodeFactory->createNull());
|
||||
// assume we have to check empty string, integer and bools
|
||||
if (!$treatAsNonEmpty) {
|
||||
$scalarFalsyIdentical = $this->createIdenticalFalsyCompare($unionType, $expr, $treatAsNonEmpty);
|
||||
if (!$scalarFalsyIdentical instanceof \PhpParser\Node\Expr) {
|
||||
return null;
|
||||
}
|
||||
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr($toNullIdentical, $scalarFalsyIdentical);
|
||||
if ($treatAsNonEmpty) {
|
||||
return $toNullIdentical;
|
||||
}
|
||||
return $toNullIdentical;
|
||||
// assume we have to check empty string, integer and bools
|
||||
$scalarFalsyIdentical = $this->createIdenticalFalsyCompare($unionType, $expr, $treatAsNonEmpty);
|
||||
if (!$scalarFalsyIdentical instanceof \PhpParser\Node\Expr) {
|
||||
return null;
|
||||
}
|
||||
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr($toNullIdentical, $scalarFalsyIdentical);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run(string $name)
|
||||
public function run(string|null $name)
|
||||
{
|
||||
if ($name === null) {
|
||||
return 'no name';
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '76667332cf4daf4d9ca8f081fe6389b41673b3e5';
|
||||
public const PACKAGE_VERSION = '9b46906e39ded6bbf0a48d016f7b95ae1431ec29';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-04-10 00:25:21';
|
||||
public const RELEASE_DATE = '2022-04-10 13:01:19';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20220410\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e::getLoader();
|
||||
return ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59::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 ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e
|
||||
class ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,19 +22,19 @@ class ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire25ca62d2ccc6a51e1168a8687223530e($fileIdentifier, $file);
|
||||
composerRequire77d63ece181c04c49904b82bbc0f8c59($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
@ -46,7 +46,7 @@ class ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e
|
||||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire25ca62d2ccc6a51e1168a8687223530e($fileIdentifier, $file)
|
||||
function composerRequire77d63ece181c04c49904b82bbc0f8c59($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e
|
||||
class ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59
|
||||
{
|
||||
public static $files = array (
|
||||
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
|
||||
@ -3858,9 +3858,9 @@ class ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit25ca62d2ccc6a51e1168a8687223530e::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit77d63ece181c04c49904b82bbc0f8c59::$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('RectorPrefix20220410\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e', false) && !interface_exists('ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e', false) && !trait_exists('ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e', false)) {
|
||||
spl_autoload_call('RectorPrefix20220410\ComposerAutoloaderInit25ca62d2ccc6a51e1168a8687223530e');
|
||||
if (!class_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false) && !interface_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false) && !trait_exists('ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59', false)) {
|
||||
spl_autoload_call('RectorPrefix20220410\ComposerAutoloaderInit77d63ece181c04c49904b82bbc0f8c59');
|
||||
}
|
||||
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('RectorPrefix20220410\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20220410\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire25ca62d2ccc6a51e1168a8687223530e')) {
|
||||
function composerRequire25ca62d2ccc6a51e1168a8687223530e() {
|
||||
return \RectorPrefix20220410\composerRequire25ca62d2ccc6a51e1168a8687223530e(...func_get_args());
|
||||
if (!function_exists('composerRequire77d63ece181c04c49904b82bbc0f8c59')) {
|
||||
function composerRequire77d63ece181c04c49904b82bbc0f8c59() {
|
||||
return \RectorPrefix20220410\composerRequire77d63ece181c04c49904b82bbc0f8c59(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user