Passed
Push — master ( a722cd...843c92 )
by Chris
03:45
created

monsterinsights_import_settings()   D

Complexity

Conditions 15
Paths 220

Size

Total Lines 71
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
eloc 40
nc 220
nop 0
dl 0
loc 71
rs 4.8333
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
// Exit if accessed directly
3
if ( ! defined( 'ABSPATH' ) ) {
4
    exit;
5
}
6
7
/**
8
 * MonsterInsights settings export.
9
 *
10
 * @since 6.0.0
11
 * @access public
12
 *
13
 * @return void
14
 */
15
function monsterinsights_process_export_settings() {
16
	if ( ! isset( $_POST['monsterinsights_action'] ) || empty( $_POST['monsterinsights_action'] ) ) {
17
		return;
18
	}
19
20
	if ( ! current_user_can( 'monsterinsights_save_settings' ) ) {
21
		return;
22
	}
23
24
	if ( 'monsterinsights_export_settings' !== $_POST['monsterinsights_action'] ) {
25
		return;
26
	}
27
28
	if ( empty( $_POST['monsterinsights_export_settings'] ) || ! wp_verify_nonce( $_POST['monsterinsights_export_settings'], 'mi-admin-nonce' ) ) {
29
		return;
30
	}
31
32
	$settings = monsterinsights_export_settings();
33
	ignore_user_abort( true );
34
35
	nocache_headers();
36
	header( 'Content-Type: application/json; charset=utf-8' );
37
	header( 'Content-Disposition: attachment; filename=monsterinsights-settings-export-' . date( 'm-d-Y' ) . '.json' );
38
	header( "Expires: 0" );
39
40
	echo $settings;
0 ignored issues
show
Bug introduced by
Are you sure $settings of type false|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
	echo /** @scrutinizer ignore-type */ $settings;
Loading history...
41
	exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
42
}
43
44
add_action( 'admin_init', 'monsterinsights_process_export_settings' );
45