Skip to content

Refactor/extract magic numbers and separator#197

Closed
blascosmog wants to merge 2 commits intoEndava:masterfrom
blascosmog:refactor/extract-magic-numbers-and-separator
Closed

Refactor/extract magic numbers and separator#197
blascosmog wants to merge 2 commits intoEndava:masterfrom
blascosmog:refactor/extract-magic-numbers-and-separator

Conversation

@blascosmog
Copy link
Copy Markdown
Contributor

Pull Request: Extract Magic Numbers and Centralize SEPARATOR Constant

Description

This PR refactors the codebase to eliminate magic numbers and centralize duplicated constants, improving code readability and maintainability across the project.

Changes Made

1. ServiceCaller.java — Extraction of Magic Numbers in ConnectionPool

  • Magic numbers removed: 10 and 15 in new ConnectionPool(10, 15, TimeUnit.MINUTES)
  • Constants created:
    • MAX_IDLE_CONNECTIONS = 10 — Maximum number of idle connections in the pool
    • KEEP_ALIVE_MINUTES = 15 — Time in minutes connections are kept alive
  • Benefit: Code is now self-documenting and easier to maintain

2. ConsoleUtils.java — Centralization of Separator and Magic Number 22

  • Magic number removed: 22 (offset for console width calculation)
  • Constants created:
    • SEPARATOR_PADDING = 22 — Padding for separator calculation
    • CONSOLE_SEPARATOR — Static string with the precalculated console separator
  • Benefit: Single source of truth for separator logic

3. TestCaseListener.java — Elimination of Code Duplication

  • Change: Replaced "-".repeat(ConsoleUtils.getConsoleColumns(22)) with ConsoleUtils.CONSOLE_SEPARATOR
  • Benefit: Removes code duplication and implicit coupling

4. CatsCommand.java — Elimination of Code Duplication

  • Change: Replaced "-".repeat(ConsoleUtils.getConsoleColumns(22)) with ConsoleUtils.CONSOLE_SEPARATOR
  • Benefit: Removes the second copy of the same magic number

Issues Resolved

Code Smell #1: Magic numbers in ServiceCaller (10, 15)
Code Smell #3: Magic number 22 duplicated in TestCaseListener and CatsCommand
DRY Violation: Duplicated separator code in two classes


Impact

  • Readability: Code is now self-documenting with descriptive constant names
  • Maintainability: Future changes to these values are made in a single location
  • Bug Reduction: Lower risk of inconsistencies due to typos or oversights
  • Best Practices: Follows clean code standards and principles

Testing

  • ✅ No functional changes — all logic remains identical
  • ✅ Existing tests should pass without modifications
  • ✅ Recommended: Run full test suite to validate changes

Notes for Reviewers

  • Constants are declared with static final for maximum efficiency
  • CONSOLE_SEPARATOR is precalculated once at class loading time
  • No changes to public APIs or program behavior

- Extract ConnectionPool values 10 and 15 into MAX_IDLE_CONNECTIONS
  and KEEP_ALIVE_MINUTES in ServiceCaller
- Extract magic number 22 into SEPARATOR_PADDING in ConsoleUtils
- Centralize CONSOLE_SEPARATOR in ConsoleUtils, use in
  TestCaseListener and CatsCommand to eliminate duplication
@en-milie
Copy link
Copy Markdown
Contributor

I'm going to reject this one also. Please avoid PRs that reformat code without bringing anything else.

@en-milie en-milie closed this Feb 27, 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.

2 participants