| Conditions | 4 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | ); |
||
| 70 |