Overriding third-party module code
I think the best method would be to use the cweagan patch manager package with composer and a local patch file.  This would allow the module to be updated normally with composer and the patch applied. If the code changes too much for the patch, it will fail and you can update the patch.

Just require cweagans/composer-patches and then modify your composer.json to include the patch.

Also, this is a good way to add patches from Drupal.org or github issues.  If your fix is something that should be generally available, sumbit an issue with the patch.  Then set up your composer patch section to use the URL to the patch in the issue.  For d.o. patches, this makes it easy to find the issue related to the patch since it issue number is in the url.