Skip to content

Refactor OpenSRS suggest method to properly handle limit parameter#44

Merged
loks0n merged 6 commits intomasterfrom
fix-opensrs-suggest-limit
Oct 6, 2025
Merged

Refactor OpenSRS suggest method to properly handle limit parameter#44
loks0n merged 6 commits intomasterfrom
fix-opensrs-suggest-limit

Conversation

@ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Oct 5, 2025

Summary

  • Simplified service selection logic by always including all services (suggestion, premium, lookup)
  • Fixed TLD filtering to apply across all services consistently
  • Implemented post-processing to enforce limit by prioritizing premium domains over suggestions
  • Removed conditional service selection based on price filters
  • Improved code readability by reducing nested conditionals

Changes

The previous implementation had complex conditional logic for selecting services and applying overrides. This refactor:

  1. Always queries all three services for comprehensive results
  2. Applies TLD filters uniformly across all services
  3. Handles the limit parameter by post-processing results and prioritizing premium domains
  4. Maintains support for price filtering (priceMin/priceMax)

Test plan

  • Test domain suggestions without any filters
  • Test with TLD filter
  • Test with limit parameter
  • Test with price filters (priceMin, priceMax)
  • Test combinations of filters
  • Verify premium domains are prioritized when limit is applied

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Add filter-by-type and premium price filters for domain suggestions; unified TLD application across discovery services.
    • Domain price lookup now returns pricing and premium flags alongside suggestion results.
  • Bug Fixes

    • Enforced valid filter/price combinations; improved result consistency, ordering and truncation when limits apply.
  • Tests

    • Expanded tests covering pricing, limits, single-TLD, premium-only scenarios and a dedicated price lookup test.

- Simplified service selection logic by always including all services
- Fixed TLD filtering to apply across all services (suggestion, premium, lookup)
- Implemented post-processing to enforce limit by prioritizing premium domains
- Removed conditional service selection based on price filters
- Improved code readability by reducing nested conditionals

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Oct 5, 2025

Walkthrough

Suggest API expanded with new filterType and premium price bounds, added getPrice(), stricter validation, always requests suggestion/premium/lookup with per-service overrides, aggregates and limits suggestion/premium results, and updates the Adapter signature and tests accordingly.

Changes

