Skip to content

Improve behavior of RemoveSoleValueSprintfRector #7689

@gisostallenberg

Description

@gisostallenberg

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.org/demo/79cecc12-043b-48ad-80e9-f831f70eec59

<?php

$myStringVar = 'test';
$myStringVarFormatted = \sprintf('%s', $myStringVar);

$myIntVar = 1;
$myIntVarFormatted = \sprintf('%s', $myIntVar);

Responsible rules

  • RemoveSoleValueSprintfRector

Expected Behavior

 <?php
 
 $myStringVar = 'test';
-$myStringVarFormatted = \sprintf('%s', $myStringVar);
+$myStringVarFormatted = $myStringVar;
 
 $myIntVar = 1;
-$myIntVarFormatted = \sprintf('%s', $myIntVar);
+$myIntVarFormatted = (string) $myIntVar;

I think RemoveSoleValueSprintfRector should also remove sole value sprintf calls when the argument is not a string, but just cast as string (which is the behavior of sprintf if the format is %s).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions