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
This commit is contained in:
2025-04-21 16:52:56 +01:00
parent af11f827c4
commit 40ebbce1cc
3 changed files with 31 additions and 16 deletions

View File

@@ -19,7 +19,7 @@ class Admin {
* *
* @var Core * @var Core
*/ */
private $core; private Core $core;
/** /**
* Constructor. * Constructor.
@@ -46,7 +46,6 @@ class Admin {
* *
* @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
*/ */
public function enqueue_admin_assets(): void { public function enqueue_admin_assets(): void {
@@ -71,22 +70,22 @@ class Admin {
// @phpcs:enable // @phpcs:enable
// Get the plugin version. // Get the plugin version.
$pluginVersion = $this->core->get_plugin_version(); $plugin_version = $this->core->get_plugin_version();
// Enqueue styles. // Enqueue styles.
\wp_enqueue_style( \wp_enqueue_style(
'wpst-admin-styles', 'wpst-admin-styles',
\plugin_dir_url( __FILE__ ) . '../../admin/css/admin-styles.css', plugin_dir_url( dirname( __DIR__ ) ) . 'admin/css/admin-styles.css',
array(), // Dependencies. array(), // Dependencies.
$pluginVersion // Version. $plugin_version // Version.
); );
// Enqueue admin scripts. // Enqueue admin scripts.
\wp_enqueue_script( \wp_enqueue_script(
'wpst-admin-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' ), array( 'jquery' ),
$pluginVersion, // Version. $plugin_version, // Version.
true true
); );

View File

@@ -17,14 +17,14 @@ class Core {
* *
* @var string * @var string
*/ */
private $version; private string $version;
/** /**
* Constructor * Constructor
* *
* @param string $version Plugin version. * @param string $version Plugin version.
*/ */
public function __construct( $version = '' ) { public function __construct( string $version = '' ) {
// Initialize hooks. // Initialize hooks.
$this->version = $version; $this->version = $version;
} }
@@ -35,7 +35,7 @@ class Core {
* @param string $content The content to filter. * @param string $content The content to filter.
* @return string The filtered content. * @return string The filtered content.
*/ */
public function filter_content( $content ) { public function filter_content( string $content ): string {
return $content; return $content;
} }
@@ -44,7 +44,7 @@ class Core {
* *
* @return string The plugin version. * @return string The plugin version.
*/ */
public function get_plugin_version() { public function get_plugin_version(): string {
return $this->version; return $this->version;
} }
} }

View File

@@ -19,14 +19,14 @@ class Plugin {
* *
* @var Core * @var Core
*/ */
private $core; private Core $core;
/** /**
* Admin instance * Admin instance
* *
* @var Admin * @var Admin
*/ */
private $admin; private Admin $admin;
/** /**
* Plugin file path * Plugin file path
@@ -40,7 +40,7 @@ class Plugin {
* *
* @var string * @var string
*/ */
private $version; private string $version;
/** /**
* Constructor * Constructor
@@ -58,7 +58,23 @@ class Plugin {
/** /**
* Initialize the plugin * Initialize the plugin
*/ */
public function init() { public function init(): void {
// Initialization logic goes here. // 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/'
);
} }
} }