Skip to content

refactor: extract shared post type support logic to utility class#10

Open
jdevalk wants to merge 1 commit intomainfrom
optimize/post-type-support
Open

refactor: extract shared post type support logic to utility class#10
jdevalk wants to merge 1 commit intomainfrom
optimize/post-type-support

Conversation

@jdevalk
Copy link
Member

@jdevalk jdevalk commented Feb 16, 2026

Summary

Eliminates DRY violation by extracting duplicated post type support logic from AlternateLinkHandler and RewriteHandler into a shared PostTypeSupport utility class.

Changes

  • New: src/PostTypeSupport.php — Shared utility for post type validation
  • Modified: src/Discovery/AlternateLinkHandler.php — Uses shared utility, removes 21 lines of duplication
  • Modified: src/Router/RewriteHandler.php — Uses shared utility, removes 21 lines of duplication

Benefits

  • DRY compliance: Single source of truth for post type support logic
  • Maintainability: Changes to supported post types only need to happen in one place
  • Testability: Utility class can be unit tested independently
  • Clarity: Static utility methods make it clear this is stateless, shared logic

Testing

  • php -l syntax check passes for all modified files
  • ✅ Filter markdown_alternate_supported_post_types still works correctly
  • ✅ Alternate link tags appear for supported post types
  • .md URLs serve markdown for supported post types
  • ✅ Unsupported post types correctly return 404

No behavior changes — pure refactoring.

- Create PostTypeSupport utility class with static methods for post type validation
- Remove duplicated get_supported_post_types() and is_supported_post_type() methods from AlternateLinkHandler and RewriteHandler
- Update all post type checks to use PostTypeSupport::is_supported()
- Fix comment in AlternateLinkHandler from "published posts" to "published content"

This eliminates ~42 lines of duplicated code and provides a single source of truth for post type support logic. No behavior changes.

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

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

This PR refactors duplicated “supported post types” logic into a shared utility class so both discovery (alternate link tag output) and routing (rewrite/markdown serving) rely on a single source of truth.

Changes:

  • Introduces MarkdownAlternate\PostTypeSupport as the centralized post type support utility (including the existing markdown_alternate_supported_post_types filter).
  • Updates RewriteHandler to use PostTypeSupport::is_supported() instead of private, duplicated helpers.
  • Updates AlternateLinkHandler to use PostTypeSupport::is_supported() instead of private, duplicated helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/PostTypeSupport.php Adds shared utility for supported post type resolution via a WP filter.
src/Router/RewriteHandler.php Replaces duplicated support-check logic with calls to the shared utility.
src/Discovery/AlternateLinkHandler.php Replaces duplicated support-check logic with calls to the shared utility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant