-
-
Notifications
You must be signed in to change notification settings - Fork 738
Open
rectorphp/rector-src
#7803Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | 2.3.0 |
Description
RemoveExtraParametersRector incorrectly removed required parameters from calls to a function that is defined in the same file. This caused a cascade of incorrect transformations:
RemoveExtraParametersRectorremoved the$messageargument fromformatErrorMessage()calls- After removal, all catch blocks appeared to have identical bodies
MultiExceptionCatchRectormerged them into a single multi-catchRemoveUnusedVariableInCatchRectorremoved the$evariable
The resulting code is broken and will throw TypeError at runtime.
Source Code
This occurred in the OpenEMR project:
- Catch blocks (lines 224-240): https://github.com/openemr/openemr/blob/master/interface/modules/custom_modules/oe-module-faxsms/library/rc_sms_notification.php#L224-L240
- Function definition (line 362): https://github.com/openemr/openemr/blob/master/interface/modules/custom_modules/oe-module-faxsms/library/rc_sms_notification.php#L362-L365
Diff Produced by Rector
- } catch (InvalidEmailAddressException) {
- $strMsg .= formatErrorMessage(xlt("Invalid email address"));
- echo(nl2br($strMsg));
- continue;
- } catch (SmtpNotConfiguredException) {
- $strMsg .= formatErrorMessage(xlt("SMTP not configured"));
- echo(nl2br($strMsg));
- continue;
- } catch (EmailSendFailedException $e) {
- $strMsg .= formatErrorMessage(xlt("Failed to send email") . ": " . text($e->getMessage()));
- echo(nl2br($strMsg));
- continue;
- } catch (\PHPMailer\PHPMailer\Exception $e) {
- $strMsg .= formatErrorMessage(xlt("Email error") . ": " . text($e->getMessage()));
+ } catch (InvalidEmailAddressException|SmtpNotConfiguredException|EmailSendFailedException|\PHPMailer\PHPMailer\Exception) {
+ $strMsg .= formatErrorMessage();
echo(nl2br($strMsg));
continue;
}Applied Rules
Applied rules:
* RemoveExtraParametersRector
* MultiExceptionCatchRector
* RemoveUnusedVariableInCatchRector
Why This Is Wrong
formatErrorMessage(string $message)is defined in the same file and clearly requires a parameter - see line 362- Each catch block had a different error message - they should not have been merged
- The resulting
formatErrorMessage()call with no arguments will throwTypeError
Reproducibility
This bug appears to be intermittent. After clearing the cache (rm -rf /tmp/rector) and re-running Rector, the issue did not reproduce. However:
- I have observed this bug multiple times on this codebase
- The git diff shown above is proof it occurred
This matches the behavior reported in #9088.
Related Issues
- Wrong refactor by RemoveExtraParametersRector rule #9088 - Similar issue with
RemoveExtraParametersRectorincorrectly removing parameters, also reported as intermittent/"blinking"
Environment
- Rector 2.3.0
- PHP 8.2
- macOS (Darwin)
- Using
->withDeadCodeLevel(5)and->withPhpSets()in rector.php - Parallel processing enabled (default settings)
Metadata
Metadata
Assignees
Labels
No labels