Updated Rector to commit 385a9cb5f1235808c7226c2efccdc10fc6de6542

385a9cb5f1 [Php74] Skip parenthesize ternary if on ParenthesizeNestedTernaryRector (#3980)
This commit is contained in:
Tomas Votruba 2023-05-26 23:56:10 +00:00
parent d3dfbb4638
commit 3267b9499d
11 changed files with 44 additions and 32 deletions

View File

@ -54,7 +54,10 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
if ($node->cond instanceof Ternary || $node->if instanceof Ternary || $node->else instanceof Ternary) {
if ($node->if instanceof Ternary && !$this->parenthesizedNestedTernaryAnalyzer->isParenthesized($this->file, $node) && $this->parenthesizedNestedTernaryAnalyzer->isParenthesized($this->file, $node->if)) {
return null;
}
if ($node->cond instanceof Ternary || $node->else instanceof Ternary) {
if ($this->parenthesizedNestedTernaryAnalyzer->isParenthesized($this->file, $node)) {
return null;
}

View File

@ -14,6 +14,11 @@ final class ParenthesizedNestedTernaryAnalyzer
$endTokenPos = $ternary->getEndTokenPos();
$hasOpenParentheses = isset($oldTokens[$startTokenPos]) && $oldTokens[$startTokenPos] === '(';
$hasCloseParentheses = isset($oldTokens[$endTokenPos]) && $oldTokens[$endTokenPos] === ')';
if ($hasOpenParentheses || $hasCloseParentheses) {
return \true;
}
$hasOpenParentheses = isset($oldTokens[$startTokenPos - 1]) && $oldTokens[$startTokenPos - 1] === '(';
$hasCloseParentheses = isset($oldTokens[$endTokenPos + 1]) && $oldTokens[$endTokenPos + 1] === ')';
return $hasOpenParentheses || $hasCloseParentheses;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '2f84187dc1d6db09788adf8346339d6854902db5';
public const PACKAGE_VERSION = '385a9cb5f1235808c7226c2efccdc10fc6de6542';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-26 23:23:51';
public const RELEASE_DATE = '2023-05-27 06:51:20';
/**
* @var int
*/

View File

@ -15,7 +15,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v33';
private const CACHE_KEY = 'v34';
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit9bfab5c1618d3a21d5425da8b46f0591
class ComposerAutoloaderInitf3ff8bd5431753ff80a266535761ae96
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit9bfab5c1618d3a21d5425da8b46f0591
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit9bfab5c1618d3a21d5425da8b46f0591', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitf3ff8bd5431753ff80a266535761ae96', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit9bfab5c1618d3a21d5425da8b46f0591', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitf3ff8bd5431753ff80a266535761ae96', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitf3ff8bd5431753ff80a266535761ae96::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitf3ff8bd5431753ff80a266535761ae96::$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 ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591
class ComposerStaticInitf3ff8bd5431753ff80a266535761ae96
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3089,9 +3089,9 @@ class ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9bfab5c1618d3a21d5425da8b46f0591::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitf3ff8bd5431753ff80a266535761ae96::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf3ff8bd5431753ff80a266535761ae96::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf3ff8bd5431753ff80a266535761ae96::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1992,12 +1992,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "9f00a628290d0a89a87003e33148ae61081b5f92"
"reference": "fdbe413a1e3e12aafd0b87c4fd09e6bb043dacd8"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/9f00a628290d0a89a87003e33148ae61081b5f92",
"reference": "9f00a628290d0a89a87003e33148ae61081b5f92",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/fdbe413a1e3e12aafd0b87c4fd09e6bb043dacd8",
"reference": "fdbe413a1e3e12aafd0b87c4fd09e6bb043dacd8",
"shasum": ""
},
"require": {
@ -2026,7 +2026,7 @@
"tomasvotruba\/type-coverage": "^0.1",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-05-26T15:58:35+00:00",
"time": "2023-05-26T22:36:03+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 259706a'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 79bc835'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9f00a62'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3fa995c'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 259706a'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 79bc835'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main fdbe413'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3fa995c'));
private function __construct()
{
}

View File

@ -6,19 +6,19 @@ namespace Rector\PHPUnit\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
final class TestsNodeAnalyzer
{
/**
* @var ObjectType[]
* @var string[]
*/
private $testCaseObjectTypes = [];
private const TEST_CASE_OBJECT_CLASSES = ['PHPUnit\\Framework\\TestCase', 'PHPUnit_Framework_TestCase'];
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
@ -36,24 +36,28 @@ final class TestsNodeAnalyzer
private $phpDocInfoFactory;
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $betterNodeFinder;
public function __construct(NodeTypeResolver $nodeTypeResolver, NodeNameResolver $nodeNameResolver, PhpDocInfoFactory $phpDocInfoFactory, BetterNodeFinder $betterNodeFinder)
private $reflectionResolver;
public function __construct(NodeTypeResolver $nodeTypeResolver, NodeNameResolver $nodeNameResolver, PhpDocInfoFactory $phpDocInfoFactory, ReflectionResolver $reflectionResolver)
{
$this->nodeTypeResolver = $nodeTypeResolver;
$this->nodeNameResolver = $nodeNameResolver;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->betterNodeFinder = $betterNodeFinder;
$this->testCaseObjectTypes = [new ObjectType('PHPUnit\\Framework\\TestCase'), new ObjectType('PHPUnit_Framework_TestCase')];
$this->reflectionResolver = $reflectionResolver;
}
public function isInTestClass(Node $node) : bool
{
$classLike = $node instanceof ClassLike ? $node : $this->betterNodeFinder->findParentType($node, ClassLike::class);
if (!$classLike instanceof ClassLike) {
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
if (!$classReflection instanceof ClassReflection) {
return \false;
}
return $this->nodeTypeResolver->isObjectTypes($classLike, $this->testCaseObjectTypes);
foreach (self::TEST_CASE_OBJECT_CLASSES as $testCaseObjectClass) {
if ($classReflection->isSubclassOf($testCaseObjectClass)) {
return \true;
}
}
return \false;
}
public function isTestClassMethod(ClassMethod $classMethod) : bool
{