Completed
Push — issues/3312 ( 6b1a83 )
by Ravinder
1313:55 queued 1307:48
created

Give_Shortcode_Donor_Wall   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 120
Duplicated Lines 5.83 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 7
loc 120
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
B define_fields() 0 101 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * The [give_donor_grid] Shortcode Generator class
4
 *
5
 * @package     Give
6
 * @subpackage  Admin
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       2.1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Class Give_Shortcode_Donor_Wall
19
 */
20
class Give_Shortcode_Donor_Wall extends Give_Shortcode_Generator {
21
22
	/**
23
	 * Class constructor
24
	 */
25 View Code Duplication
	public function __construct() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
27
		$this->shortcode['title'] = esc_html__( 'Donor Wall', 'give' );
28
		$this->shortcode['label'] = esc_html__( 'Donor Wall', 'give' );
29
30
		parent::__construct( 'give_donor_wall' );
31
	}
32
33
	/**
34
	 * Define the shortcode attribute fields
35
	 *
36
	 * @return array
37
	 */
38
	public function define_fields() {
39
		$create_form_link = sprintf(
0 ignored issues
show
Unused Code introduced by
$create_form_link 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...
40
			/* translators: %s: create new form URL */
41
			__( '<a href="%s">Create</a> a new Donation Form.', 'give' ),
42
			admin_url( 'post-new.php?post_type=give_forms' )
43
		);
44
45
		return array(
46
			array(
47
				'type'        => 'post',
48
				'query_args'  => array(
49
					'post_type' => 'give_forms',
50
				),
51
				'name'        => 'form_id',
52
				'tooltip'     => esc_attr__( 'Select a Donation Form', 'give' ),
53
				'placeholder' => '- ' . esc_attr__( 'Select a Donation Form', 'give' ) . ' -',
54
			),
55
			array(
56
				'type'        => 'textbox',
57
				'name'        => 'donors_per_page',
58
				'label'       => esc_attr__( 'Donors Per Page', 'give' ),
59
				'placeholder' => '20',
60
			),
61
			array(
62
				'type'        => 'textbox',
63
				'name'        => 'comment_length',
64
				'label'       => esc_attr__( 'Comment Length', 'give' ),
65
				'placeholder' => '20',
66
			),
67
			array(
68
				'type'        => 'textbox',
69
				'name'        => 'readmore_text',
70
				'label'       => esc_attr__( 'Read More Text', 'give' ),
71
				'placeholder' => esc_html__( 'Read More', 'give' ),
72
			),
73
			array(
74
				'type'        => 'textbox',
75
				'name'        => 'loadmore_text',
76
				'label'       => esc_attr__( 'Load More Text', 'give' ),
77
				'placeholder' => esc_html__( 'Load More', 'give' ),
78
			),
79
			array(
80
				'type'        => 'listbox',
81
				'name'        => 'columns',
82
				'label'       => esc_attr__( 'Columns:', 'give' ),
83
				'tooltip'     => esc_attr__( 'Sets the number of forms per row.', 'give' ),
84
				'options'     => array(
85
					'1' => esc_html__( '1', 'give' ),
86
					'2' => esc_html__( '2', 'give' ),
87
					'3' => esc_html__( '3', 'give' ),
88
					'4' => esc_html__( '4', 'give' ),
89
				),
90
				'placeholder' => esc_html__( 'Best Fit', 'give' ),
91
			),
92
			array(
93
				'type'        => 'listbox',
94
				'name'        => 'show_avatar',
95
				'label'       => esc_attr__( 'Show Avatar', 'give' ),
96
				'options'     => array(
97
					'false' => esc_html__( 'Hide', 'give' ),
98
				),
99
				'placeholder' => esc_html__( 'Show', 'give' ),
100
			),
101
			array(
102
				'type'        => 'listbox',
103
				'name'        => 'show_name',
104
				'label'       => esc_attr__( 'Show Name', 'give' ),
105
				'options'     => array(
106
					'false' => esc_html__( 'Hide', 'give' ),
107
				),
108
				'placeholder' => esc_html__( 'Show', 'give' ),
109
			),
110
			array(
111
				'type'        => 'listbox',
112
				'name'        => 'show_total',
113
				'label'       => esc_attr__( 'Show Total', 'give' ),
114
				'options'     => array(
115
					'false' => esc_html__( 'Hide', 'give' ),
116
				),
117
				'placeholder' => esc_html__( 'Show', 'give' ),
118
			),
119
			array(
120
				'type'        => 'listbox',
121
				'name'        => 'show_time',
122
				'label'       => esc_attr__( 'Show Date', 'give' ),
123
				'options'     => array(
124
					'false' => esc_html__( 'Hide', 'give' ),
125
				),
126
				'placeholder' => esc_html__( 'Show', 'give' ),
127
			),
128
			array(
129
				'type'        => 'listbox',
130
				'name'        => 'show_comments',
131
				'label'       => esc_attr__( 'Show Comments', 'give' ),
132
				'options'     => array(
133
					'false' => esc_html__( 'Hide', 'give' ),
134
				),
135
				'placeholder' => esc_html__( 'Show', 'give' ),
136
			)
137
		);
138
	}
139
}
140
141
new Give_Shortcode_Donor_Wall();
142