mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit edf54c85b6aadaecf064b797d340953697e0ca74
edf54c85b6
[Instanceof] Add FlipNegatedTernaryInstanceofRector (#3610)
This commit is contained in:
parent
8e0981a696
commit
ab279ddabc
@ -8,7 +8,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2|^8.0",
|
"php": "^7.2|^8.0",
|
||||||
"phpstan/phpstan": "^1.10.1"
|
"phpstan/phpstan": "^1.10.13"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -10,6 +10,7 @@ use Rector\Config\RectorConfig;
|
|||||||
use Rector\DeadCode\Rector\BinaryOp\RemoveDuplicatedInstanceOfRector;
|
use Rector\DeadCode\Rector\BinaryOp\RemoveDuplicatedInstanceOfRector;
|
||||||
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
|
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
|
||||||
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
|
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
|
||||||
|
use Rector\TypeDeclaration\Rector\Ternary\FlipNegatedTernaryInstanceofRector;
|
||||||
return static function (RectorConfig $rectorConfig) : void {
|
return static function (RectorConfig $rectorConfig) : void {
|
||||||
$rectorConfig->rules([EmptyOnNullableObjectToInstanceOfRector::class, GetClassToInstanceOfRector::class, InlineIsAInstanceOfRector::class, FlipTypeControlToUseExclusiveTypeRector::class, RemoveDuplicatedInstanceOfRector::class, RemoveDeadInstanceOfRector::class]);
|
$rectorConfig->rules([EmptyOnNullableObjectToInstanceOfRector::class, GetClassToInstanceOfRector::class, InlineIsAInstanceOfRector::class, FlipTypeControlToUseExclusiveTypeRector::class, RemoveDuplicatedInstanceOfRector::class, RemoveDeadInstanceOfRector::class, FlipNegatedTernaryInstanceofRector::class]);
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# 414 Rules Overview
|
# 415 Rules Overview
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
@ -67,10 +67,7 @@ CODE_SAMPLE
|
|||||||
*/
|
*/
|
||||||
public function refactor(Node $node) : ?Node
|
public function refactor(Node $node) : ?Node
|
||||||
{
|
{
|
||||||
$stmts = $node->stmts;
|
$stmts = (array) $node->stmts;
|
||||||
if ($stmts === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (\count($stmts) < 3) {
|
if (\count($stmts) < 3) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare (strict_types=1);
|
||||||
|
namespace Rector\TypeDeclaration\Rector\Ternary;
|
||||||
|
|
||||||
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Expr;
|
||||||
|
use PhpParser\Node\Expr\BooleanNot;
|
||||||
|
use PhpParser\Node\Expr\Instanceof_;
|
||||||
|
use PhpParser\Node\Expr\Ternary;
|
||||||
|
use Rector\Core\Rector\AbstractRector;
|
||||||
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||||
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||||
|
/**
|
||||||
|
* @see \Rector\Tests\TypeDeclaration\Rector\Ternary\FlipNegatedTernaryInstanceofRector\FlipNegatedTernaryInstanceofRectorTest
|
||||||
|
*/
|
||||||
|
final class FlipNegatedTernaryInstanceofRector extends AbstractRector
|
||||||
|
{
|
||||||
|
public function getRuleDefinition() : RuleDefinition
|
||||||
|
{
|
||||||
|
return new RuleDefinition('Flip negated ternary of instanceof to direct use of object', [new CodeSample('echo ! $object instanceof Product ? null : $object->getPrice();', 'echo $object instanceof Product ? $object->getPrice() : null;')]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return array<class-string<Node>>
|
||||||
|
*/
|
||||||
|
public function getNodeTypes() : array
|
||||||
|
{
|
||||||
|
return [Ternary::class];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param Ternary $node
|
||||||
|
*/
|
||||||
|
public function refactor(Node $node) : ?Node
|
||||||
|
{
|
||||||
|
if (!$node->if instanceof Expr) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!$node->cond instanceof BooleanNot) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$booleanNot = $node->cond;
|
||||||
|
if (!$booleanNot->expr instanceof Instanceof_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$node->cond = $booleanNot->expr;
|
||||||
|
// flip if and else
|
||||||
|
[$node->if, $node->else] = [$node->else, $node->if];
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = 'bc0a0d77f49995f9bba85e0aa244123cd66f5fae';
|
public const PACKAGE_VERSION = 'edf54c85b6aadaecf064b797d340953697e0ca74';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-04-13 09:57:39';
|
public const RELEASE_DATE = '2023-04-13 10:36:28';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @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';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInit5ff64d492681897def51109d95dd4f69::getLoader();
|
return ComposerAutoloaderInit2c290fdea3530f26f3ca0e8e30ce20e1::getLoader();
|
||||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -2837,6 +2837,7 @@ return array(
|
|||||||
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictSetUpRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictSetUpRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Property\\VarAnnotationIncorrectNullableRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/VarAnnotationIncorrectNullableRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Property\\VarAnnotationIncorrectNullableRector' => $baseDir . '/rules/TypeDeclaration/Rector/Property/VarAnnotationIncorrectNullableRector.php',
|
||||||
|
'Rector\\TypeDeclaration\\Rector\\Ternary\\FlipNegatedTernaryInstanceofRector' => $baseDir . '/rules/TypeDeclaration/Rector/Ternary/FlipNegatedTernaryInstanceofRector.php',
|
||||||
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictBoolExprAnalyzer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictBoolExprAnalyzer.php',
|
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictBoolExprAnalyzer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictBoolExprAnalyzer.php',
|
||||||
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictScalarExprAnalyzer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php',
|
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictScalarExprAnalyzer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php',
|
||||||
'Rector\\TypeDeclaration\\TypeAnalyzer\\GenericClassStringTypeNormalizer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/GenericClassStringTypeNormalizer.php',
|
'Rector\\TypeDeclaration\\TypeAnalyzer\\GenericClassStringTypeNormalizer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/GenericClassStringTypeNormalizer.php',
|
||||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// autoload_real.php @generated by Composer
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInit5ff64d492681897def51109d95dd4f69
|
class ComposerAutoloaderInit2c290fdea3530f26f3ca0e8e30ce20e1
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5ff64d492681897def51109d95dd4f69
|
|||||||
return self::$loader;
|
return self::$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInit5ff64d492681897def51109d95dd4f69', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInit2c290fdea3530f26f3ca0e8e30ce20e1', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInit5ff64d492681897def51109d95dd4f69', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInit2c290fdea3530f26f3ca0e8e30ce20e1', 'loadClassLoader'));
|
||||||
|
|
||||||
require __DIR__ . '/autoload_static.php';
|
require __DIR__ . '/autoload_static.php';
|
||||||
call_user_func(\Composer\Autoload\ComposerStaticInit5ff64d492681897def51109d95dd4f69::getInitializer($loader));
|
call_user_func(\Composer\Autoload\ComposerStaticInit2c290fdea3530f26f3ca0e8e30ce20e1::getInitializer($loader));
|
||||||
|
|
||||||
$loader->setClassMapAuthoritative(true);
|
$loader->setClassMapAuthoritative(true);
|
||||||
$loader->register(true);
|
$loader->register(true);
|
||||||
|
|
||||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5ff64d492681897def51109d95dd4f69::$files;
|
$filesToLoad = \Composer\Autoload\ComposerStaticInit2c290fdea3530f26f3ca0e8e30ce20e1::$files;
|
||||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
$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;
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
class ComposerStaticInit5ff64d492681897def51109d95dd4f69
|
class ComposerStaticInit2c290fdea3530f26f3ca0e8e30ce20e1
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||||
@ -3084,6 +3084,7 @@ class ComposerStaticInit5ff64d492681897def51109d95dd4f69
|
|||||||
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictSetUpRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictSetUpRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php',
|
||||||
'Rector\\TypeDeclaration\\Rector\\Property\\VarAnnotationIncorrectNullableRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/VarAnnotationIncorrectNullableRector.php',
|
'Rector\\TypeDeclaration\\Rector\\Property\\VarAnnotationIncorrectNullableRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Property/VarAnnotationIncorrectNullableRector.php',
|
||||||
|
'Rector\\TypeDeclaration\\Rector\\Ternary\\FlipNegatedTernaryInstanceofRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Ternary/FlipNegatedTernaryInstanceofRector.php',
|
||||||
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictBoolExprAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictBoolExprAnalyzer.php',
|
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictBoolExprAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictBoolExprAnalyzer.php',
|
||||||
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictScalarExprAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php',
|
'Rector\\TypeDeclaration\\TypeAnalyzer\\AlwaysStrictScalarExprAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/AlwaysStrictScalarExprAnalyzer.php',
|
||||||
'Rector\\TypeDeclaration\\TypeAnalyzer\\GenericClassStringTypeNormalizer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/GenericClassStringTypeNormalizer.php',
|
'Rector\\TypeDeclaration\\TypeAnalyzer\\GenericClassStringTypeNormalizer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/GenericClassStringTypeNormalizer.php',
|
||||||
@ -3138,9 +3139,9 @@ class ComposerStaticInit5ff64d492681897def51109d95dd4f69
|
|||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
{
|
{
|
||||||
return \Closure::bind(function () use ($loader) {
|
return \Closure::bind(function () use ($loader) {
|
||||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5ff64d492681897def51109d95dd4f69::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInit2c290fdea3530f26f3ca0e8e30ce20e1::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInit5ff64d492681897def51109d95dd4f69::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInit2c290fdea3530f26f3ca0e8e30ce20e1::$prefixDirsPsr4;
|
||||||
$loader->classMap = ComposerStaticInit5ff64d492681897def51109d95dd4f69::$classMap;
|
$loader->classMap = ComposerStaticInit2c290fdea3530f26f3ca0e8e30ce20e1::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user