Skip to content

Added Platform Registry Class, Shopify Platform Base, a new List command #59778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 24, 2025

Conversation

naman03malhotra
Copy link
Contributor

@naman03malhotra naman03malhotra commented Jul 18, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR introduces the PlatformRegistry service to the WooCommerce CLI Migrator and integrates it with the existing command infrastructure.

Key Changes:

  • Added PlatformRegistry.php: Migrated from standalone plugin singleton pattern to a proper dependency injection service
  • Updated BaseCommand.php: Extended init() method to inject PlatformRegistry alongside CredentialManager
  • Enhanced ListCommand.php: Replaced hardcoded platform data with real PlatformRegistry integration

Technical Details:

  • Converted singleton pattern to constructor-based initialization following WooCommerce DI standards
  • Maintains WordPress filter compatibility (woocommerce_migrator_platforms) for extensibility
  • All commands now have access to both credential management and platform registry services

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Enable the feature flag: Add define( 'WOOCOMMERCE_MIGRATOR_ENABLED', true ); to wp-config.php
  2. Add the hook in a snippet as shown below.
  3. Run wp wc migrator list command via WP-CLI
  4. Verify the command displays a properly formatted table with custom platform information
add_filter( 'wc_migrator_register_platform', function( $platforms ) {
   $platforms['custom_platform'] = [
       'name' => 'Custom Platform', 
       'description' => 'Test custom platform for migration',
       'fetcher' => 'CustomPlatformFetcher',  
       'mapper' => 'CustomPlatformMapper',   
   ];
   return $platforms;
} );
  1. Run wp wc migrator list again and verify "Custom Platform" appears in the table alongside Shopify

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Minor

Type

  • Add - Adds functionality

Message

Add PlatformRegistry service to CLI Migrator with dependency injection integration

@naman03malhotra naman03malhotra requested a review from Copilot July 18, 2025 12:33
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 18, 2025
Copy link
Contributor

@Copilot 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 introduces a PlatformRegistry service to the WooCommerce CLI Migrator, transitioning from hardcoded platform data to a proper dependency injection pattern.

  • Adds PlatformRegistry class with platform discovery via WordPress filters and dynamic instantiation of fetcher/mapper classes
  • Updates BaseCommand to inject both CredentialManager and PlatformRegistry dependencies
  • Refactors ListCommand to use real platform registry data instead of hardcoded array

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
PlatformRegistry.php New service class providing platform discovery, validation, and factory methods for fetcher/mapper instances
BaseCommand.php Extended init method to accept PlatformRegistry dependency injection
ListCommand.php Replaced hardcoded platform data with dynamic registry lookup and formatting
Comments suppressed due to low confidence (1)

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php:34

  • [nitpick] The variable name 'formatted_items' could be more descriptive. Consider renaming to 'platform_items' or 'table_rows' to better indicate its purpose.
		$formatted_items = array();

Copy link
Contributor

github-actions bot commented Jul 18, 2025

Testing Guidelines

Hi @xristos3490 ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@naman03malhotra naman03malhotra changed the title Added Platform Registry Class and passed it a dependecy to basecommand Added Platform Registry Class and passed it as a dependecy to basecommand Jul 18, 2025
Copy link
Contributor

github-actions bot commented Jul 18, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Member

@xristos3490 xristos3490 left a comment

Choose a reason for hiding this comment

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

Code looks good, but I don't see the Shopify or the custom one described in the testing steps. Could you please take another look here?
Screenshot 2025-07-22 at 7 18 07 PM

@naman03malhotra
Copy link
Contributor Author

Hey @xristos3490, thanks for testing, I've updated the instructions. The hook function was not correct, please test now.

Base automatically changed from feat/list-command to trunk July 23, 2025 08:59
@naman03malhotra naman03malhotra force-pushed the feat/platform-registry branch from ae3205c to dd3725d Compare July 23, 2025 09:07
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

📝 Walkthrough

