Skip to content

Commit

Permalink
Updated Rector to commit 64a96e39ebbb3b3c00cb2c1f23addc4017388845
Browse files Browse the repository at this point in the history
rectorphp/rector-src@64a96e3 [CodingStyle] Skip case not constant value on BinarySwitchToIfElseRector (#3452)
  • Loading branch information
TomasVotruba committed Mar 4, 2023
1 parent 2ddddb4 commit 4077cee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
17 changes: 15 additions & 2 deletions rules/CodingStyle/Rector/Switch_/BinarySwitchToIfElseRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
namespace Rector\CodingStyle\Rector\Switch_;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\BinaryOp\Equal;
use PhpParser\Node\Stmt\Case_;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Switch_;
use PHPStan\Type\NullType;
use Rector\Core\Rector\AbstractRector;
use Rector\Renaming\NodeManipulator\SwitchManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -65,12 +67,17 @@ public function refactor(Node $node) : ?Node
if (\count($node->cases) > 2) {
return null;
}
// avoid removal of cases if it goes to be skipped next
$cases = $node->cases;
/** @var Case_ $firstCase */
$firstCase = \array_shift($node->cases);
$firstCase = \array_shift($cases);
if ($firstCase->cond === null) {
return null;
}
$secondCase = \array_shift($node->cases);
if ($this->shouldSkipTypeWithValue($firstCase->cond)) {
return null;
}
$secondCase = \array_shift($cases);
// special case with empty first case → ||
$isFirstCaseEmpty = $firstCase->stmts === [];
if ($isFirstCaseEmpty && $secondCase !== null && $secondCase->cond !== null) {
Expand All @@ -95,4 +102,10 @@ public function refactor(Node $node) : ?Node
}
return $ifNode;
}
private function shouldSkipTypeWithValue(Expr $expr) : bool
{
$type = $this->nodeTypeResolver->getType($expr);
$value = $this->valueResolver->getValue($expr);
return !$type instanceof NullType && $value === null;
}
}
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'c2a6d2217395ef9f6ba9a46188a62b97f2c4b250';
public const PACKAGE_VERSION = '64a96e39ebbb3b3c00cb2c1f23addc4017388845';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-03-04 08:48:03';
public const RELEASE_DATE = '2023-03-04 08:49:01';
/**
* @var int
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitc1ee7cf6f29558c44e4e0805d658018b::getLoader();
return ComposerAutoloaderInitc108bbe265a02cb6dbc04a27ef636d6a::getLoader();
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitc1ee7cf6f29558c44e4e0805d658018b
class ComposerAutoloaderInitc108bbe265a02cb6dbc04a27ef636d6a
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInitc1ee7cf6f29558c44e4e0805d658018b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitc108bbe265a02cb6dbc04a27ef636d6a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitc1ee7cf6f29558c44e4e0805d658018b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitc108bbe265a02cb6dbc04a27ef636d6a', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitc108bbe265a02cb6dbc04a27ef636d6a::getInitializer($loader));

$loader->setClassMapAuthoritative(true);
$loader->register(true);

$filesToLoad = \Composer\Autoload\ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitc108bbe265a02cb6dbc04a27ef636d6a::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b
class ComposerStaticInitc108bbe265a02cb6dbc04a27ef636d6a
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -3134,9 +3134,9 @@ class ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc1ee7cf6f29558c44e4e0805d658018b::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitc108bbe265a02cb6dbc04a27ef636d6a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc108bbe265a02cb6dbc04a27ef636d6a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc108bbe265a02cb6dbc04a27ef636d6a::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit 4077cee

Please sign in to comment.