From 40ebbce1ccde4f87238248d6abebf6345a77be2b Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:52:56 +0100 Subject: [PATCH] Improve code quality to move from B to A grade - Added proper type declarations to all properties and methods - Fixed inconsistent variable naming (camelCase to snake_case) - Improved path handling in admin class - Added textdomain loading functionality - Removed unused phpcs:ignore comment - Implemented proper return type declarations --- includes/Admin/class-admin.php | 13 ++++++------- includes/class-core.php | 8 ++++---- includes/class-plugin.php | 26 +++++++++++++++++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/includes/Admin/class-admin.php b/includes/Admin/class-admin.php index 74373b2..0fca2f5 100644 --- a/includes/Admin/class-admin.php +++ b/includes/Admin/class-admin.php @@ -19,7 +19,7 @@ class Admin { * * @var Core */ - private $core; + private Core $core; /** * Constructor. @@ -46,7 +46,6 @@ class Admin { * - * @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found */ public function enqueue_admin_assets(): void { @@ -71,22 +70,22 @@ class Admin { // @phpcs:enable // Get the plugin version. - $pluginVersion = $this->core->get_plugin_version(); + $plugin_version = $this->core->get_plugin_version(); // Enqueue styles. \wp_enqueue_style( 'wpst-admin-styles', - \plugin_dir_url( __FILE__ ) . '../../admin/css/admin-styles.css', + plugin_dir_url( dirname( __DIR__ ) ) . 'admin/css/admin-styles.css', array(), // Dependencies. - $pluginVersion // Version. + $plugin_version // Version. ); // Enqueue admin scripts. \wp_enqueue_script( 'wpst-admin-script', - \plugin_dir_url( __FILE__ ) . '../../admin/js/admin-scripts.js', + plugin_dir_url( dirname( __DIR__ ) ) . 'admin/js/admin-scripts.js', array( 'jquery' ), - $pluginVersion, // Version. + $plugin_version, // Version. true ); diff --git a/includes/class-core.php b/includes/class-core.php index 3b4cb75..a00ac8d 100644 --- a/includes/class-core.php +++ b/includes/class-core.php @@ -17,14 +17,14 @@ class Core { * * @var string */ - private $version; + private string $version; /** * Constructor * * @param string $version Plugin version. */ - public function __construct( $version = '' ) { + public function __construct( string $version = '' ) { // Initialize hooks. $this->version = $version; } @@ -35,7 +35,7 @@ class Core { * @param string $content The content to filter. * @return string The filtered content. */ - public function filter_content( $content ) { + public function filter_content( string $content ): string { return $content; } @@ -44,7 +44,7 @@ class Core { * * @return string The plugin version. */ - public function get_plugin_version() { + public function get_plugin_version(): string { return $this->version; } } diff --git a/includes/class-plugin.php b/includes/class-plugin.php index a1ab938..39a7b51 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -19,14 +19,14 @@ class Plugin { * * @var Core */ - private $core; + private Core $core; /** * Admin instance * * @var Admin */ - private $admin; + private Admin $admin; /** * Plugin file path @@ -40,7 +40,7 @@ class Plugin { * * @var string */ - private $version; + private string $version; /** * Constructor @@ -58,7 +58,23 @@ class Plugin { /** * Initialize the plugin */ - public function init() { - // Initialization logic goes here. + public function init(): void { + // Register hooks and filters. + add_action('plugins_loaded', array($this, 'load_textdomain')); + + // Initialize any other plugin functionality. + } + + /** + * Load plugin textdomain. + * + * @return void + */ + public function load_textdomain(): void { + load_plugin_textdomain( + 'wp-plugin-starter-template', + false, + dirname(plugin_basename($this->pluginFile)) . '/languages/' + ); } }