Walkthrough

This change introduces a new PlatformRegistry service to the WooCommerce CLI Migrator, centralizing platform management, validation, and instantiation. The previously used BaseCommand abstract class is removed, and CLI commands (ListCommand, ProductsCommand, ResetCommand, SetupCommand) are refactored to use explicit dependency injection of PlatformRegistry and CredentialManager. The Shopify platform is added as a built-in migration platform with fetcher and mapper classes. Command namespaces are updated from 'wc migrator' to 'wc migrate'. Documentation for platform development is added.

Changes

File(s) Change Summary
plugins/woocommerce/changelog/59778-feat-platform-registry Added changelog entry describing the new PlatformRegistry service for CLI Migrator.
plugins/woocommerce/changelog/59780-feat-shopify-platform Added changelog entry for introducing Shopify as a built-in migration platform.
plugins/woocommerce/changelog/59803-feedback-59741 Added changelog entry describing refactor of CLI Migrator commands to use CredentialManager and PlatformRegistry services.
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php Removed entire BaseCommand abstract class, including credential handling and platform resolution methods and properties.
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php Refactored to remove BaseCommand inheritance; injected PlatformRegistry; updated platform listing to use dynamic registry data; enhanced output formatting; updated command namespace.
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php Removed BaseCommand inheritance; added dependency injection for CredentialManager and PlatformRegistry; updated platform resolution and credential setup logic.
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php Removed BaseCommand inheritance; added dependency injection for CredentialManager and PlatformRegistry; updated platform resolution and credential management logic.
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php Removed BaseCommand inheritance; added dependency injection for CredentialManager and PlatformRegistry; updated platform resolution and credential setup logic.
plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php Added new PlatformRegistry class managing platform registration, validation, instantiation, and CLI integration support.
plugins/woocommerce/src/Internal/CLI/Migrator/Core/CredentialManager.php Added setup_credentials method to handle interactive CLI credential setup given required fields.
plugins/woocommerce/src/Internal/CLI/Migrator/Runner.php Added init_platforms method to initialize built-in platforms; changed WP-CLI command namespaces from 'wc migrator' to 'wc migrate'.
plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/README.md Added platform development guide documenting platform architecture, plugin creation, and best practices.
plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php Added new ShopifyFetcher class implementing PlatformFetcherInterface with stub methods for data fetching.
plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php Added new ShopifyMapper class implementing PlatformMapperInterface with stub method for product data mapping.
plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyPlatform.php Added new ShopifyPlatform class registering Shopify as a migrator platform via filter hook.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WP_CLI
    participant Command
    participant PlatformRegistry
    participant CredentialManager

    User->>WP_CLI: Run migrate command (list/setup/reset/products)
    WP_CLI->>Command: __invoke(args, assoc_args)
    Command->>PlatformRegistry: resolve_platform(assoc_args)
    PlatformRegistry-->>Command: platform_slug
    alt Credential setup required
        Command->>PlatformRegistry: get_platform_credential_fields(platform_slug)
        PlatformRegistry-->>Command: required_fields
        Command->>CredentialManager: setup_credentials(platform_slug, required_fields)
        CredentialManager-->>Command: credentials saved
    end
    Command->>WP_CLI: Output results or messages
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/platform-registry

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 3

♻️ Duplicate comments (1)
plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (1)

49-49: Filter name inconsistency with PR documentation.

The filter name 'wc_migrator_register_platform' doesn't match the 'woocommerce_migrator_platforms' mentioned in the PR testing instructions. This inconsistency could cause confusion for developers trying to register platforms.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a33634 and dd3725d.

