Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeQuality] Allow change empty() to [] compare of other object property usage on SimplifyEmptyCheckOnEmptyArrayRector #6147

Merged
merged 1 commit into from
Jul 14, 2024
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
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector\Source\OtherClass;

final class PropertyFetchFromOtherObject
{
public function isEmptyArray(OtherClass $otherClass): bool
{
return empty($otherClass->prop);
}
}

?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector\Source\OtherClass;

final class PropertyFetchFromOtherObject
{
public function isEmptyArray(OtherClass $otherClass): bool
{
return $otherClass->prop === [];
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector\Source;

class OtherClass
{
public array $prop = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function isAllowedExpr(Expr $expr, Scope $scope): bool
return false;
}

$classReflection = $this->reflectionResolver->resolveClassReflection($expr);
$classReflection = $this->reflectionResolver->resolveClassReflectionSourceObject($expr);
if (! $classReflection instanceof ClassReflection) {
return false;
}
Expand Down