Skip to content

Refactor: extract resolvePostcode method and introduce explaining variables in Address#1777

Closed
akanksharaut2662-rgb wants to merge 1 commit intodatafaker-net:mainfrom
akanksharaut2662-rgb:refactor/address-postcode-extract-method
Closed

Refactor: extract resolvePostcode method and introduce explaining variables in Address#1777
akanksharaut2662-rgb wants to merge 1 commit intodatafaker-net:mainfrom
akanksharaut2662-rgb:refactor/address-postcode-extract-method

Conversation

@akanksharaut2662-rgb
Copy link
Copy Markdown

@akanksharaut2662-rgb akanksharaut2662-rgb commented Mar 13, 2026

Summary

Two small refactoring improvements in Address.java:

  1. Extracted a private resolvePostcode() method shared by zipCode(), postcode(), and eircode()
  2. Introduced explaining variables for magic numbers in latitude() and longitude()

Reason for Refactoring:

  • zipCode(), postcode(), and eircode() had identical method bodies causing code duplication. Any future change would need to be made in three places
  • latitude() and longitude() used raw numeric literals (180, 90, 360) with no explanation of what they represent geographically

Changes Made:

  1. Address.java - Extract Method
    Extracted duplicated postcode resolution logic from zipCode(), postcode(), and eircode() into a shared private method resolvePostcode().

  2. Address.java - Introduce Explaining Variables
    Replaced magic numbers in latitude() and longitude() with clearly named variables. These variables clarify the meaning of the numeric values used in the geographic calculations.

Testing:

  1. No behavior change
  2. All existing tests pass

Notes:

This PR contains only structural refactoring improvements to improve readability and maintainability without altering application behavior.

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Mar 13, 2026

PR Summary

  • Centralizing Postcode Retrieval
    The process to fetch postcode information was used in multiple places. This PR has improved the system by centralizing this in a new method called resolvePostcode(). This helps in maintaining the code more effectively by eliminating repetition.

  • Enhanced Geolocation Calculations
    The system used to calculate latitude and longitude has been updated. Instead of using hard-to-understand numerical values, we have switched to using understandable named constants like latitudeRange, latitudeOffset, longitudeRange, longitudeOffset. This enhances the readability of our code and makes it easier to maintain or modify these values in the future.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.44%. Comparing base (66aeb85) to head (9fa80a2).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1777      +/-   ##
============================================
+ Coverage     92.37%   92.44%   +0.06%     
- Complexity     3448     3451       +3     
============================================
  Files           339      339              
  Lines          6794     6801       +7     
  Branches        670      670              
============================================
+ Hits           6276     6287      +11     
+ Misses          353      351       -2     
+ Partials        165      163       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Address provider methods to reduce duplication and improve readability without changing behavior.

Changes:

  • Extracted shared postcode generation logic into a private resolvePostcode() helper used by zipCode(), postcode(), and eircode().
  • Replaced numeric literals in latitude() and longitude() with explaining local variables.

Comment on lines +115 to +116
return String.format(faker.getContext().getLocale(), "%.8f",
(faker.random().nextDouble() * latitudeRange) - latitudeOffset);
Comment on lines +125 to +126
return String.format(faker.getContext().getLocale(), "%.8f",
(faker.random().nextDouble() * longitudeRange) - longitudeOffset);
@bodiam
Copy link
Copy Markdown
Contributor

bodiam commented Mar 14, 2026

AI PR

@bodiam bodiam closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants