Skip to content

Commit

Permalink
feat: updates SingleBlock to implement BlockManagerInterface with typ…
Browse files Browse the repository at this point in the history
…e hinting, changes method calls from self:: to ->.
  • Loading branch information
sarahcssiqueira committed Oct 28, 2024
1 parent d24f936 commit c8a55a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
16 changes: 16 additions & 0 deletions inc/BlockManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Block Manager Interface
*
* @package wxyzblocks
*/

namespace WXYZBlocks\Inc;

interface BlockManagerInterface {
public function blocks_list(): array;
public function blocks_register(): void;
public function blocks_enqueues(): void;
public function custom_block_register(string $block): void;
public function custom_block_enqueues(string $block): void;
}
3 changes: 1 addition & 2 deletions inc/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class Blocks {
* Custom constructor for handle WordPress Hooks
*/
public static function initialize() {
$self = new self();
add_filter( 'block_categories_all', [ $self, 'register_new_category' ] );
add_filter( 'block_categories_all', [ $this, 'register_new_category' ] );
}

/**
Expand Down
22 changes: 11 additions & 11 deletions inc/SingleBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace WXYZBlocks\Inc;

/**
* Single Blocks class
* Single Blocks class implementing BlockManagerInterface
*/
class SingleBlock {
class SingleBlock implements BlockManagerInterface {

/**
* Custom constructor for handle WordPress Hooks
Expand All @@ -28,7 +28,7 @@ public function initialize() {
*
* @return array Full list of block names and paths
*/
public function blocks_list() {
public function blocks_list(): array {
return [
'block-w',
'block-x',
Expand All @@ -43,9 +43,9 @@ public function blocks_list() {
* Iterates over the list of block names returned by the blocks_list method
* and registers each block using the custom_block_register method.
*/
public function blocks_register() {
foreach ( self::blocks_list() as $block ) {
self::custom_block_register( $block );
public function blocks_register(): void {
foreach ( $this->blocks_list() as $block ) {
$this->custom_block_register( $block );
}
}

Expand All @@ -55,9 +55,9 @@ public function blocks_register() {
* Iterates over the list of block names returned by the blocks_list method
* and enqueues the scripts and styles for each block using the custom_block_enqueues method.
*/
public function blocks_enqueues() {
foreach ( self::blocks_list() as $block ) {
self::custom_block_enqueues( $block );
public function blocks_enqueues(): void {
foreach ( $this->blocks_list() as $block ) {
$this->custom_block_enqueues( $block );
}
}

Expand All @@ -66,7 +66,7 @@ public function blocks_enqueues() {
*
* @param block $block block from the blocks_list method.
*/
public function custom_block_register( $block ) {
public function custom_block_register(string $block): void {
register_block_type( __DIR__ . "/../blocks/$block" );
}

Expand All @@ -75,7 +75,7 @@ public function custom_block_register( $block ) {
*
* @param block $block block from the blocks_list method.
*/
public function custom_block_enqueues( $block ) {
public function custom_block_enqueues(string $block): void {
wp_enqueue_script(
'$block',
plugin_dir_url( __FILE__ ) . "../blocks/$block/build/index.js",
Expand Down

0 comments on commit c8a55a9

Please sign in to comment.