From 13fc3f678303d4703207747b1b5c2ae91d422f99 Mon Sep 17 00:00:00 2001 From: sarahcssiqueira Date: Sun, 23 Jun 2024 17:33:33 -0300 Subject: [PATCH 1/2] Updates IDE settings to work with a new phpcs/phcbf extension --- .vscode/settings.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c0f424b..800310f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { - "phpCodeSniffer.standard": "Automatic", - "phpCodeSniffer.exec.osx":"./vendor/bin/phpcs" -} \ No newline at end of file + "phpsab.fixerEnable":true, + "phpsab.snifferEnable": true, +} + + From 489659b8ab5428047f4267f5ce48541628f10c7d Mon Sep 17 00:00:00 2001 From: sarahcssiqueira Date: Sun, 23 Jun 2024 20:26:40 -0300 Subject: [PATCH 2/2] Refactor Init class methods and blocks classes, removing duplicated code --- inc/BlockW.php | 47 ----------------------- inc/BlockX.php | 47 ----------------------- inc/BlockY.php | 47 ----------------------- inc/BlockZ.php | 47 ----------------------- inc/Blocks.php | 38 +++++++++++++++++++ inc/Init.php | 47 +++++++++++++++-------- inc/SingleBlock.php | 92 +++++++++++++++++++++++++++++++++++++++++++++ wxyz-blocks.php | 24 ++++++------ 8 files changed, 173 insertions(+), 216 deletions(-) delete mode 100644 inc/BlockW.php delete mode 100644 inc/BlockX.php delete mode 100644 inc/BlockY.php delete mode 100644 inc/BlockZ.php create mode 100644 inc/Blocks.php create mode 100644 inc/SingleBlock.php diff --git a/inc/BlockW.php b/inc/BlockW.php deleted file mode 100644 index a20d322..0000000 --- a/inc/BlockW.php +++ /dev/null @@ -1,47 +0,0 @@ - 'wxyz-blocks', + 'title' => 'XYW...Z Blocks', + ]; + + return $categories; + } + +} diff --git a/inc/Init.php b/inc/Init.php index 81dc66f..d2ea74f 100644 --- a/inc/Init.php +++ b/inc/Init.php @@ -1,6 +1,6 @@ 'wxyz-blocks', - 'title' => 'XYW...Z Blocks', + public static function classes_list() { + return [ + Blocks::class, + SingleBlock::class, ]; + } - return $categories; + /** + * Loop through the classes list, instatiate them, + * and call the initialize() method if it exists + */ + public static function register_classes_list() { + foreach ( self::classes_list() as $class ) { + $classname = self::instantiate( $class ); + if ( method_exists( $classname, 'initialize' ) ) { + $classname->initialize(); + } + } } -} + /** + * Initialize the classes + * + * @param class $class class from the services array. + * @return class instance new instance of the class + */ + private static function instantiate( $class ) { + $classname = new $class(); + return $classname; + } +}; diff --git a/inc/SingleBlock.php b/inc/SingleBlock.php new file mode 100644 index 0000000..4c7d9fd --- /dev/null +++ b/inc/SingleBlock.php @@ -0,0 +1,92 @@ +register_classes_list();