Skip to content

Comments

Reduce code duplication in Ads portal classes through improved inheritance#155

Draft
Copilot wants to merge 2 commits intodev/issue-123/code-duplicationsfrom
copilot/improve-ads-portals-inheritance
Draft

Reduce code duplication in Ads portal classes through improved inheritance#155
Copilot wants to merge 2 commits intodev/issue-123/code-duplicationsfrom
copilot/improve-ads-portals-inheritance

Conversation

Copy link
Contributor

Copilot AI commented Oct 15, 2025

Overview

This PR addresses issue #X by improving class inheritance in the Ads portal implementations to reduce code duplication. The refactoring centralizes common parsing patterns into the base class while maintaining portal-specific functionality.

Changes

Added Protected Helper Methods to RealEstateAdsPortalBase

Four new protected helper methods were added to provide common parsing functionality:

  1. ParsePriceFromNode(HtmlNode node, string xpath) - Extracts and parses decimal price values from HTML nodes by removing non-numeric characters
  2. ParseLayoutFromText(string text) - Parses layout information (e.g., "2+kk", "3+1") from text using regex pattern matching
  3. ParseFloorAreaFromText(string text) - Extracts floor area measurements from text using regex patterns
  4. GetPriceCommentWhenZero(decimal price, HtmlNode node, string xpath) - Returns price comment text when the price is zero (for "Price on request" scenarios)

All methods include comprehensive XML documentation and follow consistent error handling patterns.

Refactored Portal Classes

The following 10 portal classes were refactored to use the new helper methods:

  • BazosCzAdsPortal
  • BezrealitkyCzAdsPortal
  • BidliCzAdsPortal
  • BravisCzAdsPortal
  • CeskeRealityCzAdsPortal
  • MMRealityCzAdsPortal
  • RealcityCzAdsPortal
  • RealityIdnesCzAdsPortal
  • RemaxCzAdsPortal
  • SrealityCzAdsPortal

Example

Before:

// Duplicated in multiple portal classes
private static decimal ParsePrice(HtmlNode node)
{
    var value = node.SelectSingleNode(".//span[@class='price']")?.InnerText;
    if (value is null)
        return decimal.Zero;

    value = RegexMatchers.AllNonNumberValues().Replace(value, string.Empty);

    return decimal.TryParse(value, out var price)
        ? price
        : decimal.Zero;
}

After:

// Simple one-liner using base class helper
private static decimal ParsePrice(HtmlNode node)
{
    return ParsePriceFromNode(node, ".//span[@class='price']");
}

Impact

  • Net code reduction: 85 lines removed (229 deletions, 144 additions)
  • 11 files changed with surgical, minimal modifications
  • No new warnings introduced - builds succeed with same warning count as before
  • Backward compatible - no breaking changes to public APIs

Benefits

  1. Reduced duplication - Common parsing logic centralized in base class
  2. Easier maintenance - Future changes to parsing logic only need updates in one place
  3. Improved readability - Portal classes are more concise and focused on their specific logic
  4. Better testability - Common parsing logic can be tested once in the base class
  5. Consistent behavior - All portals use the same parsing approach, reducing edge case bugs
Original prompt

This section details on the original issue you should resolve

<issue_title>Improve class inheritance of Ads portals to prevent high code duplications.</issue_title>
<issue_description></issue_description>

<agent_instructions>Based on edits in this branch, try to continue with edits in order to lower code duplications in Portals classes.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #123


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: supermartzin <6864050+supermartzin@users.noreply.github.com>
@sonarqubecloud
Copy link

Copilot AI changed the title [WIP] Improve class inheritance of Ads portals to reduce code duplication Reduce code duplication in Ads portal classes through improved inheritance Oct 15, 2025
Copilot AI requested a review from supermartzin October 15, 2025 16:08
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