Getting rid of Ambiguous class resolution warnings when working with the PayPal API

When using the paypal/merchant-sdk-php composer package and running composer install or composer update you're getting a lot of warning messages like the following:

...
Writing lock file
Generating autoload files
Warning: Ambiguous class resolution, "SetDataRequestType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/SetDataRequestType.php", the first will be used.
Warning: Ambiguous class resolution, "MerchantPullPaymentType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/MerchantPullPaymentType.php", the first will be used.
Warning: Ambiguous class resolution, "InitiateRecoupReq" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/InitiateRecoupReq.php", the first will be used.
Warning: Ambiguous class resolution, "CreateBillingAgreementResponseType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/CreateBillingAgreementResponseType.php", the first will be used.
Warning: Ambiguous class resolution, "MeasureType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/MeasureType.php", the first will be used.
Warning: Ambiguous class resolution, "BusinessInfoType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/BusinessInfoType.php", the first will be used.
Warning: Ambiguous class resolution, "ButtonSearchResultType" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/ButtonSearchResultType.php", the first will be used.
Warning: Ambiguous class resolution, "SetAuthFlowParamReq" was found in both "/project/vendor/paypal/merchant-sdk-php/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php" and "/project/vendor/paypal/merchant-sdk-php/lib/PayPalAPIInterfaceService/SetAuthFlowParamReq.php", the first will be used.
...
# Many more lines

There already is a bug ticket on Github for this issue but it doesn't seems to be worked on with a high priority (as it was opened on 31 Jul 2014).

After searching for a while, I found the source of the problem, which is / are called PPAutoloader and PayPalAPIInterfaceService. Every single class of the API is copied into the PayPalAPIInterfaceService. It is used for the examples (which are part of the package) and loaded with the PPAutoloader if no vendor/autoload.php is available. But this internal logic (which autoloader has to be called) is not relevant for the "composer autoloader generation process" which runs through all folders and builds it's own configuration.

So what's the solution?

There is no way to exclude folders (which are within the vendor folder) from the autoloader generation process. Of course you could run composer with the --no-autoloader flag. But then you would need to handle the autoloading yourself which is a little bit drastic for an issue which "only" produces warnings.

In this case there is an easier way. As this class is only relevant for the examples (which aren't used in the system), I can simply delete the file.

For that I use the scripts part of the composer.json and the pre-autoload-dump command event (which is triggered right before the autoloader generation process). The command deletes the services folder which contains the PayPalAPIInterfaceService.

"scripts": {
    "pre-autoload-dump": [
        "rm -rf vendor/paypal/merchant-sdk-php/lib/services"
    ]
},