Skip to content

Incorrect behavior of FlipTypeControlToUseExclusiveTypeRector #8961

@darthf1

Description

@darthf1

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/f61e55a6-164e-47b4-9047-582521ecf703

<?php

final class DemoFile
{
    public function run(?\DateTimeImmutable $param)
    {
-        if (null === ($paramValue = $param)) {
+        if (!$paramValue = $param instanceof \DateTimeImmutable) {
            return 'no';
        }

        return $paramValue;
    }
}

Responsible rules

  • FlipTypeControlToUseExclusiveTypeRector

Expected Behavior

<?php

final class DemoFile
{
    public function run(?\DateTimeImmutable $param)
    {
-        if (null === ($paramValue = $param)) {
+        if (!($paramValue = $param) instanceof \DateTimeImmutable) {
            return 'no';
        }

        return $paramValue;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions