refactor: extract shared post type support logic to utility class#10
Open
refactor: extract shared post type support logic to utility class#10
Conversation
- 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>
There was a problem hiding this comment.
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\PostTypeSupportas the centralized post type support utility (including the existingmarkdown_alternate_supported_post_typesfilter). - Updates
RewriteHandlerto usePostTypeSupport::is_supported()instead of private, duplicated helpers. - Updates
AlternateLinkHandlerto usePostTypeSupport::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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates DRY violation by extracting duplicated post type support logic from
AlternateLinkHandlerandRewriteHandlerinto a sharedPostTypeSupportutility class.Changes
src/PostTypeSupport.php— Shared utility for post type validationsrc/Discovery/AlternateLinkHandler.php— Uses shared utility, removes 21 lines of duplicationsrc/Router/RewriteHandler.php— Uses shared utility, removes 21 lines of duplicationBenefits
Testing
php -lsyntax check passes for all modified filesmarkdown_alternate_supported_post_typesstill works correctly.mdURLs serve markdown for supported post typesNo behavior changes — pure refactoring.