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

feat: Dokan Data Store #2346

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

shohag121
Copy link
Member

@shohag121 shohag121 commented Aug 21, 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

  • New Features

    • Introduced a structured data management system with new DataStore, DataStoreInterface, and Model classes.
    • Added support for basic CRUD operations through the TestDataStore and TestModel classes.
    • Established a foundation for flexible data handling and extensibility within the application.
  • Bug Fixes

    • Improved error handling in model data retrieval processes.
  • Chores

    • Set up initial framework for future development of data management functionalities.

@shohag121 shohag121 added the DO NOT MERGE Don't merge this PR label Aug 21, 2024
@shohag121 shohag121 self-assigned this Aug 21, 2024
Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Walkthrough

The recent changes introduce a structured data management framework within the WeDevs Dokan plugin. Key components include an abstract data store class, a concrete implementation, and a model class, enabling CRUD operations through a standardized interface. This architecture enhances extensibility and maintainability, setting the stage for future data handling improvements.

Changes

Files Change Summary
includes/DataStore/AbstractDataStore.php, includes/DataStore/DataStore.php, includes/DataStore/DataStoreInterface.php, includes/DataStore/Model.php, includes/DataStore/TestDataStore.php, includes/DataStore/TestModel.php Introduced foundational classes and interfaces for data stores, including abstract and concrete implementations for CRUD operations, and a comprehensive data model structure.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DataStore
    participant Model

    User->>DataStore: Request Data
    DataStore->>Model: Instantiate Model
    Model->>DataStore: Load Data
    DataStore-->>User: Return Data
Loading

Poem

In the burrow deep, where data flows,
A new structure blooms, as the rabbit knows.
With stores abstract and models so bright,
CRUD operations dance in the moonlight.
Hopping along, we manage with glee,
Oh, what wonders this change brings to thee! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Outside diff range, codebase verification and nitpick comments (2)
includes/DataStore/TestModel.php (1)

9-9: Clarify the object type.

The comment suggests changing the object type. Ensure it reflects the intended use.

includes/DataStore/DataStore.php (1)

23-50: Clarify object type handling in the constructor.

The logic for handling object types could be clarified by adding comments or restructuring the code for better readability.

Consider adding comments or restructuring the code to make the object type handling clearer.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0d2b6aa and ea2a6e9.

Files selected for processing (6)
  • includes/DataStore/AbstractDataStore.php (1 hunks)
  • includes/DataStore/DataStore.php (1 hunks)
  • includes/DataStore/DataStoreInterface.php (1 hunks)
  • includes/DataStore/Model.php (1 hunks)
  • includes/DataStore/TestDataStore.php (1 hunks)
  • includes/DataStore/TestModel.php (1 hunks)
Additional comments not posted (7)
includes/DataStore/AbstractDataStore.php (1)

1-7: LGTM! Abstract class setup is appropriate.

The AbstractDataStore class correctly extends SqlQuery, providing a foundation for further data store implementations.

includes/DataStore/Model.php (1)

19-28: Verify data store loading in the constructor.

The constructor attempts to load a data store and handle exceptions. Ensure that DataStore::load and get_instance are correctly implemented.

Run the following script to verify the implementation of DataStore::load and get_instance:

Verification successful

Data store loading in the constructor is verified successfully.

The DataStore::load and get_instance methods are correctly implemented, ensuring the data store is properly loaded in the constructor. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of DataStore::load and get_instance.

# Test: Search for the DataStore class and its methods.
rg --type php -A 5 'class DataStore'

Length of output: 366


Script:

#!/bin/bash
# Description: Verify the implementation of DataStore::load and get_instance.

# Test: Search for the load method in the DataStore class.
rg --type php -A 10 'function load' includes/DataStore/DataStore.php

# Test: Search for the get_instance method in the DataStore class.
rg --type php -A 10 'function get_instance' includes/DataStore/DataStore.php

Length of output: 514

includes/DataStore/DataStoreInterface.php (1)

1-80: LGTM! Interface definition is appropriate.

The DataStoreInterface provides a clear contract for data store implementations, covering CRUD operations and querying.

includes/DataStore/DataStore.php (4)

3-5: Namespace and imports are correctly defined.

The namespace WeDevs\Dokan\DataStore is appropriate, and the Exception import is necessary for error handling.


7-18: Class declaration and properties are well-defined.

The DataStore class and its protected properties are appropriately declared, promoting encapsulation.


56-58: Static load method is correctly implemented.

The method correctly creates and returns a new DataStore instance.


63-65: get_instance method is correctly implemented.

The method correctly returns the data store instance.

Comment on lines +14 to +16
public function get(): Model {
// TODO: Implement get() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the get method.

The get method is currently unimplemented. Consider implementing it to retrieve model data.

Would you like assistance in implementing this method?

Comment on lines +21 to +23
public function create(): Model {
// TODO: Implement create() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the create method.

The create method is currently unimplemented. Consider implementing it to create new model data.

Would you like assistance in implementing this method?

Comment on lines +28 to +30
public function update(): Model {
// TODO: Implement update() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the update method.

The update method is currently unimplemented. Consider implementing it to update existing model data.

Would you like assistance in implementing this method?

Comment on lines +35 to +37
public function delete(): bool {
// TODO: Implement delete() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the delete method.

The delete method is currently unimplemented. Consider implementing it to delete model data.

Would you like assistance in implementing this method?

Comment on lines +13 to +15
public function create( &$model ) {
// TODO: Implement create() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the create method.

The create method is currently unimplemented. Consider implementing it to handle model creation.

Would you like assistance in implementing this method?

Comment on lines +27 to +29
public function delete( &$model ) {
// TODO: Implement delete() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the delete method.

The delete method is currently unimplemented. Consider implementing it to handle model deletion.

Would you like assistance in implementing this method?

Comment on lines +34 to +36
public function get( &$model ) {
// TODO: Implement get() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the get method.

The get method is currently unimplemented. Consider implementing it to retrieve model data.

Would you like assistance in implementing this method?

Comment on lines +41 to +43
public function query( array $args = [] ): array {
// TODO: Implement query() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the query method.

The query method is currently unimplemented. Consider implementing it to handle data queries.

Would you like assistance in implementing this method?

Comment on lines +48 to +50
public function count( array $args = [] ): int {
// TODO: Implement count() method.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the count method.

The count method is currently unimplemented. Consider implementing it to count data entries.

Would you like assistance in implementing this method?

Comment on lines +39 to +66
abstract public function get(): Model;

/**
* Store a new model data.
*
* @since DOKAN_SINCE
*
* @return Model
*/
abstract public function create(): Model;

/**
* Update the model data.
*
* @since DOKAN_SINCE
*
* @return Model
*/
abstract public function update(): Model;

/**
* Delete the model data.
*
* @since DOKAN_SINCE
*
* @return bool
*/
abstract public function delete(): bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure implementation of abstract methods.

The abstract methods get, create, update, and delete need to be implemented in derived classes.

Would you like assistance in implementing these methods in a derived class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE Don't merge this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant