Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
// skip if has no private property
$hasAnyPrivateProperty = array_any($node->getProperties(), function (Property $property): bool {
return $property->isPrivate();
});
$hasAnyPrivateProperty = array_any($node->getProperties(), fn(Property $property): bool => $property->isPrivate());

if (! $hasAnyPrivateProperty) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Type\ObjectType;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -89,7 +92,7 @@ public function refactor(Node $node): ?Node
*/
private function processNullableInstance(BooleanAnd|BooleanOr $node): null|BooleanAnd|BooleanOr
{
$nullableObjectType = $this->nullableTypeAnalyzer->resolveNullableObjectType($node->left);
$nullableObjectType = $this->resolveNullableObjectType($node->left);

$hasChanged = false;
if ($nullableObjectType instanceof ObjectType) {
Expand All @@ -98,7 +101,7 @@ private function processNullableInstance(BooleanAnd|BooleanOr $node): null|Boole
$hasChanged = true;
}

$nullableObjectType = $this->nullableTypeAnalyzer->resolveNullableObjectType($node->right);
$nullableObjectType = $this->resolveNullableObjectType($node->right);

if ($nullableObjectType instanceof ObjectType) {
$node->right = $this->createExprInstanceof($node->right, $nullableObjectType);
Expand All @@ -117,7 +120,7 @@ private function processNegationBooleanOr(BooleanOr $booleanOr): ?BooleanOr
{
$hasChanged = false;
if ($booleanOr->left instanceof BooleanNot) {
$nullableObjectType = $this->nullableTypeAnalyzer->resolveNullableObjectType($booleanOr->left->expr);
$nullableObjectType = $this->resolveNullableObjectType($booleanOr->left->expr);

if ($nullableObjectType instanceof ObjectType) {
$booleanOr->left->expr = $this->createExprInstanceof($booleanOr->left->expr, $nullableObjectType);
Expand All @@ -126,7 +129,7 @@ private function processNegationBooleanOr(BooleanOr $booleanOr): ?BooleanOr
}

if ($booleanOr->right instanceof BooleanNot) {
$nullableObjectType = $this->nullableTypeAnalyzer->resolveNullableObjectType($booleanOr->right->expr);
$nullableObjectType = $this->resolveNullableObjectType($booleanOr->right->expr);

if ($nullableObjectType instanceof ObjectType) {
$booleanOr->right->expr = $this->createExprInstanceof($booleanOr->right->expr, $nullableObjectType);
Expand All @@ -142,6 +145,26 @@ private function processNegationBooleanOr(BooleanOr $booleanOr): ?BooleanOr
return $this->processNullableInstance($booleanOr);
}

private function resolveNullableObjectType(Expr $expr): ?ObjectType
{
// cheap bail - bool/scalar-shaped operands can never be a nullable object,
// skip the costly native type resolution for them (e.g. chained "$a && $b && $c")
if ($this->isNeverNullableObject($expr)) {
return null;
}

return $this->nullableTypeAnalyzer->resolveNullableObjectType($expr);
}

private function isNeverNullableObject(Expr $expr): bool
{
return $expr instanceof BinaryOp
|| $expr instanceof BooleanNot
|| $expr instanceof Instanceof_
|| $expr instanceof Empty_
|| $expr instanceof Isset_;
}

private function createExprInstanceof(Expr $expr, ObjectType $objectType): Instanceof_
{
$fullyQualified = new FullyQualified($objectType->getClassName());
Expand Down
1 change: 0 additions & 1 deletion src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ final class Option
/**
* @experimental Opt-in to the LPT bucket scheduler
* @see \Rector\Parallel\Experimental\LptScheduleFactory
* @var string
*/
public const string LPT = 'lpt';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function process(
): ProcessResult {
// reversed, so that array_pop() hands out the biggest files first
$jobsPerWorker = array_map(
static fn (array $jobs): array => array_reverse($jobs),
array_reverse(...),
$bucketSchedule->getJobsPerWorker()
);

Expand Down
Loading