Completed
Pull Request — master (#808)
by
unknown
07:45 queued 05:21
created

maybe-do-blocks.php ➔ yikes_maybe_activate_blocks()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 7
nop 0
dl 0
loc 20
ccs 0
cts 14
cp 0
crap 42
rs 8.9777
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
add_action( 'init', 'yikes_maybe_activate_blocks' );
3
4
/**
5
 * If Gutenberg is active && PHP Version is >= 5.6, activate our blocks.
6
 *
7
 * We check if Gutenberg is active by looking for the existence of the `gutenberg_init()` function (Gutenberg plugin) or WordPress version >= 5.0.0.
8
 */
9
function yikes_maybe_activate_blocks() {
10
	include ABSPATH . WPINC . '/version.php';
11
	if ( version_compare( PHP_VERSION, '5.6.0', '>=' ) && ( function_exists( 'gutenberg_init' ) || isset( $wp_version ) && version_compare( $wp_version, '5.0', '>=' ) ) ) {
0 ignored issues
show
Bug introduced by
The variable $wp_version seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
12
13
		// Wrap the init of block functionality into a Try/Catch until everything is stable.
14
		try {
15
			require_once YIKES_MC_PATH . 'blocks/blocks.php';
16
			require_once YIKES_MC_PATH . 'blocks/api/api.php';
17
			require_once YIKES_MC_PATH . 'blocks/easy-forms-block/easy-forms-block.php';
18
			$yikes_easy_form_block      = new YIKES_Easy_Form_Block();
0 ignored issues
show
Unused Code introduced by
$yikes_easy_form_block is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19
			$yikes_easy_form_blocks_api = new YIKES_Easy_Forms_Blocks_API();
0 ignored issues
show
Unused Code introduced by
$yikes_easy_form_blocks_api is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
		} catch ( Exception $e ) {
21
			$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
22
			$error_logging->maybe_write_to_log( $e->getMessage(),
23
				__( 'Error initializing the Easy Forms\' Gutenberg block functions.', 'yikes-inc-easy-mailchimp-extender' ),
24
				'blocks.php'
25
			);
26
		}
27
	}
28
}