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
@@ -0,0 +1,22 @@
<?php

namespace Rector\Tests\Issues\NullCompareInTrait\Fixture;

trait SkipBoolTypeTrait
{
/** @var array<string,class-string> */
protected array $dispatchesEvents = [];

protected function fireResourceEvent(string $event, SomeModel $model, mixed ...$args): void
{
$class = $this->dispatchesEvents[$event] ?? null;

if ($class === null) {
return;
}

some_event(new $class($model, ...$args));
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
use PhpParser\NodeVisitor;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\IntersectionType;
use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer;
use Rector\NodeAnalyzer\ExprAnalyzer;
Expand Down Expand Up @@ -118,11 +119,17 @@ public function refactor(Node $node): int|null|array|If_
return null;
}

$type = ScopeFetcher::fetch($node)->getNativeType($node->cond);
$scope = ScopeFetcher::fetch($node);
$type = $scope->getNativeType($node->cond);
if (! $type->isTrue()->yes()) {
return null;
}

$classReflection = $scope->getClassReflection();
if ($classReflection instanceof ClassReflection && $classReflection->isTrait()) {
return null;
}

if ($node->stmts === []) {
return NodeVisitor::REMOVE_NODE;
}
Expand Down