Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChangeSwitchToMatchRector should cast subject expression #8846

Closed
namex42 opened this issue Oct 2, 2024 · 0 comments · Fixed by rectorphp/rector-src#6359
Closed

ChangeSwitchToMatchRector should cast subject expression #8846

namex42 opened this issue Oct 2, 2024 · 0 comments · Fixed by rectorphp/rector-src#6359
Labels

Comments

@namex42
Copy link

namex42 commented Oct 2, 2024

Bug Report

Subject Details
Rector version v1.2.2

The switch uses loose comparsions (==) but the match uses Identical comparisons (===)

<?php

function test(string $code): int
{
    switch($code) {
        case 777:
            return 1;
        case 88:
            return 2;
        default:
            return 4;
    };
}

https://getrector.com/demo/4f488776-3a2b-4df6-bf87-088fdc73a5e6
https://3v4l.org/6Vpuf#v8.3.12 - error

Expected Behaviour

Leave as is or try cast?

<?php

function test(string $code): int
{
    return match ((int) $code) {
        777 => 1,
        88 => 2,
        default => 4,
    };
}

https://3v4l.org/6ikFd#v8.3.12 - with cast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant