tomzx / php-semver-checker

Compares two source sets and determines the appropriate semantic versioning to apply.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing method default parameter value should generate MAJOR level entry

ajant opened this issue · comments

Removing method default parameter value should generate MAJOR level entry. Because if you remove default value, you are changing the signature of the method, effectively breaking backwards compatibility. Before the change, you were able to call the method without providing said parameter and after the change, you have to provide it. Am I missing anything?

If I'm not mistaken, this should be taken care by V002, V010 and V011.

As you've observed, the removal of a default parameter is similar to the addition of a new parameter to the function/method signature. I believe this case is already taken care of in https://github.com/tomzx/php-semver-checker/blob/master/src/PHPSemVerChecker/Comparator/Signature.php#L22:L27.

If that is not the case, could you please provide a test case where V002/V010/V011 is not triggered?

Then I'm definitely missing something. Admittedly I did use my project's composer.json & composer update to install the package into my project, against your recommendation, but I'm not sure that is the reason behind the problem:
"tomzx/php-semver-checker": "*"
I made no custom configurations. If I understood correctly V002, V010 and V011 should all cause MAJOR entry by default?
I also got same result after making custom configuration like this:
myconfig.json
{ "level": { "mapping": { "V002": "MAJOR", "V010": "MAJOR", "V011": "MAJOR" } } }

When I remove default params to try and trigger the V010 & V011, I only get V023, V024 & V060 triggered.

You are correct, it appears there is a bug if the previous/after function are of the same length but their optional parameters have changed.

This however points out there's a couple of issues with the current verification rules, namely that we might have to create a set for the addition of new parameters with default or the conversion of a required parameter into an optional parameter (aka parameter with default value) (which is a minor change), the removal of a parameter's default value (which is a major change as you pointed out).

Supporting this change will be more involved than what I expected however, so I'll have to look into it a little more before anything can be fixed.

Thanks for reporting this issue.

No problem, glad I could help.

Do you have any timetable for this? I'm looking forward to using your library, as soon as the issue is fixed.

Sadly, the whole function/method signature comparison needs a major overhaul.

As this project is not overly active, I cannot provide you with any timetable. However, I'll try to allocate myself some time to work on this issue this month. Hopefully it can be done within the month (with a bunch of new features/fixes).

I've been able to finish most of the bulk of the work (@c896df0b71b37d58891bddfb977a15e86fe1f392), however I believe there are still issues left (which will be discovered in time).

Note that rules V072, V094-V096, V078 and V112-V114 have been assigned to this.

Give it a try and let me know if you have any issues.