Test Failed
Push — issues/370 ( 90279e )
by Ravinder
05:35
created

Give_Settings_Import::render_media_csv()   F

Complexity

Conditions 12
Paths 1152

Size

Total Lines 55
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 42
nc 1152
nop 0
dl 0
loc 55
rs 3.4396
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
/**
3
 * Give Settings Page/Tab
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Settings_Import
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.8
10
 */
11
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit; // Exit if accessed directly
14
}
15
16
if ( ! class_exists( 'Give_Settings_Import' ) ) {
17
18
	/**
19
	 * Give_Settings_Import.
20
	 *
21
	 * Add a submenu page in give tools menu called Import donations which import the donations from the CSV files.
22
	 *
23
	 * @since 1.8.13
24
	 */
25
	class Give_Settings_Import extends Give_Settings_Page {
26
27
		/**
28
		 * Importing donation per page.
29
		 *
30
		 * @since 1.8.13
31
		 *
32
		 * @var   int
33
		 */
34
		public static $per_page = 5;
35
36
		/**
37
		 * Constructor.
38
		 */
39
		public function __construct() {
40
			$this->id    = 'import';
41
			$this->label = __( 'Import', 'give' );
42
43
			// Add Import tab in submenu.
44
			add_filter( 'give-tools_tabs_array', array( $this, 'add_settings_page' ), 20 );
45
46
			// Will display html of the import donation.
47
			add_action( 'give_admin_field_tools_import', array( 'Give_Settings_Import', 'render_import_field' ), 10, 2 );
48
49
			// Will call the function that generated the hook called 'give_admin_field_tools_import'.
50
			add_action( "give-tools_settings_{$this->id}_page", array( $this, 'output' ) );
51
52
			// Do not use main form for this tab.
53
			if ( give_get_current_setting_tab() === $this->id ) {
54
				add_action( "give-tools_open_form", '__return_empty_string' );
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal give-tools_open_form does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
55
				add_action( "give-tools_close_form", '__return_empty_string' );
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal give-tools_close_form does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
56
57
				require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/import/class-give-import-donations.php';
58
			}
59
		}
60
61
62
		/**
63
		 * Get settings array.
64
		 *
65
		 * @since  1.8.13
66
		 * @return array
67
		 */
68
		public function get_settings() {
69
			// Hide save button.
70
			$GLOBALS['give_hide_save_button'] = true;
71
72
			/**
73
			 * Filter the settings.
74
			 *
75
			 * @since  1.8.13
76
			 *
77
			 * @param  array $settings
78
			 */
79
			$settings = apply_filters(
80
				'give_get_settings_' . $this->id,
81
				array(
82
					array(
83
						'id'   => 'give_tools_import',
84
						'type' => 'title',
85
						'table_html' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
86
					),
87
					array(
88
						'id'   => 'import',
89
						'name' => __( 'Import', 'give' ),
90
						'type' => 'tools_import',
91
					),
92
					array(
93
						'id'   => 'give_tools_import',
94
						'type' => 'sectionend',
95
						'table_html' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
96
					)
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
97
				)
98
			);
99
100
			// Output.
101
			return $settings;
102
		}
103
104
		/**
105
		 * Render report import field
106
		 *
107
		 * @since  1.8.13
108
		 * @access public
109
		 *
110
		 * @param $field
111
		 * @param $option_value
112
		 */
113
		public static function render_import_field( $field, $option_value ) {
114
			include_once GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-imports.php';
115
		}
116
	}
117
}
118
return new Give_Settings_Import();
119