Updated Rector to commit a27370519f4e17bf73f0d548e098de448895401d

a27370519f [CodeQuality] Handle negated isset on IssetOnPropertyObjectToPropertyExistsRector on property not exists (#5206)
This commit is contained in:
Tomas Votruba 2023-10-27 12:14:09 +00:00
parent 102128ffca
commit f5adafb1c4
3 changed files with 14 additions and 5 deletions

View File

@ -7,6 +7,7 @@ use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
@ -121,7 +122,7 @@ CODE_SAMPLE
continue;
}
if (!$classReflection->hasProperty($propertyFetchName) || $classReflection->isBuiltin()) {
$newNodes[] = $this->replaceToPropertyExistsWithNullCheck($issetExpr->var, $propertyFetchName, $issetExpr);
$newNodes[] = $this->replaceToPropertyExistsWithNullCheck($issetExpr->var, $propertyFetchName, $issetExpr, $isNegated);
} elseif ($isNegated) {
$newNodes[] = $this->createIdenticalToNull($issetExpr);
} else {
@ -130,10 +131,17 @@ CODE_SAMPLE
}
return $this->nodeFactory->createReturnBooleanAnd($newNodes);
}
private function replaceToPropertyExistsWithNullCheck(Expr $expr, string $property, PropertyFetch $propertyFetch) : BooleanAnd
/**
* @return \PhpParser\Node\Expr\BinaryOp\BooleanAnd|\PhpParser\Node\Expr\BinaryOp\BooleanOr
*/
private function replaceToPropertyExistsWithNullCheck(Expr $expr, string $property, PropertyFetch $propertyFetch, bool $isNegated)
{
$args = [new Arg($expr), new Arg(new String_($property))];
$propertyExistsFuncCall = $this->nodeFactory->createFuncCall('property_exists', $args);
if ($isNegated) {
$booleanNot = new BooleanNot($propertyExistsFuncCall);
return new BooleanOr($booleanNot, $this->createIdenticalToNull($propertyFetch));
}
return new BooleanAnd($propertyExistsFuncCall, $this->createNotIdenticalToNull($propertyFetch));
}
private function createNotIdenticalToNull(PropertyFetch $propertyFetch) : NotIdentical

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '89b3e62f82ad480b57f002096cc16af16d7ac597';
public const PACKAGE_VERSION = 'a27370519f4e17bf73f0d548e098de448895401d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-10-27 01:41:41';
public const RELEASE_DATE = '2023-10-27 19:10:40';
/**
* @var int
*/

View File

@ -15,6 +15,7 @@ use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
@ -305,7 +306,7 @@ final class NodeFactory
return $this->builderFactory->classConstFetch($className, $constantName);
}
/**
* @param array<NotIdentical|BooleanAnd|Identical> $newNodes
* @param array<NotIdentical|BooleanAnd|BooleanOr|Identical> $newNodes
*/
public function createReturnBooleanAnd(array $newNodes) : ?Expr
{