Skip to content

Commit

Permalink
[Strict] Skip from docblock @return on DisallowedEmptyRuleFixerRector (
Browse files Browse the repository at this point in the history
…#4608)

* [Strict] Skip from docblock @return on DisallowedEmptyRuleFixerRector

* [ci-review] Rector Rectify

* Fixed 🎉

* fix

* remove ArrayDimFetch feature

* [ci-review] Rector Rectify

* Revert "[ci-review] Rector Rectify"

This reverts commit cf4f602.

* Revert "remove ArrayDimFetch feature"

This reverts commit d4a8040.

* negated test

* from return

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Jul 26, 2023
1 parent c01925a commit 65e6cae
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\Fixture;

final class FromReturnCall
{
public function run()
{
return empty($this->getProperty());
}

public function run2()
{
return ! empty($this->getProperty());
}

public function getProperty(): string
{
return '';
}
}

?>
-----
<?php

namespace Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\Fixture;

final class FromReturnCall
{
public function run()
{
return $this->getProperty() === '';
}

public function run2()
{
return $this->getProperty() !== '';
}

public function getProperty(): string
{
return '';
}
}

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

namespace Rector\Tests\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector\Fixture;

final class SkipFromDocblockReturn
{
public function run()
{
return empty($this->getProperty());
}

public function run2()
{
return ! empty($this->getProperty());
}

/**
* @return string
*/
public function getProperty()
{
}
}
4 changes: 2 additions & 2 deletions rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function refactorBooleanNot(BooleanNot $booleanNot, Scope $scope): Expr|
return null;
}

$emptyExprType = $scope->getType($empty->expr);
$emptyExprType = $scope->getNativeType($empty->expr);

return $this->exactCompareFactory->createNotIdenticalFalsyCompare(
$emptyExprType,
Expand All @@ -119,7 +119,7 @@ private function refactorEmpty(Empty_ $empty, Scope $scope, bool $treatAsNonEmpt
return null;
}

$exprType = $scope->getType($empty->expr);
$exprType = $scope->getNativeType($empty->expr);
return $this->exactCompareFactory->createIdenticalFalsyCompare($exprType, $empty->expr, $treatAsNonEmpty);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
$ternary = $return->expr;

$returnScope = $return->expr->getAttribute(AttributeKey::SCOPE);
if ($returnScope === null) {
if (!$returnScope instanceof Scope) {
return null;
}

Expand Down

0 comments on commit 65e6cae

Please sign in to comment.