📒 Files selected for processing (5)
  • plugins/woocommerce/changelog/59778-feat-platform-registry (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Runner.php (0 hunks)
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
🧠 Learnings (3)
📓 Common learnings
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-07-21T05:22:46.417Z
Learning: Provide clear, step-by-step instructions for how to test the changes in the PR description.
plugins/woocommerce/changelog/59778-feat-platform-registry (2)

Learnt from: jorgeatorres
PR: #59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in plugins/woocommerce/changelog/ directory and are processed during releases, not at the repository root level.

Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/woo-build.mdc:0-0
Timestamp: 2025-07-18T14:55:02.778Z
Learning: To watch for changes during development, use 'pnpm --filter=@woocommerce/plugin-woocommerce watch:build' to ensure experimental features are active.

plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (3)

Learnt from: vladolaru
PR: #58784
File: plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders/Paytrail.php:29-35
Timestamp: 2025-06-18T09:58:10.616Z
Learning: In WooCommerce codebase, prefer using wc_string_to_bool() over filter_var($value, FILTER_VALIDATE_BOOLEAN) when converting option values (especially 'yes'/'no' style flags) to boolean. The WooCommerce helper function is more idiomatic and handles the conversion consistently with core WooCommerce patterns.

Learnt from: vladolaru
PR: #58784
File: plugins/woocommerce/src/Internal/Admin/Settings/Payments.php:431-439
Timestamp: 2025-06-17T14:19:30.933Z
Learning: In plugins/woocommerce/src/Internal/Admin/Settings/Payments.php, the process_payment_provider_states() method intentionally filters out payment providers that don't have a _suggestion_id. This is by design to only track state changes for gateways from partner extensions, not core WooCommerce gateways or other installed gateways.

Learnt from: samueljseay
PR: #58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.

💤 Files with no reviewable changes (1)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Runner.php
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
🧠 Learnings (3)
📓 Common learnings
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-07-21T05:22:46.417Z
Learning: Provide clear, step-by-step instructions for how to test the changes in the PR description.
plugins/woocommerce/changelog/59778-feat-platform-registry (2)

Learnt from: jorgeatorres
PR: #59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in plugins/woocommerce/changelog/ directory and are processed during releases, not at the repository root level.

Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/woo-build.mdc:0-0
Timestamp: 2025-07-18T14:55:02.778Z
Learning: To watch for changes during development, use 'pnpm --filter=@woocommerce/plugin-woocommerce watch:build' to ensure experimental features are active.

plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (3)

Learnt from: vladolaru
PR: #58784
File: plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders/Paytrail.php:29-35
Timestamp: 2025-06-18T09:58:10.616Z
Learning: In WooCommerce codebase, prefer using wc_string_to_bool() over filter_var($value, FILTER_VALIDATE_BOOLEAN) when converting option values (especially 'yes'/'no' style flags) to boolean. The WooCommerce helper function is more idiomatic and handles the conversion consistently with core WooCommerce patterns.

Learnt from: vladolaru
PR: #58784
File: plugins/woocommerce/src/Internal/Admin/Settings/Payments.php:431-439
Timestamp: 2025-06-17T14:19:30.933Z
Learning: In plugins/woocommerce/src/Internal/Admin/Settings/Payments.php, the process_payment_provider_states() method intentionally filters out payment providers that don't have a _suggestion_id. This is by design to only track state changes for gateways from partner extensions, not core WooCommerce gateways or other installed gateways.

Learnt from: samueljseay
PR: #58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.

🔇 Additional comments (2)
plugins/woocommerce/changelog/59778-feat-platform-registry (1)

1-4: Changelog entry follows the correct format and location.

The changelog entry correctly uses the WooCommerce changelog directory structure and format.

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php (1)

8-8: Dependency injection implementation looks good.

The PlatformRegistry integration follows the existing pattern for CredentialManager and maintains proper type safety with the final init() method.

Also applies to: 23-28, 38-40

Comment on lines 34 to 42
$formatted_items = array();
foreach ( $platforms as $id => $details ) {
$formatted_items[] = array(
'id' => $id,
'name' => $details['name'] ?? '',
'fetcher' => $details['fetcher'] ?? '',
'mapper' => $details['mapper'] ?? '',
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider validating required platform fields before display.

The current implementation uses null coalescing to provide empty strings for missing fields, which could hide improperly registered platforms. Consider validating that all required fields (name, fetcher, mapper) are present and skip platforms with missing data or show a warning.

 $formatted_items = array();
 foreach ( $platforms as $id => $details ) {
+    // Skip platforms missing required fields
+    if ( empty( $details['name'] ) || empty( $details['fetcher'] ) || empty( $details['mapper'] ) ) {
+        WP_CLI::warning( sprintf( 'Platform "%s" is missing required fields and will be skipped.', $id ) );
+        continue;
+    }
     $formatted_items[] = array(
         'id'      => $id,
-        'name'    => $details['name'] ?? '',
-        'fetcher' => $details['fetcher'] ?? '',
-        'mapper'  => $details['mapper'] ?? '',
+        'name'    => $details['name'],
+        'fetcher' => $details['fetcher'],
+        'mapper'  => $details['mapper'],
     );
 }
🤖 Prompt for AI Agents
In plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php around
lines 34 to 42, the code currently uses null coalescing to default missing
platform fields to empty strings, which can mask improperly registered
platforms. Update the loop to validate that each platform has all required
fields (name, fetcher, mapper) present and non-empty before adding to the
formatted_items array. If any required field is missing, either skip that
platform or log a warning message to notify about the incomplete registration.

Comment on lines +55 to +59
foreach ( $platforms as $platform_id => $config ) {
if ( isset( $config['fetcher'], $config['mapper'] ) ) {
$this->platforms[ $platform_id ] = $config;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Strengthen platform configuration validation.

The current validation only checks for fetcher and mapper existence but doesn't validate the configuration structure or required fields.

 foreach ( $platforms as $platform_id => $config ) {
+    // Validate platform configuration structure
+    if ( ! is_array( $config ) ) {
+        continue;
+    }
+    
+    // Ensure all required fields are present
+    if ( ! isset( $config['name'], $config['fetcher'], $config['mapper'] ) ) {
+        continue;
+    }
+    
+    // Validate field types
+    if ( ! is_string( $config['name'] ) || ! is_string( $config['fetcher'] ) || ! is_string( $config['mapper'] ) ) {
+        continue;
+    }
+    
-    if ( isset( $config['fetcher'], $config['mapper'] ) ) {
         $this->platforms[ $platform_id ] = $config;
-    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
foreach ( $platforms as $platform_id => $config ) {
if ( isset( $config['fetcher'], $config['mapper'] ) ) {
$this->platforms[ $platform_id ] = $config;
}
}
foreach ( $platforms as $platform_id => $config ) {
// Validate platform configuration structure
if ( ! is_array( $config ) ) {
continue;
}
// Ensure all required fields are present
if ( ! isset( $config['name'], $config['fetcher'], $config['mapper'] ) ) {
continue;
}
// Validate field types
if ( ! is_string( $config['name'] ) || ! is_string( $config['fetcher'] ) || ! is_string( $config['mapper'] ) ) {
continue;
}
$this->platforms[ $platform_id ] = $config;
}
🤖 Prompt for AI Agents
In plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
around lines 55 to 59, the current code only checks if 'fetcher' and 'mapper'
keys exist in the platform configuration but does not validate the structure or
required fields. Enhance the validation by verifying that the configuration
array contains all necessary keys with valid types or formats before assigning
it to $this->platforms. Implement explicit checks for each required field and
ensure the configuration meets expected criteria to prevent invalid platform
setups.

);
}

return new $fetcher_class();
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider handling constructor parameters for fetcher and mapper classes.

The current implementation assumes fetcher and mapper classes have parameterless constructors. This could cause fatal errors if the classes require constructor arguments.

Consider either:

  1. Document that fetcher/mapper classes must have parameterless constructors
  2. Add support for constructor parameters through the platform configuration
  3. Wrap instantiation in try-catch blocks to handle constructor failures gracefully

Also applies to: 153-153


🏁 Script executed:

#!/bin/bash
# Check if there are any existing fetcher/mapper implementations that might have constructor parameters
# This will help determine if this is a real concern or theoretical

# Search for classes implementing PlatformFetcherInterface
ast-grep --pattern 'class $_ implements $_PlatformFetcherInterface$_ {
  $$$
}'

# Search for classes implementing PlatformMapperInterface  
ast-grep --pattern 'class $_ implements $_PlatformMapperInterface$_ {
  $$$
}'

# Also search for any existing fetcher/mapper classes by common naming patterns
fd -e php -x grep -l "class.*Fetcher" {} \; | head -20
fd -e php -x grep -l "class.*Mapper" {} \; | head -20

Length of output: 429


PlatformRegistry fetcher/mapper instantiation assumes parameterless constructors

Verified that there are currently no PlatformFetcherInterface or PlatformMapperInterface implementations in the codebase defining constructors with parameters—so the risk is theoretical today. To prevent future breakage if anyone adds a fetcher or mapper with required dependencies, please:

  • Document in your developer or plugin docs (and/or in the PHPDoc for PlatformRegistry) that all fetcher and mapper classes must provide parameterless constructors.
  • Optionally, consider refactoring plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (lines 116 and 153) to accept constructor arguments via configuration or a factory/DI container in the future.
🤖 Prompt for AI Agents
In plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php at
line 116, the code instantiates fetcher and mapper classes assuming they have
parameterless constructors, which could cause issues if future implementations
require constructor parameters. To fix this, add clear PHPDoc comments in
PlatformRegistry and relevant developer documentation stating that all fetcher
and mapper classes must have parameterless constructors. Additionally, consider
planning a refactor to allow passing constructor arguments via configuration or
a factory/DI container for better flexibility in the future.

@xristos3490
Copy link
Member

Thank you, Naman!

I now have my own migrators, but I still can't find the Shopify one. Am I missing something? 🤔
Screenshot 2025-07-23 at 1 02 42 PM

P.S. Not commenting on validation since we discussed this one to be fixed in the following PR.

@naman03malhotra
Copy link
Contributor Author

I now have my own migrators, but I still can't find the Shopify one. Am I missing something?

I've removed Shopify from testing instrucitons after you comment, as it is in this PR: #59780

Copy link
Member

@xristos3490 xristos3490 left a comment

Choose a reason for hiding this comment

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

Thanks for clarifying! 🙌

@naman03malhotra naman03malhotra linked an issue Jul 24, 2025 that may be closed by this pull request
* Added platform list command and Platform interfaces

* lint issues

* Added platform registry class

* Added Shopify internal platform scaffolding

* Add changefile(s) from automation for the following project(s): woocommerce

* updated list command formating

* lint issues

* lint issues

* Improve separation of concerns and eliminate unnecessary base class coupling. (#59803)

* Added platform list command and Platform interfaces

* lint issues

* Moved credital setup logic to credential manager

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>

---------

Co-authored-by: github-actions <github-actions@github.com>
Copy link
Contributor

@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

♻️ Duplicate comments (2)
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php (1)

57-63: Consider validating required platform fields before display.

The current implementation uses null coalescing to provide empty strings for missing fields, which could hide improperly registered platforms. Consider validating that all required fields (name, fetcher, mapper) are present and skip platforms with missing data or show a warning.

 foreach ( $platforms as $id => $details ) {
+    // Skip platforms missing required fields
+    if ( empty( $details['name'] ) || empty( $details['fetcher'] ) || empty( $details['mapper'] ) ) {
+        WP_CLI::warning( sprintf( 'Platform "%s" is missing required fields and will be skipped.', $id ) );
+        continue;
+    }
     $formatted_items[] = array(
         'id'      => $id,
-        'name'    => $details['name'] ?? '',
-        'fetcher' => $details['fetcher'] ?? '',
-        'mapper'  => $details['mapper'] ?? '',
+        'name'    => $details['name'],
+        'fetcher' => $details['fetcher'],
+        'mapper'  => $details['mapper'],
     );
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php (1)

68-70: Verify error handling consistency with SetupCommand.

Similar to SetupCommand, this code calls WP_CLI::error() followed by a return statement. Ensure consistent error handling behavior across commands.

🧹 Nitpick comments (1)
plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php (1)

64-64: Remove trailing whitespace.

Line 64 contains trailing whitespace that should be removed.

-			WP_CLI::log( "Credentials for '{$platform}' not found. Let's set them up." );
-			
+			WP_CLI::log( "Credentials for '{$platform}' not found. Let's set them up." );
+
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd3725d and d74779a.

📒 Files selected for processing (14)
  • plugins/woocommerce/changelog/59780-feat-shopify-platform (1 hunks)
  • plugins/woocommerce/changelog/59803-feedback-59741 (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php (0 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/CredentialManager.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/README.md (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyPlatform.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Runner.php (3 hunks)
💤 Files with no reviewable changes (1)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/BaseCommand.php
✅ Files skipped from review due to trivial changes (2)
  • plugins/woocommerce/changelog/59803-feedback-59741
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Runner.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/CredentialManager.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyPlatform.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/CredentialManager.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyPlatform.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-07-21T05:22:46.426Z
Learning: Provide clear, step-by-step instructions for how to test the changes in the PR description.
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
plugins/woocommerce/changelog/59780-feat-shopify-platform (2)

Learnt from: jorgeatorres
PR: #59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in plugins/woocommerce/changelog/ directory and are processed during releases, not at the repository root level.

Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/woo-build.mdc:0-0
Timestamp: 2025-07-18T14:55:02.778Z
Learning: To watch for changes during development, use 'pnpm --filter=@woocommerce/plugin-woocommerce watch:build' to ensure experimental features are active.

plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php (1)

Learnt from: tpaksu
PR: #59172
File: plugins/woocommerce/src/Internal/Fulfillments/Providers/MPLShippingProvider.php:14-21
Timestamp: 2025-06-26T10:47:27.212Z
Learning: In the WooCommerce fulfillments system, only the UPS shipping provider is currently fully implemented. All other shipping provider classes in plugins/woocommerce/src/Internal/Fulfillments/Providers/ are placeholders for future implementations, so empty shipping country arrays and stub methods in these classes are intentional and should not be flagged as issues.

plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php (1)

Learnt from: tpaksu
PR: #59172
File: plugins/woocommerce/src/Internal/Fulfillments/Providers/MPLShippingProvider.php:14-21
Timestamp: 2025-06-26T10:47:27.212Z
Learning: In the WooCommerce fulfillments system, only the UPS shipping provider is currently fully implemented. All other shipping provider classes in plugins/woocommerce/src/Internal/Fulfillments/Providers/ are placeholders for future implementations, so empty shipping country arrays and stub methods in these classes are intentional and should not be flagged as issues.

🪛 PHPMD (2.15.0)
plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php

35-35: Avoid unused parameters such as '$args'. (Unused Code Rules)

(UnusedFormalParameter)


51-51: Avoid unused parameters such as '$args'. (Unused Code Rules)

(UnusedFormalParameter)

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php

45-45: Avoid unused parameters such as '$args'. (Unused Code Rules)

(UnusedFormalParameter)


45-45: Avoid unused parameters such as '$assoc_args'. (Unused Code Rules)

(UnusedFormalParameter)

plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php

33-33: Avoid unused parameters such as '$platform_data'. (Unused Code Rules)

(UnusedFormalParameter)

🔇 Additional comments (9)
plugins/woocommerce/changelog/59780-feat-shopify-platform (1)

1-4: LGTM! Properly formatted changelog entry.

The changelog entry correctly follows WooCommerce's format and accurately describes the Shopify platform addition to the CLI Migrator.

plugins/woocommerce/src/Internal/CLI/Migrator/Core/CredentialManager.php (1)

82-100: LGTM! Well-structured credential setup method.

The setup_credentials method follows good practices:

  • Proper input validation with early return
  • Clear error messaging via WP_CLI::error
  • Effective delegation to existing methods
  • Descriptive logging for user feedback

The implementation integrates well with the existing credential management workflow.

plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyMapper.php (1)

24-36: LGTM! Proper stub implementation for future development.

The ShopifyMapper class correctly implements the PlatformMapperInterface with appropriate stub methods. The documentation clearly indicates this is a placeholder for future implementation, which aligns with the phased development approach.

The unused parameter warning from static analysis is expected and acceptable for stub implementations.

plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyPlatform.php (1)

20-47: LGTM! Clean platform registration implementation.

The ShopifyPlatform class properly implements the platform registration pattern:

  • Correct use of WordPress filter system for extensibility
  • Appropriate static method pattern for initialization
  • Well-structured platform metadata with required fields
  • Safe class references using ::class constants

The implementation integrates seamlessly with the new platform registry system.

plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Shopify/ShopifyFetcher.php (1)

23-54: LGTM! Well-structured stub implementation with correct return formats.

The ShopifyFetcher class properly implements the PlatformFetcherInterface with appropriate stub methods:

  • fetch_batch returns the correct data structure with items, cursor, and hasNextPage fields
  • fetch_total_count returns appropriate placeholder value
  • Documentation clearly indicates future implementation plans

The unused parameter warnings from static analysis are expected and acceptable for stub implementations that will be replaced with actual Shopify GraphQL API logic.

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php (1)

14-41: Well-structured dependency injection implementation.

The refactoring from inheritance to composition with explicit dependency injection is clean and follows best practices. The typed properties and init() method align with WooCommerce's DI container patterns.

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php (1)

14-41: Consistent DI implementation across commands.

The dependency injection pattern is implemented consistently with other refactored commands, maintaining good architectural cohesion.

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php (1)

13-31: Clean dependency injection with appropriate service selection.

Good design choice to only inject PlatformRegistry since this command doesn't need credential management functionality.

plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php (1)

14-41: Good use of final keyword and consistent DI pattern.

Making the class final is a good practice when inheritance is not intended. The dependency injection implementation maintains consistency with other commands.

Copy link
Contributor

@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: 0

♻️ Duplicate comments (3)
plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (3)

55-59: Strengthen platform configuration validation to guard against unexpected inputs.

The current validation only checks for fetcher and mapper existence but doesn't validate the configuration structure or required fields. This could lead to runtime errors with malformed platform configurations.

Apply enhanced validation to ensure robust input handling:

 foreach ( $platforms as $platform_id => $config ) {
+    // Validate platform configuration structure
+    if ( ! is_array( $config ) ) {
+        continue;
+    }
+    
+    // Ensure all required fields are present
+    if ( ! isset( $config['name'], $config['fetcher'], $config['mapper'] ) ) {
+        continue;
+    }
+    
+    // Validate field types
+    if ( ! is_string( $config['name'] ) || ! is_string( $config['fetcher'] ) || ! is_string( $config['mapper'] ) ) {
+        continue;
+    }
+    
-    if ( isset( $config['fetcher'], $config['mapper'] ) ) {
         $this->platforms[ $platform_id ] = $config;
-    }
 }

116-116: Document parameterless constructor requirement for fetcher classes.

The instantiation assumes fetcher classes have parameterless constructors, which could cause fatal errors if future implementations require constructor arguments.

As verified in previous reviews, this is currently not an issue but should be documented to prevent future breakage. Add PHPDoc comments stating that all fetcher classes must provide parameterless constructors, or consider supporting constructor parameters via configuration in the future.


153-153: Document parameterless constructor requirement for mapper classes.

Similar to the fetcher method, this instantiation assumes mapper classes have parameterless constructors. This could cause issues if future implementations require constructor parameters.

Ensure documentation clearly states that all mapper classes must provide parameterless constructors to prevent future breakage.

🧹 Nitpick comments (1)
plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (1)

206-214: Consider making credential fields configurable per platform.

The current hardcoded approach works for the initial implementation, but consider making credential fields configurable through the platform configuration array to improve extensibility.

This would allow platforms to define their own credential requirements:

// In platform configuration
'credentials' => array(
    'api_key' => 'Enter your API Access Token:',
    'shop_url' => 'Enter your store URL:',
)

// In method
return $platform_config['credentials'] ?? array();
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d74779a and 9a8d713.

📒 Files selected for processing (6)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php (2 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (1 hunks)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/README.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ProductsCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.php
  • plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ResetCommand.php
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-07-21T05:22:46.426Z
Learning: Provide clear, step-by-step instructions for how to test the changes in the PR description.
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.
plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (3)

Learnt from: vladolaru
PR: #58784
File: plugins/woocommerce/src/Internal/Admin/Settings/PaymentsProviders/Paytrail.php:29-35
Timestamp: 2025-06-18T09:58:10.616Z
Learning: In WooCommerce codebase, prefer using wc_string_to_bool() over filter_var($value, FILTER_VALIDATE_BOOLEAN) when converting option values (especially 'yes'/'no' style flags) to boolean. The WooCommerce helper function is more idiomatic and handles the conversion consistently with core WooCommerce patterns.

Learnt from: vladolaru
PR: #58784
File: plugins/woocommerce/src/Internal/Admin/Settings/Payments.php:431-439
Timestamp: 2025-06-17T14:19:30.933Z
Learning: In plugins/woocommerce/src/Internal/Admin/Settings/Payments.php, the process_payment_provider_states() method intentionally filters out payment providers that don't have a _suggestion_id. This is by design to only track state changes for gateways from partner extensions, not core WooCommerce gateways or other installed gateways.

Learnt from: samueljseay
PR: #58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
  • GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.2] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Lint - @woocommerce/plugin-woocommerce
  • GitHub Check: build
🔇 Additional comments (4)
plugins/woocommerce/src/Internal/CLI/Migrator/Core/PlatformRegistry.php (4)

1-30: LGTM: Clean class structure with proper dependency management.

The file structure follows PHP best practices with strict typing, appropriate imports, and a clean constructor that delegates platform loading. The dependency injection approach aligns with WooCommerce's DI standards as mentioned in the PR objectives.


67-69: LGTM: Simple and correct getter implementation.


78-80: LGTM: Safe platform retrieval with proper null handling.


164-189: LGTM: Robust platform resolution with comprehensive error handling.

Excellent implementation that handles multiple edge cases:

  • Missing platform argument with default fallback
  • Invalid platform with helpful error messages listing available platforms
  • No registered platforms with clear guidance
  • Proper use of WP_CLI methods for CLI context

@naman03malhotra naman03malhotra enabled auto-merge (squash) July 24, 2025 14:16
@naman03malhotra naman03malhotra merged commit bf641c7 into trunk Jul 24, 2025
24 checks passed
@naman03malhotra naman03malhotra deleted the feat/platform-registry branch July 24, 2025 14:23
@github-actions github-actions bot added this to the 10.2.0 milestone Jul 24, 2025
@naman03malhotra naman03malhotra changed the title Added Platform Registry Class and passed it as a dependecy to basecommand Added Platform Registry Class, Shopify Platform Base, List command etc Jul 24, 2025
@naman03malhotra naman03malhotra changed the title Added Platform Registry Class, Shopify Platform Base, List command etc Added Platform Registry Class, Shopify Platform Base, a new List command Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Migrator]: Implement PlatformRegistry
2 participants