braintree / braintree_php

Braintree PHP library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
545 stars 224 forks source link

Updated continue statement inside a switch statement for compatibility with PHP 7.3 #238

Closed briandotdev closed 5 years ago

briandotdev commented 5 years ago

As per php-src, '"continue" statements targeting "switch" control flow structures will now generate a warning' as of PHP 7.3. Ref

PHP manual states that continue 2 will continue with the next iteration of the outer loop. Ref

This Pull Request updates the continue statement in lib/Braintree/Util.php for compatibility with PHP 7.3.

crookedneighbor commented 5 years ago

We have this done internally already and opted to just use an if/else if chain instead of a switch statement.

diff --git a/lib/Braintree/Util.php b/lib/Braintree/Util.php
index 6b921fa..437a998 100644
--- a/lib/Braintree/Util.php
+++ b/lib/Braintree/Util.php
@@ -97,33 +97,26 @@ class Util
                 throw new Exception\Unexpected("Unexpected exception:" . $message);
             }

-            switch($error["extensions"]["errorClass"]) {
-            case "VALIDATION":
+            $errorClass = $error["extensions"]["errorClass"];
+
+            if ($errorClass == "VALIDATION") {
                 continue;
-            case "AUTHENTICATION":
+            } else if ($errorClass == "AUTHENTICATION") {
                 throw new Exception\Authentication();
-                break;
-            case "AUTHORIZATION":
+            } else if ($errorClass == "AUTHORIZATION") {
                 throw new Exception\Authorization($message);
-                break;
-            case "NOT_FOUND":
+            } else if ($errorClass == "NOT_FOUND") {
                 throw new Exception\NotFound();
-                break;
-            case "UNSUPPORTED_CLIENT":
+            } else if ($errorClass == "UNSUPPORTED_CLIENT") {
                 throw new Exception\UpgradeRequired();
-                break;
-            case "RESOURCE_LIMIT":
+            } else if ($errorClass == "RESOURCE_LIMIT") {
                 throw new Exception\TooManyRequests();
-                break;
-            case "INTERNAL":
+            } else if ($errorClass == "INTERNAL") {
                 throw new Exception\ServerError();
-                break;
-            case "SERVICE_AVAILABILITY":
+            } else if ($errorClass == "SERVICE_AVAILABILITY") {
                 throw new Exception\DownForMaintenance();
-                break;
-            default:
+            } else {
                 throw new Exception\Unexpected('Unexpected exception ' . $message);
-                break;
             }
         }
     }

Going to close this now. Hoping to get the fix out this week.