Skip to content

Refactoring #186

@w3bdesign

Description

@w3bdesign

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions