Skip to content

Commit

Permalink
[CodeQuality] Allow change empty() to [] compare of other object prop…
Browse files Browse the repository at this point in the history
…erty usage on SimplifyEmptyCheckOnEmptyArrayRector (#6147)
  • Loading branch information
samsonasik committed Jul 14, 2024
1 parent a9ddf8f commit 25b437a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
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

0 comments on commit 25b437a

Please sign in to comment.