Test Failed
Push — issue/2900 ( f2122b )
by Ravinder
07:32
created

Give_Shortcode_Donor_Wall   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 93
Duplicated Lines 7.53 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 7
loc 93
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
A define_fields() 0 74 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_grid' );
31
	}
32
33
	/**
34
	 * Define the shortcode attribute fields
35
	 *
36
	 * @return array
37
	 */
38
	public function define_fields() {
39
		$create_form_link = sprintf(
40
		/* translators: %s: create new form URL */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 8.
Loading history...
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'        => 'give_forms',
52
				'tooltip'     => esc_attr__( 'Select a Donation Form', 'give' ),
53
				'placeholder' => '- ' . esc_attr__( 'Select a Donation Form', 'give' ) . ' -',
54
				'required'    => array(
55
					'alert' => esc_html__( 'You must first select a Form!', 'give' ),
56
					'error' => sprintf( '<p class="strong">%s</p><p class="no-margin">%s</p>', esc_html__( 'No forms found.', 'give' ), $create_form_link ),
57
				),
58
			),
59
			array(
60
				'type'    => 'textbox',
61
				'classes' => 'give-hidden give-donors-per-page',
62
				'name'    => 'donors_per_page',
63
				'label'   => esc_attr__( 'Donor Per Page', 'give' ),
64
			),
65
			array(
66
				'type'    => 'listbox',
67
				'name'    => 'show_avatar',
68
				'label'   => esc_attr__( 'Show Avatar', 'give' ),
69
				'options' => array(
70
					'true'  => esc_html__( 'Show', 'give' ),
71
					'false' => esc_html__( 'Hide', 'give' ),
72
				),
73
			),
74
			array(
75
				'type'    => 'listbox',
76
				'name'    => 'show_name',
77
				'label'   => esc_attr__( 'Show Name', 'give' ),
78
				'options' => array(
79
					'true'  => esc_html__( 'Show', 'give' ),
80
					'false' => esc_html__( 'Hide', 'give' ),
81
				),
82
			),
83
			array(
84
				'type'    => 'listbox',
85
				'name'    => 'show_total',
86
				'label'   => esc_attr__( 'Show Total', 'give' ),
87
				'options' => array(
88
					'true'  => esc_html__( 'Show', 'give' ),
89
					'false' => esc_html__( 'Hide', 'give' ),
90
				),
91
			),
92
			array(
93
				'type'    => 'listbox',
94
				'name'    => 'show_time',
95
				'label'   => esc_attr__( 'Show Time', 'give' ),
96
				'options' => array(
97
					'true'  => esc_html__( 'Show', 'give' ),
98
					'false' => esc_html__( 'Hide', 'give' ),
99
				),
100
			),
101
			array(
102
				'type'    => 'listbox',
103
				'name'    => 'show_comments',
104
				'label'   => esc_attr__( 'Show Comments', 'give' ),
105
				'options' => array(
106
					'true'  => esc_html__( 'Show', 'give' ),
107
					'false' => esc_html__( 'Hide', 'give' ),
108
				),
109
			),
110
		);
111
	}
112
}
113
114
new Give_Shortcode_Donor_Wall();
115