Skip to content
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

[Skip] payment in Setup wizard when no payment is active #2468

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

osmansufy
Copy link
Contributor

@osmansufy osmansufy commented Dec 6, 2024

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced setup wizard functionality with improved step handling and redirection logic.
    • Introduced new methods for defining steps and retrieving the next step link, allowing for better management of the wizard flow.
  • Bug Fixes

    • Corrected references to the current step throughout the setup wizard, ensuring accurate rendering and navigation.
  • Refactor

    • Streamlined variable naming for clarity and consistency.
    • Improved error handling for form submissions to enhance user experience.
    • Minor formatting adjustments made for better readability.

@osmansufy osmansufy self-assigned this Dec 6, 2024
@osmansufy osmansufy requested a review from mrabbani December 6, 2024 09:44
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes in this pull request involve renaming the protected variable $step to $current_step across multiple classes related to the setup wizard functionality. This includes updates to type declarations and modifications in various methods to ensure consistency in referencing the current step. The changes enhance clarity and maintainability of the code without altering the core functionality of the setup wizards.

Changes

File Path Change Summary
includes/Admin/SetupWizard.php Renamed $step to $current_step, updated type declaration, and modified method references.
includes/Admin/SetupWizardNoWC.php Changed $this->step to $this->current_step in setup_wizard_content method. Minor formatting adjustments made.
includes/Vendor/SetupWizard.php Renamed $step to $current_step, added get_next_step_link() and set_steps() methods, updated method references.

Assessment against linked issues

Objective Addressed Explanation
Ensure no deprecated notices in Admin and Vendor Setup Wizard (#3303)
Fix console error on setup wizard payment section (#3454)
Prevent payment method availability without enabled methods (#3454) Logic to disable payment methods is not implemented.

Possibly related PRs

  • [Fix] Deprecated Noticed on Admin Setup Wizard #2414: This PR modifies the SetupWizard class in includes/Admin/SetupWizard.php, specifically addressing the handling of styles in the setup_wizard_header method, which is related to the overall functionality of the setup wizard, similar to the changes made in the main PR regarding variable renaming and usage consistency.
  • Fix admin fixed commission setting validation #2437: This PR updates the dokan_setup_commission_save method in the SetupWizard class, which is relevant to the overall functionality of the setup wizard.
  • Fix commission upgrader #2463: This PR involves changes to the commission handling logic, which may indirectly relate to the setup process in the SetupWizard class.

Suggested labels

QA approved, :+1: Dev Review Done, Upcoming Release

Suggested reviewers

  • mrabbani

🐰 In the wizard's glow, we hop and play,
Renamed our steps, in a clearer way.
Current steps lead us, no more to stray,
Together we build, come what may!
Hopping through code, bright as the day! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 33fc50f and 61b707d.

📒 Files selected for processing (1)
  • includes/Admin/SetupWizard.php (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Admin/SetupWizard.php

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Experiment)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 490a380 and 33fc50f.

📒 Files selected for processing (3)
  • includes/Admin/SetupWizard.php (10 hunks)
  • includes/Admin/SetupWizardNoWC.php (2 hunks)
  • includes/Vendor/SetupWizard.php (16 hunks)
🔇 Additional comments (1)
includes/Admin/SetupWizardNoWC.php (1)

76-82: Consistent Use of $this->current_step

The variable $this->current_step is correctly used to reference the current step, aligning with the updated property name and maintaining consistency across the setup wizard implementation.

Comment on lines +12 to +13
/** @var string Current Step */
protected string $current_step = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure PHP Version Compatibility with Typed Properties

The use of typed properties, such as protected string $current_step = '';, requires PHP 7.4 or higher. Please confirm that the project's minimum PHP version supports this feature to avoid compatibility issues.


// get step from url
if ( isset( $_GET['_admin_sw_nonce'], $_GET['step'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_admin_sw_nonce'] ) ), 'dokan_admin_setup_wizard_nonce' ) ) {
$this->step = sanitize_key( wp_unslash( $_GET['step'] ) );
$this->current_step = sanitize_key( wp_unslash( $_GET['step'] ) ) ?? current( array_keys( $this->steps ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Confirm PHP Version Compatibility with Null Coalescing Operator

The use of the null coalescing operator ?? in $this->current_step = sanitize_key( wp_unslash( $_GET['step'] ) ) ?? current( array_keys( $this->steps ) ); requires PHP 7.0 or higher. Please verify that the project's minimum PHP version supports this operator.

@@ -12,7 +12,7 @@
class SetupWizard {

/** @var string Currenct Step */
protected $step = '';
protected string $current_step = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure PHP Version Compatibility with Typed Properties

The use of typed properties, such as protected string $current_step = '';, requires PHP 7.4 or higher. Please confirm that the project's minimum PHP version supports this feature to avoid compatibility issues.

@@ -292,7 +292,7 @@

return add_query_arg(
[
'step' => $keys[ array_search( $this->step, array_keys( $this->steps ), true ) + 1 ],
'step' => $keys[ array_search( $this->current_step, array_keys( $this->steps ), true ) + 1 ],
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle Potential Array Offset Error in get_next_step_link Method

When calculating the next step, array_search( $this->current_step, array_keys( $this->steps ), true ) + 1 may exceed the bounds of the $keys array if $this->current_step is the last element. This could lead to an undefined index notice. Consider adding a check to ensure the computed index exists in $keys before accessing it.

Apply this diff to handle the array offset error:

 public function get_next_step_link() {
     $keys = array_keys( $this->steps );
-    return add_query_arg(
-        [
-            'step' => $keys[ array_search( $this->current_step, array_keys( $this->steps ), true ) + 1 ],
-            '_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ),
-        ]
-    );
+    $current_index = array_search( $this->current_step, $keys, true );
+    if ( false !== $current_index && isset( $keys[ $current_index + 1 ] ) ) {
+        $next_step = $keys[ $current_index + 1 ];
+    } else {
+        $next_step = '';
+    }
+    return add_query_arg(
+        [
+            'step' => $next_step,
+            '_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ),
+        ]
+    );
 }

Committable suggestion skipped: line range outside the PR's diff.

@osmansufy osmansufy added Needs: Dev Review It requires a developer review and approval and removed Needs: Dev Review It requires a developer review and approval labels Dec 9, 2024
@osmansufy osmansufy added the Needs: Dev Review It requires a developer review and approval label Dec 12, 2024
@mrabbani mrabbani mentioned this pull request Dec 17, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Dev Review It requires a developer review and approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant