Open spelgubbe opened 2 years ago
Complexity after refactoring: 9
First off is a part of the function that strips prefixes from phone numbers, such that no national calling code or similar precedes the phone number. This is done after extracting the national code in the number (if any). For example, +46073XXXX would be stripped to 073XXXX. This functionality moved to a separate private method.
Second is the part of the function where there is a check whether the number is being dialed from the same country code as the country code specified by the phone number. This is moved to a separate private function.
Finally, the function adds an international prefix to the phone number, if possible. This is moved to a separate private function.
Complexity 14.
The method formats a phone number according to many different rules and conditions. The number is formatted to be used for dialing out-of-country.
The plan is to break up the method into multiple methods which have slightly different responsibilities. There seem to be 3-4 important parts of the function which do different things.
One functionality is stripping unnecessary prefixes from the phone number. One functionality is checking whether the number is being dialed from the same country that the caller is in, and formatting the number accordingly. One functionality is checking whether an international prefix should be added to the phone number.