DD2480-G12 / libphonenumber

Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers.
Apache License 2.0
0 stars 0 forks source link

Refactor PhoneNumberUtil::maybeStripNationalPrefixAndCarrierCode #19

Open ekner opened 2 years ago

ekner commented 2 years ago

Current cyclomatic complexity: 16

ekner commented 2 years ago

Plan:

In the if-statement if (transformRule == null || transformRule.length() == 0 || prefixMatcher.group(numOfGroups) == null) { there are two clauses which are quite similar. The first handles the case when there is no transform rule and the second when there is one. The contents in these clauses can be moved to their own functions. The first function must take the following parameters: isViableOriginalNumber, number, prefixMatcher, generalDesc, carrierCode, numOfGroups. The second one must take the same parameters and one additional: transformRule. Those are quite a lot, but there is also one upside with this refactoring: There are no values that are changed here that must be propagated to the calling function. This means the code can simply by copied to their respective functions without any changes.

ekner commented 2 years ago

Cyclomatic complexity after refactor: 7 (56% decrease from 16)