Skip to content

Commit

Permalink
Skip no-isset/no-empty check on possibly undefined variable (rectorph…
Browse files Browse the repository at this point in the history
…p#32)

* Skip no-isset/no-empty check on possibly undefined variable

* fix
  • Loading branch information
staabm authored Jul 8, 2024
1 parent 019d395 commit 7a96f32
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Guard/EmptyIssetGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function isLegal(Expr $expr, Scope $scope): bool
return true;
}

$varType = $scope->getType($expr);
$varType = $scope->getNativeType($expr);
$varType = TypeCombinator::removeNull($varType);
return $varType->getObjectClassNames() === [];
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Rules/NoEmptyOnObjectRule/Fixture/SkipPhpDocType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\TypePerfect\Tests\Rules\NoEmptyOnObjectRule\Fixture;

/** @var SkipPhpDocType|null $x */
if (!empty($x)) {
return $x;
}

class SkipPhpDocType {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/SkipEmptyOnArray.php', []];
yield [__DIR__ . '/Fixture/SkipEmptyOnArrayNestedOnObject.php', []];
yield [__DIR__ . '/Fixture/SkipPossibleUndefinedVariable.php', []];
yield [__DIR__ . '/Fixture/SkipPhpDocType.php', []];
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/Rules/NoIssetOnObjectRule/Fixture/SkipPhpDocType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\TypePerfect\Tests\Rules\NoIssetOnObjectRule\Fixture;

/** @var SkipPhpDocType|null $x */
if (isset($x)) {
return $x;
}

class SkipPhpDocType {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/SkipIssetOnArrayNestedOnObject.php', []];
yield [__DIR__ . '/Fixture/SkipPossibleUndefinedVariable.php', []];
yield [__DIR__ . '/Fixture/SkipIssetOnPropertyFetch.php', []];
yield [__DIR__ . '/Fixture/SkipPhpDocType.php', []];
}

/**
Expand Down

0 comments on commit 7a96f32

Please sign in to comment.