Cohort / File(s) Change Summary
OpenSRS implementation
src/Domains/Registrar/OpenSRS.php
- Updated public method `suggest(array
Abstract adapter API
src/Domains/Registrar/Adapter.php
- Updated abstract suggest signature to `abstract public function suggest(array
Tests
tests/OpenSRSTest.php
- Expanded testSuggest scenarios and assertions to cover: suggestions with price data, mixed premium/non-premium results, premium-only filtering with price constraints, premium-only without price filters, single-TLD behavior, adjusted limits and price-range assertions.
- Added testGetPrice to validate getPrice response structure and types.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Client
  participant Adapter as Registrar Adapter (OpenSRS)
  participant API as OpenSRS API

  Note over Client,Adapter: Input: query, tlds, limit, filterType, premiumPriceMin/Max
  Client->>Adapter: suggest(params)
  Adapter->>Adapter: validate filterType and premium price bounds
  Adapter->>Adapter: normalize query/tlds, build message (service_override, per-service max, premium overrides)
  Adapter->>API: request services: suggestion, premium, lookup
  API-->>Adapter: response {suggestion[], premium[], lookup[]}
  Adapter->>Adapter: parse suggestion & premium blocks
  alt price needed for domain
    Adapter->>Adapter: call getPrice(domain)
  end
  alt filterType or limits
    Adapter->>Adapter: apply filtering, merging, and in-memory limiting (prioritize premium then suggestion)
  end
  Adapter-->>Client: consolidated items array
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • loks0n

Poem

A rabbit hops through code and dots each name,
I sniff for premiums and tidy up the frame.
I check the prices, guard bounds with care,
I mix suggestions so results are fair.
Hoppity-hop — new endpoints, clean and tame.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the refactor of the OpenSRS suggest method to correctly enforce the limit parameter, which aligns with the PR’s stated goal of improving limit handling in that method.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-opensrs-suggest-limit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69dabbf and 499bcc9.

📒 Files selected for processing (3)
  • src/Domains/Registrar/Adapter.php (1 hunks)
  • src/Domains/Registrar/OpenSRS.php (1 hunks)
  • tests/OpenSRSTest.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/Domains/Registrar/OpenSRS.php (2)
src/Domains/Registrar/Adapter.php (2)
  • suggest (32-32)
  • tlds (37-37)
src/Domains/Registrar.php (2)
  • suggest (26-29)
  • tlds (31-34)
src/Domains/Registrar/Adapter.php (2)
src/Domains/Registrar/OpenSRS.php (2)
  • suggest (240-435)
  • tlds (479-483)
src/Domains/Registrar.php (2)
  • suggest (26-29)
  • tlds (31-34)
tests/OpenSRSTest.php (2)
src/Domains/Registrar/Adapter.php (1)
  • suggest (32-32)
src/Domains/Registrar/OpenSRS.php (1)
  • suggest (240-435)
🪛 GitHub Actions: Linter
src/Domains/Registrar/OpenSRS.php

[error] 1-1: PSR-12: 1 style issue in 11 files. 'OpenSRS.php' issue: braces, function_declaration, no_trailing (linting).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 499bcc9 and 9e08bcc.

📒 Files selected for processing (1)
  • src/Domains/Registrar/OpenSRS.php (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ChiragAgg5k
PR: utopia-php/domains#44
File: src/Domains/Registrar/OpenSRS.php:292-438
Timestamp: 2025-10-05T13:46:00.554Z
Learning: In the OpenSRS `suggest()` method, non-premium (suggestion) domains should be prioritized and shown first. When a limit is applied, the limit should be filled with suggestion domains first, and premium domains should only be included if there's remaining capacity after processing suggestions.
📚 Learning: 2025-10-05T13:46:00.554Z
Learnt from: ChiragAgg5k
PR: utopia-php/domains#44
File: src/Domains/Registrar/OpenSRS.php:292-438
Timestamp: 2025-10-05T13:46:00.554Z
Learning: In the OpenSRS `suggest()` method, non-premium (suggestion) domains should be prioritized and shown first. When a limit is applied, the limit should be filled with suggestion domains first, and premium domains should only be included if there's remaining capacity after processing suggestions.

Applied to files:

  • src/Domains/Registrar/OpenSRS.php
🧬 Code graph analysis (1)
src/Domains/Registrar/OpenSRS.php (2)
src/Domains/Registrar.php (3)
  • suggest (26-29)
  • tlds (31-34)
  • available (16-19)
src/Domains/Registrar/Adapter.php (3)
  • suggest (32-32)
  • tlds (37-37)
  • available (13-13)
🔇 Additional comments (6)
src/Domains/Registrar/OpenSRS.php (6)

234-256: LGTM! Parameter validation is comprehensive.

The validation logic correctly enforces:

  • Price range consistency (premiumPriceMin < premiumPriceMax)
  • Valid filter types and sort orders
  • Incompatible parameter combinations (e.g., price filters with filterType='suggestion')

258-285: LGTM! Request building correctly implements uniform service querying.

The implementation correctly:

  • Always queries all three services (suggestion, premium, lookup) as per PR objectives
  • Applies TLD filtering uniformly across all services via service_override
  • Sets per-service maximum limits when $limit is provided
  • Applies premium price filters only to the premium service

292-351: LGTM! Suggestion processing correctly prioritizes non-premium domains.

The implementation correctly:

  • Processes suggestion domains first, up to $limit
  • Fetches prices for available domains via getPrice()
  • Includes early return optimizations when sorting is not requested
  • Enforces the limit during iteration to avoid over-processing

This aligns with the learnings that suggestion domains should be prioritized first. Based on learnings.


415-436: LGTM! Sorting logic itself is correct.

The price-based sorting correctly:

  • Uses uasort to maintain key associations
  • Treats null prices as PHP_FLOAT_MAX (reasonable for unavailable/unpriceable domains)
  • Applies $limit after sorting via array_slice

Note: The sorting implementation is sound, but effectiveness depends on having both suggestion and premium domains collected before sorting (see previous comment regarding line 356).


441-481: LGTM! Well-structured price lookup method.

The getPrice() method correctly:

  • Follows the established pattern for OpenSRS API calls
  • Uses XPath to extract price, premium flag, and premium group from the response
  • Handles missing elements gracefully with isset() checks
  • Returns a clear, documented structure

This method integrates well with the suggestion processing at line 326.


292-438: Clarify: Implementation prioritizes suggestions, but PR objectives state premium priority.

The current implementation prioritizes suggestion domains over premiums when enforcing the limit (lines 308-313, 356, 372), which aligns with the retrieved learning that states: "suggestion domains should be prioritized and shown first... premium domains should only be included if there's remaining capacity after processing suggestions." Based on learnings.

However, this directly contradicts:

  • The PR objectives which state: "enforcing the limit via post-processing that prioritizes premium domains over suggestions"
  • The previous review comment which flagged that premium domains are excluded when suggestions fill the limit

Current behavior:

  • When $limit=5: fetch up to 5 suggestions first, then fill remaining capacity with premiums
  • Result: suggestions always appear first; premiums only if space remains

Please confirm:

  1. Is the current prioritization of suggestions over premiums the intended behavior?
  2. Should the PR objectives/description be updated to reflect this?
  3. Is the previous review comment outdated and should be disregarded?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/OpenSRSTest.php (1)

107-107: Consider using assertLessThanOrEqual for consistency.

Using assertCount(5, $result) expects exactly 5 results, which could cause test flakiness if the API returns fewer results. Other tests in this file use assertLessThanOrEqual (lines 132, 154, 172) for more resilient assertions.

Apply this diff for consistency:

-$this->assertCount(5, $result);
+$this->assertLessThanOrEqual(5, count($result));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aba0b34 and 1b3cadf.

📒 Files selected for processing (2)
  • src/Domains/Registrar/OpenSRS.php (1 hunks)
  • tests/OpenSRSTest.php (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-05T13:46:00.554Z
Learnt from: ChiragAgg5k
PR: utopia-php/domains#44
File: src/Domains/Registrar/OpenSRS.php:292-438
Timestamp: 2025-10-05T13:46:00.554Z
Learning: In the OpenSRS `suggest()` method, non-premium (suggestion) domains should be prioritized and shown first. When a limit is applied, the limit should be filled with suggestion domains first, and premium domains should only be included if there's remaining capacity after processing suggestions.

Applied to files:

  • src/Domains/Registrar/OpenSRS.php
🧬 Code graph analysis (2)
src/Domains/Registrar/OpenSRS.php (2)
src/Domains/Registrar/Adapter.php (3)
  • suggest (32-32)
  • tlds (37-37)
  • available (13-13)
src/Domains/Registrar.php (3)
  • suggest (26-29)
  • tlds (31-34)
  • available (16-19)
tests/OpenSRSTest.php (2)
src/Domains/Registrar/OpenSRS.php (2)
  • suggest (239-408)
  • getPrice (418-450)
src/Domains/Registrar/Adapter.php (1)
  • suggest (32-32)
🔇 Additional comments (5)
tests/OpenSRSTest.php (1)

180-190: LGTM!

The test properly validates the structure and types of the getPrice() response, including the new registry premium fields.

src/Domains/Registrar/OpenSRS.php (4)

241-251: LGTM! Solid parameter validation.

The validation logic correctly enforces parameter constraints:

  • Price range validation (min < max)
  • filterType enum validation
  • Prevents invalid combinations (suggestion + price filters)

265-288: LGTM! Service overrides configured correctly.

The service override logic properly:

  • Applies TLD filtering to all services conditionally based on filterType
  • Sets per-service maximum limits for suggestion and premium services
  • Applies premium price bounds only to the premium service

336-342: Clarify the prioritization behavior in the PR description.

The implementation prioritizes suggestion domains over premium domains (filling the limit with suggestions first), which contradicts the PR description stating "prioritizing premium domains over suggestions." However, this matches your stated preference in the past review discussion where you mentioned wanting to show non-premium domains first.

Based on learnings: The current implementation correctly prioritizes suggestions as per your preference, but the PR description should be updated to reflect this behavior accurately.

Consider updating the PR description to state: "enforce the limit parameter via post-processing, prioritizing suggestion domains over premium domains."


410-450: LGTM! Well-structured pricing API.

The getPrice() method provides comprehensive pricing information including:

  • Domain price extraction with proper float conversion
  • Registry premium status (boolean)
  • Premium group classification (string|null)

The XPath queries are clear and the response structure is well-documented.

@loks0n loks0n merged commit caa294d into master Oct 6, 2025
7 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix-opensrs-suggest-limit branch October 6, 2025 10:00
@coderabbitai coderabbitai bot mentioned this pull request Oct 15, 2025
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