Completed
Push — staging ( e273cb...e4c251 )
by
unknown
13:50
created

YIKES_Easy_Forms_Blocks::get_recaptcha()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 10
nop 0
dl 0
loc 26
rs 8.8817
c 0
b 0
f 0
ccs 0
cts 17
cp 0
crap 42
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, activate our blocks.
6
 *
7
 * We check if Gutenberg is active by looking for the existence of the `gutenberg_init()` function.
8
 */
9
function yikes_maybe_activate_blocks() {
10
	include ABSPATH . WPINC . '/version.php';
11
	if ( function_exists( 'gutenberg_init' ) || isset( $wp_version ) && version_compare( $wp_version, '5.0.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...
Bug introduced by
The variable $wp_version does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
12
		require_once YIKES_MC_PATH . 'blocks/api/api.php';
13
		require_once YIKES_MC_PATH . 'blocks/easy-forms-block/easy-forms-block.php';
14
		$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...
15
		$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...
16
	}
17
}
18
19
/**
20
 * Class YIKES_Easy_Forms_Blocks.
21
 */
22
abstract class YIKES_Easy_Forms_Blocks {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
23
24
	const BLOCK_NAMESPACE = 'yikes-inc-easy-forms/';
25
26
	/**
27
	 * Register our hooks.
28
	 */
29
	public function __construct() {
30
		add_action( 'enqueue_block_editor_assets', array( $this, 'editor_scripts' ) );
31
		add_action( 'init', array( $this, 'register_blocks' ), 11 );
32
	}
33
34
	/**
35
	 * Enqueue our scripts.
36
	 */
37
	abstract public function editor_scripts();
38
39
	/**
40
	 * Register our Easy Forms block callback.
41
	 */
42
	public function register_blocks() {
43
		register_block_type( static::BLOCK_NAMESPACE . static::BLOCK, array(
44
			'render_callback' => array( $this, 'render_block' ),
45
		));
46
	}
47
48
	/**
49
	 * Take the shortcode parameters from the Gutenberg block and render our shortcode.
50
	 *
51
	 * @param array  $attributes Block attributes.
52
	 * @param string $content    Block content.
53
	 * @return string Block output.
54
	 */
55
	abstract public function render_block( $attributes, $content );
56
}
57