Refactoring
w3bdesign opened this issue · comments
Here are some suggestions for refactoring the code:
- Rename the class to follow the PHP naming convention - AlgoliaWooIndexer
- Extract constants to a separate class - AlgoliaWooIndexerConstants
- Extract functions to separate classes - AlgoliaWooIndexerSettings, AlgoliaWooIndexerNonce, etc.
- Use snake_case for function and variable names instead of camelCase
- Add docblock comments for all functions and variables
- Validate input in the functions where they are used, not in a global validate function
- Use self::class instead of get_called_class()
- Avoid static properties and methods where possible. Use dependency injection instead.
- 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.