Skip to content

Commit

Permalink
Updated Rector to commit f453969311462cd11987768ae1b2843f38cadcb3
Browse files Browse the repository at this point in the history
rectorphp/rector-src@f453969 [TypeDeclaration] Using negation on BinaryOr on BinaryOpNullableToInstanceofRector (#3633)
  • Loading branch information
TomasVotruba committed Apr 20, 2023
1 parent 37ad4fb commit 9c02097
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -54,19 +55,58 @@ public function getNodeTypes() : array
* @param BooleanAnd|BooleanOr $node
*/
public function refactor(Node $node) : ?Node
{
if ($node instanceof BooleanOr) {
return $this->processNegationBooleanOr($node);
}
return $this->processsNullableInstance($node);
}
/**
* @param \PhpParser\Node\Expr\BinaryOp\BooleanAnd|\PhpParser\Node\Expr\BinaryOp\BooleanOr $node
* @return null|\PhpParser\Node\Expr\BinaryOp\BooleanAnd|\PhpParser\Node\Expr\BinaryOp\BooleanOr
*/
private function processsNullableInstance($node)
{
$nullableObjectType = $this->returnNullableObjectType($node->left);
$hasChanged = \false;
if ($nullableObjectType instanceof ObjectType) {
$node->left = $this->createExprInstanceof($node->left, $nullableObjectType);
return $node;
$hasChanged = \true;
}
$nullableObjectType = $this->returnNullableObjectType($node->right);
if ($nullableObjectType instanceof ObjectType) {
$node->right = $this->createExprInstanceof($node->right, $nullableObjectType);
$hasChanged = \true;
}
if ($hasChanged) {
return $node;
}
return null;
}
private function processNegationBooleanOr(BooleanOr $booleanOr) : ?BooleanOr
{
$hasChanged = \false;
if ($booleanOr->left instanceof BooleanNot) {
$nullableObjectType = $this->returnNullableObjectType($booleanOr->left->expr);
if ($nullableObjectType instanceof ObjectType) {
$booleanOr->left->expr = $this->createExprInstanceof($booleanOr->left->expr, $nullableObjectType);
$hasChanged = \true;
}
}
if ($booleanOr->right instanceof BooleanNot) {
$nullableObjectType = $this->returnNullableObjectType($booleanOr->right->expr);
if ($nullableObjectType instanceof ObjectType) {
$booleanOr->right->expr = $this->createExprInstanceof($booleanOr->right->expr, $nullableObjectType);
$hasChanged = \true;
}
}
if ($hasChanged) {
return $booleanOr;
}
/** @var BooleanOr|null $result */
$result = $this->processsNullableInstance($booleanOr);
return $result;
}
private function returnNullableObjectType(Expr $expr) : ?\PHPStan\Type\ObjectType
{
$exprType = $this->getType($expr);
Expand Down
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 = 'a4c1d7e481d426cb82d5a5bf89bfcac21deb3764';
public const PACKAGE_VERSION = 'f453969311462cd11987768ae1b2843f38cadcb3';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-04-19 10:59:12';
public const RELEASE_DATE = '2023-04-20 07:16:36';
/**
* @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 ComposerAutoloaderInitbafd83555148cc453afc1531baabf75a::getLoader();
return ComposerAutoloaderInit34ab03c21c233c43f1265d63a292fa57::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 ComposerAutoloaderInitbafd83555148cc453afc1531baabf75a
class ComposerAutoloaderInit34ab03c21c233c43f1265d63a292fa57
{
private static $loader;

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

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

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

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

$filesToLoad = \Composer\Autoload\ComposerStaticInitbafd83555148cc453afc1531baabf75a::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit34ab03c21c233c43f1265d63a292fa57::$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 ComposerStaticInitbafd83555148cc453afc1531baabf75a
class ComposerStaticInit34ab03c21c233c43f1265d63a292fa57
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -3144,9 +3144,9 @@ class ComposerStaticInitbafd83555148cc453afc1531baabf75a
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitbafd83555148cc453afc1531baabf75a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbafd83555148cc453afc1531baabf75a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitbafd83555148cc453afc1531baabf75a::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit34ab03c21c233c43f1265d63a292fa57::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit34ab03c21c233c43f1265d63a292fa57::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit34ab03c21c233c43f1265d63a292fa57::$classMap;

}, null, ClassLoader::class);
}
Expand Down
12 changes: 6 additions & 6 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -869,17 +869,17 @@
},
{
"name": "phpstan\/phpstan",
"version": "1.10.13",
"version_normalized": "1.10.13.0",
"version": "1.10.14",
"version_normalized": "1.10.14.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpstan.git",
"reference": "f07bf8c6980b81bf9e49d44bd0caf2e737614a70"
"reference": "d232901b09e67538e5c86a724be841bea5768a7c"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/f07bf8c6980b81bf9e49d44bd0caf2e737614a70",
"reference": "f07bf8c6980b81bf9e49d44bd0caf2e737614a70",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/d232901b09e67538e5c86a724be841bea5768a7c",
"reference": "d232901b09e67538e5c86a724be841bea5768a7c",
"shasum": ""
},
"require": {
Expand All @@ -888,7 +888,7 @@
"conflict": {
"phpstan\/phpstan-shim": "*"
},
"time": "2023-04-12T19:29:52+00:00",
"time": "2023-04-19T13:47:27+00:00",
"bin": [
"phpstan",
"phpstan.phar"
Expand Down
Loading

0 comments on commit 9c02097

Please sign in to comment.