lsx_register_block_patterns()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 51
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 18
nc 6
nop 0
dl 0
loc 51
rs 9.6666
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * LSX: Block Patterns
4
 *
5
 * @since LSX 1.0
6
 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @package tag in file comment
Loading history...
7
8
/**
9
 * Registers block patterns and categories.
10
 *
11
 * @since LSX 1.0
12
 *
13
 * @return void
14
 */
15
function lsx_register_block_patterns() {
16
	$block_pattern_categories = array(
17
		'featured' => array( 'label' => __( 'Featured', 'lsx' ) ),
18
		'footer'   => array( 'label' => __( 'Footers', 'lsx' ) ),
19
		'header'   => array( 'label' => __( 'Headers', 'lsx' ) ),
20
		'query'    => array( 'label' => __( 'Query', 'lsx' ) ),
21
		'pages'    => array( 'label' => __( 'Pages', 'lsx' ) ),
22
	);
23
24
	/**
25
	 * Filters the theme block pattern categories.
26
	 *
27
	 * @since LSX 1.0
28
	 *
29
	 * @param array[] $block_pattern_categories {
30
	 *     An associative array of block pattern categories, keyed by category name.
31
	 *
32
	 *     @type array[] $properties {
33
	 *         An array of block category properties.
34
	 *
35
	 *         @type string $label A human-readable label for the pattern category.
36
	 *     }
37
	 * }
38
	 */
39
	$block_pattern_categories = apply_filters( 'lsx_block_pattern_categories', $block_pattern_categories );
40
41
	foreach ( $block_pattern_categories as $name => $properties ) {
42
		if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
43
			register_block_pattern_category( $name, $properties );
44
		}
45
	}
46
47
	$block_patterns = array(
48
		'general-pricing-table',
49
	);
50
51
	/**
52
	 * Filters the theme block patterns.
53
	 *
54
	 * @since LSX 1.0
55
	 *
56
	 * @param array $block_patterns List of block patterns by name.
57
	 */
58
	$block_patterns = apply_filters( 'lsx_block_patterns', $block_patterns );
59
60
	foreach ( $block_patterns as $block_pattern ) {
61
		$pattern_file = get_theme_file_path( '/includes/patterns/' . $block_pattern . '.php' );
62
63
		register_block_pattern(
64
			'lsx/' . $block_pattern,
65
			require $pattern_file
66
		);
67
	}
68
}
69
add_action( 'init', 'lsx_register_block_patterns', 9 );
70