vaimo / composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and composer command for testing/troubleshooting patches.
MIT License
287 stars 40 forks source link

Add patch markers to patched code #69

Open allanpaiste opened 3 years ago

allanpaiste commented 3 years ago

Is your feature request related to a problem? Please describe.

In case one is working on a large-scale project or works in an agency where the patching of project is handled by a specific core team - there might be cases where someone in a project team ends up relying on a piece of code/logic that has been introduced by a patch. Because the production code does not have any indicators that some rows were patched in (unless patch author has taken care of this), it takes extra effort to check this.

Describe the solution you'd like

Introduce mechanism that would automatically add comments near the patched in code. Might be reference to the file and package that owns the patch.

This would be somewhat tricky to achieve as the comments have to be removed in case there are multiple patches targeting the same part of the code (or that layer on top of each other -- something that is not out-of-this-world scenario when the patches are managed in relatively granular manner).

Describe alternatives you've considered

Enforcing comments in patches would be another way to achieve this (where the patch applier would just error out when patch does not introduce such contextual comments). Not very convenient though.

One could also consider erroring out when patch removes part of code without adding anything - which might be confusing as well (in this case the validator could require a one-liner replacement)

Additional context

This could be considered somewhat edge-case'y and might not be something that the main plugin needs, but have experienced situations where production code becomes very much unintentionally dependent on the patched-in code.