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

Refactoring #186

Open
w3bdesign opened this issue May 30, 2023 · 0 comments
Open

Refactoring #186

w3bdesign opened this issue May 30, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@w3bdesign
Copy link
Owner

Here are some suggestions for refactoring the code:

  1. Rename the class to follow the PHP naming convention - AlgoliaWooIndexer
  2. Extract constants to a separate class - AlgoliaWooIndexerConstants
  3. Extract functions to separate classes - AlgoliaWooIndexerSettings, AlgoliaWooIndexerNonce, etc.
  4. Use snake_case for function and variable names instead of camelCase
  5. Add docblock comments for all functions and variables
  6. Validate input in the functions where they are used, not in a global validate function
  7. Use self::class instead of get_called_class()
  8. Avoid static properties and methods where possible. Use dependency injection instead.
  9. Move activation/deactivation hooks to a separate file.

For example:

class AlgoliaWooIndexerConstants {
  const PLUGIN_NAME = 'Algolia Woo Indexer'; 
  // ... other constants
}

class AlgoliaWooIndexerSettings {
  public function algolia_woo_indexer_settings_page() {
    // Render settings page
  }
  
  public function validate_settings() {
   // Validate settings
  }
}

class AlgoliaWooIndexer {

  public function __construct(AlgoliaWooIndexerSettings $settings) {
    $this->settings = $settings;
  }
  
  public function do_something() {
    $this->settings->algolia_woo_indexer_settings_page();  
  }
}

Hope this helps! Let me know if you have any other questions.

@w3bdesign w3bdesign added the enhancement New feature or request label May 30, 2023
@w3bdesign w3bdesign self-assigned this May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant