"Create parameter" intention fails and gives an error message "Cannot apply quick fix. Selected function/method has usages"

When I have for example this code:

 

<?php

echo myfunction();

function myfunction ()

{

    return 'ABC' . $parameter;

}

?>

 

If I place the cursor on the $parameter variable and open the intention menu by hitting Alt + Enter and select "Create parameter", PhpStorm refuses to create the parameter because the function is already called in the source code. While I understand that it's not good to break existing code by adding more parameters, I think this behavior could be improved.

Ideas:

1. Ask if the users really want to add a parameter when the function has usages.

2. Offer to make the new parameter optional by defining a default value.

For me it would be just perfect if I could just ignore the error message and force PhpStorm to add the new parameter even if the function had usages. I can then go to fix the function calls manually.

Thank you for your support!

3 comments

Hi,

thanks for your help, but it's not actually what I'm looking for. Let's look at the example code again:

<?php

echo myfunction();

function myfunction ()

{

return 'ABC' . $parameter;

}

?>

If I have the cursor at $parameter and I hit Alt+Enter and select 'Create parameter', it's far more intuitive than moving the cursor to the function name and then pressing Ctrl + F6 which opens the Change signature window. In the Change signature window I would still need to manually type the new parameter name. So in this particular case I would actually just end up writing the new parameter name directly to the parentheses after the function name as it's even quicker than using the Change signature window.

So the question still remains, can the "Create parameter" intention be changed to allow creating new parameters even when the function/method has usages?

0

Here's a feature request for this: https://youtrack.jetbrains.com/issue/WI-20601. Feel free to vote/comment to increase its priority.

0

Please sign in to leave a comment.