rector icon indicating copy to clipboard operation
rector copied to clipboard

Double cast of NullToStrictStringFuncCallArgRector

Open jorgsowa opened this issue 2 months ago • 2 comments

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/c96ef6c0-7fad-444f-9fb8-5941280101fd

<?php

explode(',',
(string) $getInstance->get()
	? $_SERVER['REMOTE_ADDR']
	: $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '',
);

Responsible rules

  • NullToStrictStringFuncCallArgRector

Expected Behavior

No change. Double cast shouldn't be added.

jorgsowa avatar Dec 09 '25 11:12 jorgsowa

I'm looking into it.

Btw, the (string) only affects the (string) $getInstance->get(), not the rest of ternary. So IMO can be removed as rest of ternary are always strings.

TomasVotruba avatar Dec 09 '25 14:12 TomasVotruba

Btw, the (string) only affects the (string) $getInstance->get(), not the rest of ternary. So IMO can be removed as rest of ternary are always strings.

I'm aware of it. As addition whole ternary statement was surrounded by parenthesis that were removed. I have another example that would be good to add as a test case: https://getrector.com/demo/4d9920dd-7a76-404d-af4b-9b41a0952c0a

jorgsowa avatar Dec 10 '25 10:12 jorgsowa